@@ -28,6 +28,7 @@ import {
28
28
methodIcons ,
29
29
methodLabels ,
30
30
} from "modules/notifications/utils" ;
31
+ import type { Permissions } from "modules/permissions" ;
31
32
import { type FC , Fragment } from "react" ;
32
33
import { useEffect } from "react" ;
33
34
import { Helmet } from "react-helmet-async" ;
@@ -46,22 +47,7 @@ const NotificationsPage: FC = () => {
46
47
} ,
47
48
{
48
49
...systemNotificationTemplates ( ) ,
49
- select : ( data : NotificationTemplate [ ] ) => {
50
- const groups = selectTemplatesByGroup ( data ) ;
51
-
52
- let displayedGroups : Record < string , NotificationTemplate [ ] > = {
53
- // Members only have access to the "Workspace Notifications" group.
54
- "Workspace Events" : groups [ "Workspace Events" ] ,
55
- } ;
56
-
57
- if ( permissions . viewDeploymentConfig ) {
58
- displayedGroups = groups ;
59
- } else if ( permissions . createTemplates ) {
60
- displayedGroups [ "Template Events" ] = groups [ "Template Events" ] ;
61
- }
62
-
63
- return displayedGroups ;
64
- } ,
50
+ select : ( data : NotificationTemplate [ ] ) => selectTemplatesByGroup ( data ) ,
65
51
} ,
66
52
notificationDispatchMethods ( ) ,
67
53
] ,
@@ -110,6 +96,10 @@ const NotificationsPage: FC = () => {
110
96
{ ready ? (
111
97
< Stack spacing = { 4 } >
112
98
{ Object . entries ( templatesByGroup . data ) . map ( ( [ group , templates ] ) => {
99
+ if ( ! canSeeNotificationGroup ( group , permissions ) ) {
100
+ return null ;
101
+ }
102
+
113
103
const allDisabled = templates . some ( ( tpl ) => {
114
104
return notificationIsDisabled ( disabledPreferences . data , tpl ) ;
115
105
} ) ;
@@ -218,6 +208,22 @@ const NotificationsPage: FC = () => {
218
208
219
209
export default NotificationsPage ;
220
210
211
+ function canSeeNotificationGroup (
212
+ group : string ,
213
+ permissions : Permissions ,
214
+ ) : boolean {
215
+ switch ( group ) {
216
+ case "Workspace Events" :
217
+ return true ;
218
+ case "Template Events" :
219
+ return permissions . createTemplates ;
220
+ case "User Events" :
221
+ return permissions . createUser ;
222
+ default :
223
+ return false ;
224
+ }
225
+ }
226
+
221
227
function notificationIsDisabled (
222
228
disabledPreferences : Record < string , boolean > ,
223
229
tmpl : NotificationTemplate ,
0 commit comments