73
73
74
74
define ( 'CCGN_USER_ROLE_CC_LEGAL_TEAM ' , 'membership-cc-legal ' );
75
75
76
+ // User is a sub admin. new profile added on Octobre, 2018
77
+ // The purpose is a rol that can only see some applications data on the admin screens
78
+ // the sub-admin can't make any action
79
+
80
+ define ('CCGN_USER_ROLE_SUB_ADMIN ' , 'membership-cc-sub-admin ' );
81
+
76
82
// Which Field Groups different levels of registration/vouching can see
77
83
// Admin users are handled separately
78
84
@@ -135,6 +141,10 @@ function ccgn_add_roles_on_plugin_activation () {
135
141
$ approver ->add_cap ( 'ccgn_view_applications ' );
136
142
$ legal ->add_cap ( 'ccgn_view_applications ' );
137
143
144
+ $ council ->add_cap ('ccgn_sub_admin_view ' );
145
+ $ approver ->add_cap ('ccgn_sub_admin_view ' );
146
+ $ legal ->add_cap ('ccgn_sub_admin_view ' );
147
+
138
148
$ council ->add_cap ( 'ccgn_list_applications ' );
139
149
$ approver ->add_cap ( 'ccgn_list_applications ' );
140
150
$ legal ->add_cap ( 'ccgn_list_applications ' );
@@ -144,8 +154,34 @@ function ccgn_add_roles_on_plugin_activation () {
144
154
$ legal ->add_cap ( 'ccgn_list_applications_legal ' );
145
155
// The Final Approver can list but not approve legal-stage applications
146
156
$ approver ->add_cap ( 'ccgn_list_applications_legal ' );
157
+ //Create sub_admin role
158
+ add_sub_admin_role ();
147
159
}
148
160
161
+ // The subadmin function have the permission to see the application list
162
+ // but can not make any actions
163
+
164
+ function add_sub_admin_role () {
165
+ $ result = add_role (
166
+ CCGN_USER_ROLE_SUB_ADMIN ,
167
+ 'CC Sub Administrator ' ,
168
+ array ()
169
+ );
170
+ if (null !== $ result ) {
171
+ $ sub_admin = get_role (CCGN_USER_ROLE_SUB_ADMIN );
172
+ $ sub_admin ->add_cap ('ccgn_view_applications ' );
173
+ $ sub_admin ->add_cap ('ccgn_list_applications ' );
174
+ $ sub_admin ->add_cap ('ccgn_sub_admin_view ' );
175
+ $ sub_admin ->add_cap ('ccgn_list_applications_legal ' );
176
+ }
177
+ $ council = get_role (CCGN_USER_ROLE_MEMBERSHIP_COUNCIL );
178
+ $ approver = get_role (CCGN_USER_ROLE_FINAL_APPROVER );
179
+ $ legal = get_role (CCGN_USER_ROLE_CC_LEGAL_TEAM );
180
+
181
+ $ council ->add_cap ('ccgn_sub_admin_view ' );
182
+ $ approver ->add_cap ('ccgn_sub_admin_view ' );
183
+ $ legal ->add_cap ('ccgn_sub_admin_view ' );
184
+ }
149
185
function ccgn_user_is_new ( $ user_id ) {
150
186
$ new = true ;
151
187
$ user = get_user_by ( 'ID ' , $ user_id );
@@ -227,11 +263,22 @@ function ccgn_current_user_is_legal_team () {
227
263
}
228
264
return $ is ;
229
265
}
266
+ function ccgn_current_user_is_sub_admin ()
267
+ {
268
+ $ is = false ;
269
+ if (is_user_logged_in ()) {
270
+ $ user_id = get_current_user_id ();
271
+ $ data = get_userdata ($ user_id );
272
+ $ is = in_array (CCGN_USER_ROLE_SUB_ADMIN , $ data ->roles );
273
+ }
274
+ return $ is ;
275
+ }
230
276
231
277
function ccgn_current_user_can_see_user_application_page () {
232
278
return ccgn_current_user_is_membership_council ()
233
279
|| ccgn_current_user_is_final_approver ()
234
- || ccgn_current_user_is_legal_team ();
280
+ || ccgn_current_user_is_legal_team ()
281
+ || ccgn_current_user_is_sub_admin ();
235
282
}
236
283
237
284
////////////////////////////////////////////////////////////////////////////////
0 commit comments