Skip to content

Commit 28fe033

Browse files
committed
fix(flow): add flow typing to user permission types
1 parent 1409672 commit 28fe033

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

lib/common/user/UserPermissions.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,25 @@
22

33
import type {Subscription} from './UserSubscriptions'
44

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+
521
export type Permission = {
622
feeds?: Array<string>,
7-
type: string
23+
type: PermissionType
824
}
925

1026
type Project = {
@@ -103,7 +119,7 @@ export default class UserPermissions {
103119
this.getOrganizationPermission(orgId, 'administer-organization') != null
104120
}
105121

106-
getOrganizationPermission (organizationId: string, permissionType: string) {
122+
getOrganizationPermission (organizationId: string, permissionType: PermissionType) {
107123
if (!this.hasOrganization(organizationId)) return null
108124
for (const permission of this.getOrganizationPermissions(organizationId)) {
109125
if (permission.type === permissionType) return permission
@@ -138,13 +154,13 @@ export default class UserPermissions {
138154
return this.projectLookup[projectId].defaultFeeds || []
139155
}
140156

141-
hasProjectPermission (organizationId: ?string, projectId: string, permissionType: string) {
157+
hasProjectPermission (organizationId: ?string, projectId: string, permissionType: PermissionType) {
142158
if (this.isProjectAdmin(projectId, organizationId)) return true
143159
const p = this.getProjectPermission(projectId, permissionType)
144160
return (p !== null)
145161
}
146162

147-
getProjectPermission (projectId: string, permissionType: string): ?Permission {
163+
getProjectPermission (projectId: string, permissionType: PermissionType): ?Permission {
148164
if (!this.hasProject(projectId)) return null
149165
var projectPermissions = this.getProjectPermissions(projectId)
150166
for (const permission of projectPermissions) {
@@ -159,7 +175,7 @@ export default class UserPermissions {
159175
return null
160176
}
161177

162-
hasFeedPermission (organizationId: ?string, projectId: string, feedId: string, permissionType: string) {
178+
hasFeedPermission (organizationId: ?string, projectId: string, feedId: string, permissionType: PermissionType) {
163179
if (this.isProjectAdmin(projectId, organizationId)) return true
164180
const permission = this.getProjectPermission(projectId, permissionType)
165181
if (permission) {

lib/common/util/permissions.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,14 @@
22

33
import {isModuleEnabled} from './config'
44

5+
import type {PermissionType} from '../user/UserPermissions'
56
import type {AlertEntity, Feed, Project} from '../../types'
67
import type {ManagerUserState} from '../../types/reducers'
78

89
export function getFeedsForPermission (
910
project: ?Project,
1011
user: ManagerUserState,
11-
permission: string
12+
permission: PermissionType
1213
): Array<Feed> {
1314
if (project && project.feedSources) {
1415
const {id, organizationId} = project

lib/types/reducers.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import type {
2323
Trip,
2424
UserProfile
2525
} from './'
26+
import type {PermissionType} from '../common/user/UserPermissions'
2627

2728
type FetchStatusSubState = {
2829
fetchStatus: FetchStatus
@@ -284,7 +285,7 @@ export type FilterState = {
284285
loadedFeeds: Array<any>,
285286
map: MapFilter,
286287
patternFilter: ?string,
287-
permissionFilter: string,
288+
permissionFilter: PermissionType,
288289
project: ?string,
289290
routeFilter: ?string,
290291
routeLimit: number,

0 commit comments

Comments
 (0)