@galadrim/galadmin 0.1.145 → 0.1.146

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.
@@ -299,6 +299,7 @@ export type CustomView = {
299
299
  export type BaseTypeView = {
300
300
  hidden?: boolean;
301
301
  roles?: string[];
302
+ readRoles?: string[];
302
303
  };
303
304
  export type View = BaseTypeView & (TableView | IframeView | LinkView | CustomView);
304
305
  export type AuthRole = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@galadrim/galadmin",
3
- "version": "0.1.145",
3
+ "version": "0.1.146",
4
4
  "main": "dist/index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",
package/src/api.ts CHANGED
@@ -90,7 +90,6 @@ export default (db, config, user) => {
90
90
 
91
91
  app.get('/config', async (req, res) => {
92
92
  try {
93
- /*
94
93
  config = {
95
94
  ...config,
96
95
  ...{
@@ -102,7 +101,6 @@ export default (db, config, user) => {
102
101
  view.columns = view.columns.filter(column => !column.roles || column.roles.includes(user.role))
103
102
  }
104
103
  }
105
- */
106
104
  const { mysql, auth, sessionSecret, ...safeConfig } = config;
107
105
  res.send({
108
106
  config: serializeJs(safeConfig)
package/src/index.ts CHANGED
@@ -151,7 +151,14 @@ export default (config: Config): any => {
151
151
  app.use("/api", (req, res, next) => {
152
152
  return api(db, {
153
153
  ...config,
154
- views: config.views.filter(x => !x.roles || (req.session.user && x.roles.includes(req.session.user.role)))
154
+ views: config.views
155
+ .filter(x => !x.roles
156
+ || (req.session.user && ([...(x.roles || []), ...(x.readRoles || [])].includes(req.session.user.role)))
157
+ )
158
+ .map(view => ({
159
+ ...view,
160
+ ...(view.type === "table" && view.canEdit !== false ? { canEdit: (req.session.user && view.roles.includes(req.session.user.role)) } : {}),
161
+ }))
155
162
  }, req.session.user)(req, res, next)
156
163
  })
157
164
 
@@ -342,6 +342,7 @@ export type BaseTypeView = {
342
342
  /** Cache la vue dans le menu latéral */
343
343
  hidden?: boolean;
344
344
  roles?: string[];
345
+ readRoles?: string[];
345
346
  };
346
347
 
347
348
  export type View = BaseTypeView &