moving canAssignUsers, canUnassignUsers to Site, adding specific interface
MODIFY
src/server/rest/v1/service/AuthorizationService.ts
src/server/rest/v1/service/AuthorizationService.ts
@@ -81,8 +81,6 @@ export default class AuthorizationService {
const siteAdminIDs = await AuthorizationService.getSiteAdminSiteIDs(tenant.id, userToken);
// Add canCreate flag to root
sites.canCreate = await Authorizations.canCreateSite(userToken);
- sites.canAssignUsers = await Authorizations.canAssignUsersSites(userToken);
- sites.canUnassignUsers = await Authorizations.canUnassignUsersSites(userToken);
// Enrich
for (const site of sites.result) {
await AuthorizationService.addSiteAuthorizations(tenant, userToken, site, siteAdminIDs);
@@ -104,6 +102,8 @@ export default class AuthorizationService {
site.canRead = await Authorizations.canReadSite(userToken);
site.canDelete = await Authorizations.canDeleteSite(userToken);
site.canUpdate = await Authorizations.canUpdateSite(userToken) && isSiteAdmin;
+ site.canAssignUsers = await Authorizations.canAssignUsersSites(userToken);
+ site.canUnassignUsers = await Authorizations.canUnassignUsersSites(userToken) && isSiteAdmin;
}
}

MODIFY
src/types/Authorization.ts
src/types/Authorization.ts
@@ -173,6 +173,9 @@ export interface AuthorizationActions {
canCreate?: boolean;
canUpdate?: boolean;
canDelete?: boolean;
+}
+
+export interface SiteAuthorizationActions extends AuthorizationActions {
canAssignUsers?: boolean;
canUnassignUsers?: boolean;
}

MODIFY
src/types/Site.ts
src/types/Site.ts
import Address from './Address';
-import { AuthorizationActions } from './Authorization';
import Company from './Company';
import ConnectorStats from './ConnectorStats';
import CreatedUpdatedProps from './CreatedUpdatedProps';
import SiteArea from './SiteArea';
+import { SiteAuthorizationActions } from './Authorization';
-export default interface Site extends CreatedUpdatedProps, AuthorizationActions {
+export default interface Site extends CreatedUpdatedProps, SiteAuthorizationActions {
id: string;
name: string;
issuer: boolean;

moving canAssignUsers, canUnassignUsers to Site, adding specific interface