adminizer 4.1.0-build.20 → 4.1.0-build.21

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.
@@ -13,3 +13,6 @@ export declare class AccessRightsHelper {
13
13
  enoughPermissions(tokens: string[], user: UserAP): boolean;
14
14
  hasPermission(tokenId: string, user: UserAP): boolean;
15
15
  }
16
+ export declare class GroupsAccessRightsHelper {
17
+ static hasAccess(user: UserAP, groupsAccessRights?: string[]): boolean;
18
+ }
@@ -62,3 +62,15 @@ export class AccessRightsHelper {
62
62
  return user.groups.some((group) => group.tokens?.includes(tokenId));
63
63
  }
64
64
  }
65
+ export class GroupsAccessRightsHelper {
66
+ static hasAccess(user, groupsAccessRights) {
67
+ const userGroups = user.groups?.map(group => group.name.toLowerCase());
68
+ if (groupsAccessRights) {
69
+ const allowedGroups = groupsAccessRights.map(item => item.toLowerCase());
70
+ return userGroups?.some(group => allowedGroups.includes(group)) ?? false;
71
+ }
72
+ else {
73
+ return true;
74
+ }
75
+ }
76
+ }
@@ -5,7 +5,7 @@ export class InertiaMenuHelper {
5
5
  }
6
6
  getMenuItems(req) {
7
7
  let menu = [];
8
- for (const menuItem of this.adminizer.menuHelper.getMenuItems()) {
8
+ for (const menuItem of this.adminizer.menuHelper.getMenuItems(req.user)) {
9
9
  const menuItemTokens = menuItem.actions ? menuItem.actions.map(item => {
10
10
  return item.accessRightsToken;
11
11
  }).filter(item => {
@@ -3,6 +3,7 @@
3
3
  *
4
4
  * @constructor
5
5
  */
6
+ import { UserAP } from "models/UserAP";
6
7
  import { ActionType, AdminpanelConfig, HrefConfig, ModelConfig } from "../interfaces/adminpanelConfig";
7
8
  export type MenuItem = {
8
9
  link: string;
@@ -60,5 +61,5 @@ export declare class MenuHelper {
60
61
  *
61
62
  * @returns {Array}
62
63
  */
63
- getMenuItems(): MenuItem[];
64
+ getMenuItems(user: UserAP): MenuItem[];
64
65
  }
@@ -1,3 +1,4 @@
1
+ import { GroupsAccessRightsHelper } from "./accessRightsHelper";
1
2
  export class MenuHelper {
2
3
  static config;
3
4
  constructor(config) {
@@ -98,7 +99,7 @@ export class MenuHelper {
98
99
  *
99
100
  * @returns {Array}
100
101
  */
101
- getMenuItems() {
102
+ getMenuItems(user) {
102
103
  let menus = [];
103
104
  if (MenuHelper.config.navbar.additionalLinks && MenuHelper.config.navbar.additionalLinks.length > 0) {
104
105
  MenuHelper.config.navbar.additionalLinks.forEach(function (additionalLink) {
@@ -118,7 +119,12 @@ export class MenuHelper {
118
119
  }
119
120
  if (MenuHelper.config.models) {
120
121
  Object.entries(MenuHelper.config.models).forEach(function ([key, val]) {
121
- if (!val.hide) {
122
+ const hide = typeof val.navbar?.visible === 'boolean'
123
+ ? !val.navbar.visible
124
+ : val.navbar?.groupsAccessRights
125
+ ? !GroupsAccessRightsHelper.hasAccess(user, val.navbar.groupsAccessRights)
126
+ : false;
127
+ if (!hide) {
122
128
  if (val.tools && val.tools.length > 0 && val.tools[0].id !== "overview") {
123
129
  val.tools.unshift({
124
130
  id: "overview",
@@ -184,9 +184,18 @@ export interface ModelConfig {
184
184
  * */
185
185
  model: string;
186
186
  /**
187
- * Hide entity in left navbar
187
+ * If the field is not definitely, then it will appear in Navbar
188
188
  * */
189
- hide?: boolean;
189
+ navbar?: {
190
+ /**
191
+ * @default true
192
+ */
193
+ visible?: boolean;
194
+ /**
195
+ * For which it will be shown if not established will be shown to all groups who have the rights to read
196
+ */
197
+ groupsAccessRights?: string[];
198
+ };
190
199
  /**
191
200
  * Entity fields configuration
192
201
  * */
@@ -37,6 +37,7 @@ export class DataAccessor {
37
37
  }
38
38
  const result = {};
39
39
  Object.entries(modelAttributes).forEach(([key, modelField]) => {
40
+ console.log(key);
40
41
  // The fields that are recorded separately from the connection in some ORMs, because they are processed at the level above them.
41
42
  if (modelAttributes[key].primaryKeyForAssociation === true) {
42
43
  return undefined;
@@ -77,7 +78,7 @@ export class DataAccessor {
77
78
  let populatedModelFieldsConfig = {};
78
79
  if (modelField.type === "association" || modelField.type === "association-many") {
79
80
  const modelName = modelField.model || modelField.collection;
80
- const tokenId = `${this.actionVerb}-${modelName}-${this.entity.type}`;
81
+ const tokenId = `read-${modelName}-${this.entity.type}`;
81
82
  if (!this.adminizer.accessRightsHelper.hasPermission(tokenId, this.user)) {
82
83
  Adminizer.log.silly(`No access rights to ${this.entity.type}: ${this.entity.model.modelname}`);
83
84
  return undefined;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "adminizer",
3
3
  "type": "module",
4
- "version": "4.1.0-build.20",
4
+ "version": "4.1.0-build.21",
5
5
  "main": "index.js",
6
6
  "scripts": {
7
7
  "test": "vitest --reporter verbose",