@lenne.tech/nest-server 9.4.0 → 9.4.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lenne.tech/nest-server",
3
- "version": "9.4.0",
3
+ "version": "9.4.1",
4
4
  "description": "Modern, fast, powerful Node.js web framework in TypeScript based on Nest with a GraphQL API and a connection to MongoDB (or other databases).",
5
5
  "keywords": [
6
6
  "node",
@@ -137,6 +137,7 @@ export const checkRestricted = (
137
137
  roles.includes(RoleEnum.S_EVERYONE) ||
138
138
  user?.hasRole?.(roles) ||
139
139
  (user?.id && roles.includes(RoleEnum.S_USER)) ||
140
+ (roles.includes(RoleEnum.S_SELF) && getIncludedIds(config.dbObject, user)) ||
140
141
  (roles.includes(RoleEnum.S_CREATOR) && getIncludedIds(config.dbObject?.createdBy, user))
141
142
  ) {
142
143
  valid = true;
@@ -53,4 +53,7 @@ export enum RoleEnum {
53
53
 
54
54
  // User must be the creator of the processed object(s) (see createdBy property of object(s))
55
55
  S_CREATOR = 's_creator',
56
+
57
+ // User must be herself/himself
58
+ S_SELF = 's_self',
56
59
  }
@@ -250,6 +250,8 @@ export async function check(
250
250
  (roles.includes(RoleEnum.S_USER) && user?.id) ||
251
251
  // check if the user has at least one of the required roles
252
252
  user?.hasRole?.(roles) ||
253
+ // check if the user is herself / himself
254
+ (roles.includes(RoleEnum.S_SELF) && equalIds(config.dbObject, user)) ||
253
255
  // check if the user is the creator
254
256
  (roles.includes(RoleEnum.S_CREATOR) && equalIds(config.dbObject?.createdBy, user))
255
257
  ) {
@@ -62,7 +62,7 @@ export class UserResolver {
62
62
  async getUser(@GraphQLServiceOptions() serviceOptions: ServiceOptions, @Args('id') id: string): Promise<User> {
63
63
  return await this.userService.get(id, {
64
64
  ...serviceOptions,
65
- roles: [RoleEnum.ADMIN, RoleEnum.S_CREATOR],
65
+ roles: [RoleEnum.ADMIN, RoleEnum.S_CREATOR, RoleEnum.S_SELF],
66
66
  });
67
67
  }
68
68
 
@@ -111,7 +111,7 @@ export class UserResolver {
111
111
  async deleteUser(@GraphQLServiceOptions() serviceOptions: ServiceOptions, @Args('id') id: string): Promise<User> {
112
112
  return await this.userService.delete(id, {
113
113
  ...serviceOptions,
114
- roles: [RoleEnum.ADMIN, RoleEnum.S_CREATOR],
114
+ roles: [RoleEnum.ADMIN, RoleEnum.S_CREATOR, RoleEnum.S_SELF],
115
115
  });
116
116
  }
117
117
 
@@ -138,7 +138,7 @@ export class UserResolver {
138
138
  return await this.userService.update(id, input, {
139
139
  ...serviceOptions,
140
140
  inputType: UserInput,
141
- roles: [RoleEnum.ADMIN, RoleEnum.S_CREATOR],
141
+ roles: [RoleEnum.ADMIN, RoleEnum.S_CREATOR, RoleEnum.S_SELF],
142
142
  });
143
143
  }
144
144