@galadrim/galadmin 0.1.150 → 0.1.152

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,6 +15,7 @@ export type BaseTypeColumn = {
15
15
  required?: boolean;
16
16
  includeInExport?: boolean;
17
17
  displayCondition?: (record: any) => boolean;
18
+ roles?: string[];
18
19
  };
19
20
  export type ColorColumn = {
20
21
  dataType: 'color';
@@ -134,7 +135,7 @@ export type CreateType = {
134
135
  };
135
136
  export type CustomAction = {
136
137
  label: string;
137
- action: (record: any) => void;
138
+ action: (record: any) => void | string;
138
139
  successMessage?: string;
139
140
  };
140
141
  export type FormDataFile = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galadrim/galadmin",
3
- "version": "0.1.150",
3
+ "version": "0.1.152",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/src/api.ts CHANGED
@@ -562,7 +562,13 @@ export default (db, config, user) => {
562
562
  try {
563
563
  const { rows } = await db.query("SELECT " + (view.selectExpression || "*") + " FROM ?? " + (view.join || "") + " WHERE ?? = ?", [view.tableName, view.tableName + "." + view.primaryId, recordId])
564
564
  const record = rows[0]
565
- await action.action(record);
565
+ const actionResult = await action.action(record);
566
+ if (actionResult) {
567
+ return res.send({
568
+ success: true,
569
+ message: actionResult
570
+ })
571
+ }
566
572
  } catch (err) {
567
573
  console.error(err)
568
574
  return res.send({
package/src/index.ts CHANGED
@@ -169,6 +169,16 @@ export default (config: Config): any => {
169
169
  return view;
170
170
  }
171
171
  })
172
+ .map(view => {
173
+ if (view.type === "table") {
174
+ return {
175
+ ...view,
176
+ columns: view.columns.filter(column => !column.roles || (req.session.user && column.roles.includes(req.session.user.role)))
177
+ }
178
+ } else {
179
+ return view;
180
+ }
181
+ })
172
182
  }, req.session.user)(req, res, next)
173
183
  })
174
184
 
@@ -16,6 +16,7 @@ export type BaseTypeColumn = {
16
16
  required?: boolean;
17
17
  includeInExport?: boolean;
18
18
  displayCondition?: (record: any) => boolean;
19
+ roles?: string[];
19
20
  };
20
21
 
21
22
  export type ColorColumn = {
@@ -161,7 +162,7 @@ export type CreateType = {
161
162
 
162
163
  export type CustomAction = {
163
164
  label: string;
164
- action: (record: any) => void;
165
+ action: (record: any) => void | string;
165
166
  successMessage?: string;
166
167
  };
167
168