@driveflux/auth 4.0.90 → 4.0.91

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.
Files changed (42) hide show
  1. package/dist/AuthProvider.js +76 -59
  2. package/dist/authorization/define.js +57 -28
  3. package/dist/authorization/fields/index.js +4 -7
  4. package/dist/authorization/helpers.js +10 -8
  5. package/dist/authorization/index.js +6 -6
  6. package/dist/authorization/permissions-list.js +5 -7
  7. package/dist/authorization/quick.js +1 -1
  8. package/dist/authorization/roles/admin/business-development-executive.js +20 -7
  9. package/dist/authorization/roles/admin/ceo.js +4 -2
  10. package/dist/authorization/roles/admin/common.js +5 -3
  11. package/dist/authorization/roles/admin/concierge.js +35 -10
  12. package/dist/authorization/roles/admin/customer-success-executive.js +40 -10
  13. package/dist/authorization/roles/admin/data-analyst.js +7 -4
  14. package/dist/authorization/roles/admin/designer.js +7 -4
  15. package/dist/authorization/roles/admin/engineer.js +7 -4
  16. package/dist/authorization/roles/admin/finance-executive.js +11 -4
  17. package/dist/authorization/roles/admin/head-of-business-development.js +14 -4
  18. package/dist/authorization/roles/admin/head-of-data-analytics.js +14 -4
  19. package/dist/authorization/roles/admin/head-of-engineering.js +17 -6
  20. package/dist/authorization/roles/admin/head-of-finance.js +8 -3
  21. package/dist/authorization/roles/admin/head-of-human-resources.js +13 -5
  22. package/dist/authorization/roles/admin/head-of-marketing.js +17 -5
  23. package/dist/authorization/roles/admin/head-of-operations.js +8 -3
  24. package/dist/authorization/roles/admin/head-of-product.js +17 -6
  25. package/dist/authorization/roles/admin/head-of-sales.js +17 -5
  26. package/dist/authorization/roles/admin/human-resources-executive.js +12 -5
  27. package/dist/authorization/roles/admin/marketing-executive.js +7 -4
  28. package/dist/authorization/roles/admin/product-manager.js +7 -4
  29. package/dist/authorization/roles/admin/sales-executive.js +24 -8
  30. package/dist/authorization/roles/consumer/business-admin.js +19 -6
  31. package/dist/authorization/roles/consumer/business-user.js +18 -6
  32. package/dist/authorization/roles/consumer/member.js +16 -6
  33. package/dist/authorization/types.js +1 -1
  34. package/dist/authorization/update-user-permissions.js +22 -15
  35. package/dist/authorization/utils.js +26 -11
  36. package/dist/server/authenticate-user.js +11 -7
  37. package/dist/server/cors.js +23 -12
  38. package/dist/server/credentials-provider.js +2 -2
  39. package/dist/server/next-auth.js +104 -109
  40. package/dist/server/prisma-adapter.js +88 -52
  41. package/dist/server/verfiy-token.js +39 -24
  42. package/package.json +2 -2
@@ -6,37 +6,34 @@ import { useToastResult } from '@driveflux/ui/toast';
6
6
  import { useTrackEvent } from '@driveflux/web-analytics/track';
7
7
  import Cookies from 'js-cookie';
8
8
  import Router, { useRouter } from 'next/router';
9
- import { useCallback, useEffect, useMemo, useRef, useState, } from 'react';
9
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
10
10
  import useSWR from 'swr';
11
11
  import { AuthContext } from './context.js';
12
12
  import { translations } from './translations.js';
13
- const AuthProvider = ({ children }) => {
13
+ const AuthProvider = ({ children })=>{
14
14
  const { data: session, status, update } = useAuthSession();
15
15
  const { setUserData } = useTrackEvent();
16
16
  const [token, setToken] = useState(null);
17
17
  /**
18
- * A reference to a promise that fetches a new access token from the server.
19
- * This is used to prevent multiple token requests from being sent simultaneously.
20
- */
21
- const newTokenPromise = useRef(null);
18
+ * A reference to a promise that fetches a new access token from the server.
19
+ * This is used to prevent multiple token requests from being sent simultaneously.
20
+ */ const newTokenPromise = useRef(null);
22
21
  const localeLogicRan = useRef(false);
23
22
  const router = useRouter();
24
23
  const { pathname, asPath, query, locale } = router;
25
24
  const { toastResult } = useToastResult();
26
- const { data: user, isValidating, mutate, error, } = useSWR(session ? `${config.apiUrl}/user` : null, {
27
- fallbackData: session
28
- ?.user,
25
+ const { data: user, isValidating, mutate, error } = useSWR(session ? `${config.apiUrl}/user` : null, {
26
+ fallbackData: session?.user
29
27
  });
30
28
  const isLoadingUser = status !== 'unauthenticated' && isValidating && !user;
31
29
  /**
32
- * Retrieves an access token for the current user. If a token is already available and has not expired, it will be returned immediately.
33
- * Otherwise, the function will attempt to retrieve the token from cookies, and if that fails, it will fetch a new token from the server.
34
- * If a new token is fetched, it will be stored in cookies and returned.
35
- * If the user is not authenticated, the function will return null and display an error message.
36
- * @returns {Promise<string | null>} A promise that resolves to the access token string, or null if the user is not authenticated.
37
- */
38
- // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
39
- const getAccessToken = useCallback(async () => {
30
+ * Retrieves an access token for the current user. If a token is already available and has not expired, it will be returned immediately.
31
+ * Otherwise, the function will attempt to retrieve the token from cookies, and if that fails, it will fetch a new token from the server.
32
+ * If a new token is fetched, it will be stored in cookies and returned.
33
+ * If the user is not authenticated, the function will return null and display an error message.
34
+ * @returns {Promise<string | null>} A promise that resolves to the access token string, or null if the user is not authenticated.
35
+ */ // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
36
+ const getAccessToken = useCallback(async ()=>{
40
37
  // Check the state first, if we have a token, return it
41
38
  if (token && token.expiresAt > new Date()) {
42
39
  return token.accessToken;
@@ -49,19 +46,17 @@ const AuthProvider = ({ children }) => {
49
46
  if (expiresAt > new Date()) {
50
47
  setToken({
51
48
  accessToken: tokenFromCookies.accessToken,
52
- expiresAt,
49
+ expiresAt
53
50
  });
54
51
  }
55
52
  return tokenFromCookies.accessToken;
56
53
  }
54
+ } catch (_e) {
55
+ // TODO
56
+ // Nothing to do here
57
57
  }
58
- catch (_e) {
59
- // TODO
60
- // Nothing to do here
61
- }
62
- const tokenPromise = newTokenPromise.current ||
63
- // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
64
- (newTokenPromise.current = enhancedFetch(`${config.apiUrl}/user/token`));
58
+ const tokenPromise = newTokenPromise.current || // biome-ignore lint/suspicious/noAssignInExpressions: <explanation>
59
+ (newTokenPromise.current = enhancedFetch(`${config.apiUrl}/user/token`));
65
60
  // As a last resort, fetch a new token
66
61
  const newToken = await tokenPromise;
67
62
  // Resets the newTokenPromise reference to null after the new token has been fetched.
@@ -70,42 +65,50 @@ const AuthProvider = ({ children }) => {
70
65
  toastResult(newToken, {
71
66
  error: {
72
67
  title: translations.unauthenticated,
73
- description: translations.unauthenticatedDescription,
74
- },
68
+ description: translations.unauthenticatedDescription
69
+ }
75
70
  });
76
71
  return null;
77
72
  }
78
73
  const newTokenDetils = {
79
74
  accessToken: newToken.val.id,
80
- expiresAt: new Date(newToken.val.expiresAt),
75
+ expiresAt: new Date(newToken.val.expiresAt)
81
76
  };
82
77
  Cookies.set('accessTokenDetails', JSON.stringify(newTokenDetils));
83
78
  setToken(newTokenDetils);
84
79
  return newToken.val.id;
85
- }, [token]);
86
- const refresh = useCallback(async () => {
80
+ }, [
81
+ token
82
+ ]);
83
+ const refresh = useCallback(async ()=>{
87
84
  await update();
88
85
  return await mutate();
89
- }, [mutate, update]);
90
- const logout = useCallback(async () => {
91
- await signOut({ redirect: false });
86
+ }, [
87
+ mutate,
88
+ update
89
+ ]);
90
+ const logout = useCallback(async ()=>{
91
+ await signOut({
92
+ redirect: false
93
+ });
92
94
  await refresh();
93
- }, [refresh]);
94
- const context = useMemo(() => ({
95
- user,
96
- isLoadingUser,
97
- refresh,
98
- error,
99
- getAccessToken,
100
- // TODO
101
- /**
102
- * @deprecated do not use this property, use getAccessToken instead
103
- */
104
- accessToken: token?.accessToken,
105
- signIn,
106
- logout,
107
- status,
108
- }), [
95
+ }, [
96
+ refresh
97
+ ]);
98
+ const context = useMemo(()=>({
99
+ user,
100
+ isLoadingUser,
101
+ refresh,
102
+ error,
103
+ getAccessToken,
104
+ // TODO
105
+ /**
106
+ * @deprecated do not use this property, use getAccessToken instead
107
+ */ accessToken: token?.accessToken,
108
+ signIn,
109
+ logout,
110
+ status
111
+ }), [
109
112
  user,
110
113
  isLoadingUser,
111
114
  refresh,
@@ -113,11 +116,11 @@ const AuthProvider = ({ children }) => {
113
116
  getAccessToken,
114
117
  logout,
115
118
  token,
116
- status,
119
+ status
117
120
  ]);
118
121
  // Add preferredLocal if any
119
122
  // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
120
- useEffect(() => {
123
+ useEffect(()=>{
121
124
  if (localeLogicRan.current || !user) {
122
125
  return;
123
126
  }
@@ -125,23 +128,37 @@ const AuthProvider = ({ children }) => {
125
128
  const langFromCookies = Cookies.get('NEXT_LOCALE');
126
129
  if (user?.preferredLocale && langFromCookies !== user?.preferredLocale) {
127
130
  Cookies.set('NEXT_LOCALE', user.preferredLocale);
128
- Router.push({ pathname, query }, asPath, { locale: user.preferredLocale });
131
+ Router.push({
132
+ pathname,
133
+ query
134
+ }, asPath, {
135
+ locale: user.preferredLocale
136
+ });
129
137
  }
130
- }, [user?.preferredLocale, pathname, query, asPath]);
138
+ }, [
139
+ user?.preferredLocale,
140
+ pathname,
141
+ query,
142
+ asPath
143
+ ]);
131
144
  // Add user to the tracking
132
145
  // biome-ignore lint/correctness/useExhaustiveDependencies: <explanation>
133
- useEffect(() => {
134
- if (!user)
135
- return;
146
+ useEffect(()=>{
147
+ if (!user) return;
136
148
  setUserData({
137
149
  id: user.id,
138
150
  email: user.email,
139
151
  phoneNumber: user.phoneNumber,
140
152
  firstName: user.firstName,
141
153
  lastName: user.lastName,
142
- addresses: user.addresses,
154
+ addresses: user.addresses
143
155
  });
144
- }, [user]);
145
- return _jsx(AuthContext.Provider, { value: context, children: children });
156
+ }, [
157
+ user
158
+ ]);
159
+ return /*#__PURE__*/ _jsx(AuthContext.Provider, {
160
+ value: context,
161
+ children: children
162
+ });
146
163
  };
147
164
  export default AuthProvider;
@@ -1,6 +1,6 @@
1
1
  import { AbilityBuilder } from '@casl/ability';
2
2
  import { createPrismaAbility } from '@casl/prisma';
3
- import { ALL_ADMIN_ROLES, CONSUMER_ROLES, GENERAL_ROLES, HIGHER_ADMIN_ROLES, OWNER_ROLES, } from './constants.js';
3
+ import { ALL_ADMIN_ROLES, CONSUMER_ROLES, GENERAL_ROLES, HIGHER_ADMIN_ROLES, OWNER_ROLES } from './constants.js';
4
4
  import { defineRoleAbilitiesBusinessDevelopmentExecutive } from './roles/admin/business-development-executive.js';
5
5
  import { defineRoleAbilitiesCeo } from './roles/admin/ceo.js';
6
6
  import { defineRoleAbilitiesCommonAdmin } from './roles/admin/common.js';
@@ -26,45 +26,64 @@ import { defineRoleAbilitiesSalesExecutive } from './roles/admin/sales-executive
26
26
  import { defineRoleAbilitiesBusinessAdmin } from './roles/consumer/business-admin.js';
27
27
  import { defineRoleAbilitiesBusinessUser } from './roles/consumer/business-user.js';
28
28
  import { defineRoleAbilitiesMember } from './roles/consumer/member.js';
29
- export const defineAbilityFor = async (user) => {
29
+ export const defineAbilityFor = async (user)=>{
30
30
  const { can, cannot, build } = new AbilityBuilder(createPrismaAbility);
31
31
  if (!user) {
32
32
  return build();
33
33
  }
34
- const groups = Array.isArray(user.groups)
35
- ? user.groups.map((r) => `${r}`)
36
- : typeof user.groups === 'string'
37
- ? [user.groups]
38
- : [];
39
- const consumerGroups = groups.filter((g) => CONSUMER_ROLES.includes(g));
40
- const adminGroups = groups.filter((g) => !consumerGroups.includes(g));
41
- const sortedGroups = [...consumerGroups, ...adminGroups];
42
- for (const role of sortedGroups) {
34
+ const groups = Array.isArray(user.groups) ? user.groups.map((r)=>`${r}`) : typeof user.groups === 'string' ? [
35
+ user.groups
36
+ ] : [];
37
+ const consumerGroups = groups.filter((g)=>CONSUMER_ROLES.includes(g));
38
+ const adminGroups = groups.filter((g)=>!consumerGroups.includes(g));
39
+ const sortedGroups = [
40
+ ...consumerGroups,
41
+ ...adminGroups
42
+ ];
43
+ for (const role of sortedGroups){
43
44
  await defineSpecificRoleAbilities(role, can, cannot, user);
44
45
  }
45
46
  // Common admin abilities
46
- if (user.groups.some((g) => adminGroups.includes(g))) {
47
+ if (user.groups.some((g)=>adminGroups.includes(g))) {
47
48
  await defineRoleAbilitiesCommonAdmin(can);
48
49
  }
49
50
  // General abilities
50
- can(['read', 'update'], 'User', { id: user.id });
51
- can(['read'], 'Invoice', { payerId: user.id });
51
+ can([
52
+ 'read',
53
+ 'update'
54
+ ], 'User', {
55
+ id: user.id
56
+ });
57
+ can([
58
+ 'read'
59
+ ], 'Invoice', {
60
+ payerId: user.id
61
+ });
52
62
  if (user.businessId) {
53
- can(['read'], 'Invoice', { payerId: user.businessId });
63
+ can([
64
+ 'read'
65
+ ], 'Invoice', {
66
+ payerId: user.businessId
67
+ });
54
68
  }
55
- can('reserveVehicle', 'User', { banned: false, consented: true });
69
+ can('reserveVehicle', 'User', {
70
+ banned: false,
71
+ consented: true
72
+ });
56
73
  // Prevent updating the groups for all users
57
- cannot('update', 'User', ['groups']);
74
+ cannot('update', 'User', [
75
+ 'groups'
76
+ ]);
58
77
  return build();
59
78
  };
60
- const defineSpecificRoleAbilities = async (r, can, cannot, rawUser) => {
79
+ const defineSpecificRoleAbilities = async (r, can, cannot, rawUser)=>{
61
80
  if (!~GENERAL_ROLES.indexOf(r)) {
62
81
  return;
63
82
  }
64
83
  // Type issue
65
84
  const user = rawUser;
66
85
  const role = r;
67
- switch (role) {
86
+ switch(role){
68
87
  // Owners
69
88
  case 'ceo':
70
89
  defineRoleAbilitiesCeo(can);
@@ -142,20 +161,30 @@ const defineSpecificRoleAbilities = async (r, can, cannot, rawUser) => {
142
161
  case 'businessAdmin':
143
162
  defineRoleAbilitiesBusinessAdmin(can, user);
144
163
  break;
145
- default: {
146
- const _exhaustiveCheck = role;
147
- break;
148
- }
164
+ default:
165
+ {
166
+ const _exhaustiveCheck = role;
167
+ break;
168
+ }
149
169
  }
150
- if (![...OWNER_ROLES, ...HIGHER_ADMIN_ROLES].includes(role)) {
170
+ if (![
171
+ ...OWNER_ROLES,
172
+ ...HIGHER_ADMIN_ROLES
173
+ ].includes(role)) {
151
174
  cannot('manageAdmin', 'User');
152
- cannot(['create', 'update', 'delete'], 'User', undefined, {
175
+ cannot([
176
+ 'create',
177
+ 'update',
178
+ 'delete'
179
+ ], 'User', undefined, {
153
180
  groups: {
154
- hasSome: [...ALL_ADMIN_ROLES],
155
- },
181
+ hasSome: [
182
+ ...ALL_ADMIN_ROLES
183
+ ]
184
+ }
156
185
  }).because('You are not allowed to update admin users');
157
186
  can('update', 'User', undefined, {
158
- id: user.id,
187
+ id: user.id
159
188
  });
160
189
  }
161
190
  };
@@ -1,6 +1,5 @@
1
1
  import { Prisma, prisma } from '@driveflux/db';
2
- export const MODEL_FIELDS = Object.keys(Prisma.ModelName)
3
- .map((k) => {
2
+ export const MODEL_FIELDS = Object.keys(Prisma.ModelName).map((k)=>{
4
3
  if (!(k in Prisma.ModelName)) {
5
4
  return null;
6
5
  }
@@ -8,17 +7,15 @@ export const MODEL_FIELDS = Object.keys(Prisma.ModelName)
8
7
  return {
9
8
  // TODO
10
9
  // @ts-expect-error
11
- [key]: prisma._runtimeDataModel.models[key].fields.map((f) => f.name),
10
+ [key]: prisma._runtimeDataModel.models[key].fields.map((f)=>f.name)
12
11
  };
13
- })
14
- .filter((m) => m)
15
- .reduce((carry, current) => {
12
+ }).filter((m)=>m).reduce((carry, current)=>{
16
13
  if (current) {
17
14
  Object.assign(carry, current);
18
15
  }
19
16
  return carry;
20
17
  }, {});
21
- export const getModelFields = (model) => {
18
+ export const getModelFields = (model)=>{
22
19
  const fields = MODEL_FIELDS[model];
23
20
  return fields;
24
21
  };
@@ -1,16 +1,18 @@
1
1
  import { ALL_ADMIN_ROLES, CONSUMER_ROLES, OWNER_ROLES } from './constants';
2
- export const extractAdminRoles = (userGroups) => {
3
- return userGroups?.filter((group) => isAdmin(group));
2
+ export const extractAdminRoles = (userGroups)=>{
3
+ return userGroups?.filter((group)=>isAdmin(group));
4
4
  };
5
- export const extractNonAdminRoles = (userGroups) => {
6
- return userGroups?.filter((group) => !isAdmin(group));
5
+ export const extractNonAdminRoles = (userGroups)=>{
6
+ return userGroups?.filter((group)=>!isAdmin(group));
7
7
  };
8
- export const isConsumer = (group) => {
8
+ export const isConsumer = (group)=>{
9
9
  return CONSUMER_ROLES.includes(group);
10
10
  };
11
- export const isOwner = (group) => {
12
- return [...OWNER_ROLES]?.map((r) => group === r)?.[0];
11
+ export const isOwner = (group)=>{
12
+ return [
13
+ ...OWNER_ROLES
14
+ ]?.map((r)=>group === r)?.[0];
13
15
  };
14
- export const isAdmin = (group) => {
16
+ export const isAdmin = (group)=>{
15
17
  return ALL_ADMIN_ROLES.includes(group);
16
18
  };
@@ -4,15 +4,15 @@ import { ErrorWithResult } from '@driveflux/result';
4
4
  import { GUEST_PERMISSIONS } from './constants.js';
5
5
  import buildAbilityFromJson from './quick.js';
6
6
  import { updateUserPermissions } from './update-user-permissions.js';
7
- export const buildOrDefineAbility = async (user, refresh) => {
7
+ export const buildOrDefineAbility = async (user, refresh)=>{
8
8
  if (!user) {
9
- return createPrismaAbility([...GUEST_PERMISSIONS], {
10
- detectSubjectType: detectSubjectType,
9
+ return createPrismaAbility([
10
+ ...GUEST_PERMISSIONS
11
+ ], {
12
+ detectSubjectType: detectSubjectType
11
13
  });
12
14
  }
13
- if (!Array.isArray(user.permissions) ||
14
- !user.permissions?.length ||
15
- refresh) {
15
+ if (!Array.isArray(user.permissions) || !user.permissions?.length || refresh) {
16
16
  const result = await updateUserPermissions(user);
17
17
  if (result.err) {
18
18
  throw new ErrorWithResult(result);
@@ -1,5 +1,5 @@
1
1
  import { s } from './utils.js';
2
- export const getPermissionsFromAbility = (ability) => {
2
+ export const getPermissionsFromAbility = (ability)=>{
3
3
  return {
4
4
  // Lists
5
5
  viewContractsList: ability.can('read', 'SubscriptionContract'),
@@ -53,7 +53,7 @@ export const getPermissionsFromAbility = (ability) => {
53
53
  updateVehicleServiceCenters: ability.can('update', 'Vehicle', 'allowedServiceCenterIds'),
54
54
  readPricingInput: ability.can('readPricingInput', 'Vehicle'),
55
55
  updatePricingInput: ability.can('update', 'Vehicle', 'pricing'),
56
- testPricingInput: ability.can('testPricingInput', 'Vehicle'), // Special Permission to allow users edit pricing but without the ability to update
56
+ testPricingInput: ability.can('testPricingInput', 'Vehicle'),
57
57
  // Users ( Members )
58
58
  createMember: ability.can('create', 'User'),
59
59
  updateMember: ability.can('update', s('User')),
@@ -84,8 +84,7 @@ export const getPermissionsFromAbility = (ability) => {
84
84
  updateInvoice: ability.can('update', s('Invoice', 'payerId')),
85
85
  cancelInvoice: ability.can('cancelInvoice', 'Invoice'),
86
86
  markInvoiceAsPaid: ability.can('markInvoice', 'Invoice', 'paid'),
87
- markInvoiceAsRefunded: ability.can('markInvoice', 'Invoice', 'totalRefunded') &&
88
- ability.can('create', 'Refund'),
87
+ markInvoiceAsRefunded: ability.can('markInvoice', 'Invoice', 'totalRefunded') && ability.can('create', 'Refund'),
89
88
  readPaymentMethodsUser: ability.can('read', s('User'), 'paymentMethods'),
90
89
  readPaymentMethodsBusiness: ability.can('read', s('Business'), 'paymentMethods'),
91
90
  addPaymentMethodUser: ability.can('update', s('User'), 'paymentMethods'),
@@ -133,8 +132,7 @@ export const getPermissionsFromAbility = (ability) => {
133
132
  // TODO add logs permision or remove the comments
134
133
  // Logs
135
134
  // Website Settings
136
- uploadBanners: ability.can('update', 'PlatformConfig') &&
137
- ability.can('create', 'PlatformConfig'),
135
+ uploadBanners: ability.can('update', 'PlatformConfig') && ability.can('create', 'PlatformConfig'),
138
136
  deleteBanners: ability.can('update', 'PlatformConfig'),
139
137
  // Quotations
140
138
  createQuotation: ability.can('create', 'Quotation'),
@@ -143,6 +141,6 @@ export const getPermissionsFromAbility = (ability) => {
143
141
  createVacancy: ability.can('create', 'Vacancy'),
144
142
  updateVacancy: ability.can('update', 'Vacancy'),
145
143
  readApplicant: ability.can('read', 'Applicant'),
146
- readVacancy: ability.can('read', 'Vacancy'),
144
+ readVacancy: ability.can('read', 'Vacancy')
147
145
  };
148
146
  };
@@ -2,7 +2,7 @@ import { createPrismaAbility } from '@casl/prisma';
2
2
  import { detectSubjectType } from './utils.js';
3
3
  export function buildAbilityFromJson(user) {
4
4
  return createPrismaAbility(user.permissions, {
5
- detectSubjectType,
5
+ detectSubjectType
6
6
  });
7
7
  }
8
8
  export default buildAbilityFromJson;
@@ -1,5 +1,5 @@
1
1
  import { getDocumentsFields } from '../../utils.js';
2
- export const defineRoleAbilitiesBusinessDevelopmentExecutive = async (can, cannot) => {
2
+ export const defineRoleAbilitiesBusinessDevelopmentExecutive = async (can, cannot)=>{
3
3
  can('read', [
4
4
  'Subscription',
5
5
  'Vehicle',
@@ -13,22 +13,35 @@ export const defineRoleAbilitiesBusinessDevelopmentExecutive = async (can, canno
13
13
  'PaymentLink',
14
14
  'Invoice',
15
15
  'Transaction',
16
- 'Refund',
16
+ 'Refund'
17
17
  ]);
18
18
  cannot('update', 'Invoice');
19
- can('manage', ['Vehicle', 'ServiceCenter', 'Host', 'Inquiry', 'Token']);
19
+ can('manage', [
20
+ 'Vehicle',
21
+ 'ServiceCenter',
22
+ 'Host',
23
+ 'Inquiry',
24
+ 'Token'
25
+ ]);
20
26
  can('readPricingInput', 'Vehicle');
21
27
  can('connectHostToStripe', 'Host');
22
- can('update', 'Subscription', ['vehicleId']);
28
+ can('update', 'Subscription', [
29
+ 'vehicleId'
30
+ ]);
23
31
  cannot('read', 'User', 'status');
24
32
  cannot('read', 'User', [
25
33
  ...getDocumentsFields('identification'),
26
34
  ...getDocumentsFields('drivingHistory'),
27
35
  ...getDocumentsFields('financial'),
28
- ...getDocumentsFields('offerLetter'),
36
+ ...getDocumentsFields('offerLetter')
37
+ ]);
38
+ can([
39
+ 'viewSubscriptionApproval'
40
+ ], 'Subscription');
41
+ cannot('read', [
42
+ 'Vacancy',
43
+ 'Applicant'
29
44
  ]);
30
- can(['viewSubscriptionApproval'], 'Subscription');
31
- cannot('read', ['Vacancy', 'Applicant']);
32
45
  can('read', 'Activity');
33
46
  can('read', 'ActivityTask');
34
47
  };
@@ -1,3 +1,5 @@
1
- export const defineRoleAbilitiesCeo = async (can) => {
2
- can(['manage'], 'all');
1
+ export const defineRoleAbilitiesCeo = async (can)=>{
2
+ can([
3
+ 'manage'
4
+ ], 'all');
3
5
  };
@@ -1,9 +1,11 @@
1
- export const defineRoleAbilitiesCommonAdmin = async (can) => {
2
- can(['read'], [
1
+ export const defineRoleAbilitiesCommonAdmin = async (can)=>{
2
+ can([
3
+ 'read'
4
+ ], [
3
5
  'Log',
4
6
  'Issue',
5
7
  'SubscriptionContract',
6
8
  'HostContribution',
7
- 'SubscriptionEvent',
9
+ 'SubscriptionEvent'
8
10
  ]);
9
11
  };
@@ -1,5 +1,5 @@
1
1
  import { getDocumentsFields } from '../../utils.js';
2
- export const defineRoleAbilitiesConcierge = async (can, cannot) => {
2
+ export const defineRoleAbilitiesConcierge = async (can, cannot)=>{
3
3
  can('read', [
4
4
  'Subscription',
5
5
  'Cycle',
@@ -12,11 +12,14 @@ export const defineRoleAbilitiesConcierge = async (can, cannot) => {
12
12
  'Inquiry',
13
13
  'Discount',
14
14
  'PlatformConfig',
15
- 'PaymentLink',
15
+ 'PaymentLink'
16
16
  ]);
17
17
  cannot('create', 'Business');
18
18
  can('manage', 'ServiceCenter');
19
- can('update', 'Vehicle', ['images', 'allowedServiceCenterIds']);
19
+ can('update', 'Vehicle', [
20
+ 'images',
21
+ 'allowedServiceCenterIds'
22
+ ]);
20
23
  can('readPricingInput', 'Vehicle');
21
24
  can('update', 'Host', 'serviceCenterIds');
22
25
  can('manage', 'Subscription');
@@ -30,16 +33,38 @@ export const defineRoleAbilitiesConcierge = async (can, cannot) => {
30
33
  'payerType',
31
34
  'driversIds',
32
35
  'drivers',
33
- 'vehicleId',
36
+ 'vehicleId'
37
+ ]);
38
+ can([
39
+ 'read'
40
+ ], [
41
+ 'Invoice',
42
+ 'Transaction',
43
+ 'Refund'
34
44
  ]);
35
- can(['read'], ['Invoice', 'Transaction', 'Refund']);
36
45
  cannot('read', 'User', [
37
46
  ...getDocumentsFields('drivingHistory'),
38
47
  ...getDocumentsFields('financial'),
39
- ...getDocumentsFields('offerLetter'),
48
+ ...getDocumentsFields('offerLetter')
49
+ ]);
50
+ can([
51
+ 'manage'
52
+ ], [
53
+ 'Activity',
54
+ 'ActivityTask'
55
+ ]);
56
+ cannot([
57
+ 'create',
58
+ 'delete'
59
+ ], [
60
+ 'Activity',
61
+ 'ActivityTask'
62
+ ]);
63
+ can([
64
+ 'viewSubscriptionApproval'
65
+ ], 'Subscription');
66
+ cannot('read', [
67
+ 'Vacancy',
68
+ 'Applicant'
40
69
  ]);
41
- can(['manage'], ['Activity', 'ActivityTask']);
42
- cannot(['create', 'delete'], ['Activity', 'ActivityTask']);
43
- can(['viewSubscriptionApproval'], 'Subscription');
44
- cannot('read', ['Vacancy', 'Applicant']);
45
70
  };