2
2
3
3
import type { Subscription } from './UserSubscriptions'
4
4
5
+ /**
6
+ * The permission types that can be defined in the user profile object
7
+ * and which determine a user's role and permissions within the application's
8
+ * modules.
9
+ */
10
+ export type PermissionType =
11
+ // Items related to GTFS editing (NOTE: these end in -gtfs not -feed).
12
+ 'edit-gtfs' | 'approve-gtfs' |
13
+ // Items related to feed source management.
14
+ 'manage-feed' | 'view-feed' |
15
+ // MTC alerts module items
16
+ 'approve-alert' | 'edit-alert' |
17
+ // Privileges related to administration of applications, organizations,
18
+ // and projects.
19
+ 'administer-application' | 'administer-organization' | 'administer-project'
20
+
5
21
export type Permission = {
6
22
feeds ?: Array < string > ,
7
- type : string
23
+ type : PermissionType
8
24
}
9
25
10
26
type Project = {
@@ -103,7 +119,7 @@ export default class UserPermissions {
103
119
this . getOrganizationPermission ( orgId , 'administer-organization' ) != null
104
120
}
105
121
106
- getOrganizationPermission ( organizationId : string , permissionType : string ) {
122
+ getOrganizationPermission ( organizationId : string , permissionType : PermissionType ) {
107
123
if ( ! this . hasOrganization ( organizationId ) ) return null
108
124
for ( const permission of this . getOrganizationPermissions ( organizationId ) ) {
109
125
if ( permission . type === permissionType ) return permission
@@ -138,13 +154,13 @@ export default class UserPermissions {
138
154
return this . projectLookup [ projectId ] . defaultFeeds || [ ]
139
155
}
140
156
141
- hasProjectPermission ( organizationId : ?string , projectId : string , permissionType : string ) {
157
+ hasProjectPermission ( organizationId : ?string , projectId : string , permissionType : PermissionType ) {
142
158
if ( this . isProjectAdmin ( projectId , organizationId ) ) return true
143
159
const p = this . getProjectPermission ( projectId , permissionType )
144
160
return ( p !== null )
145
161
}
146
162
147
- getProjectPermission ( projectId : string , permissionType : string ) : ?Permission {
163
+ getProjectPermission ( projectId : string , permissionType : PermissionType ) : ?Permission {
148
164
if ( ! this . hasProject ( projectId ) ) return null
149
165
var projectPermissions = this . getProjectPermissions ( projectId )
150
166
for ( const permission of projectPermissions ) {
@@ -159,7 +175,7 @@ export default class UserPermissions {
159
175
return null
160
176
}
161
177
162
- hasFeedPermission ( organizationId : ?string , projectId : string , feedId : string , permissionType : string ) {
178
+ hasFeedPermission ( organizationId : ?string , projectId : string , feedId : string , permissionType : PermissionType ) {
163
179
if ( this . isProjectAdmin ( projectId , organizationId ) ) return true
164
180
const permission = this . getProjectPermission ( projectId , permissionType )
165
181
if ( permission ) {
0 commit comments