Skip to content

Commit a384e57

Browse files
authored
Merge pull request #289 from creativecommons/staging
Add new user role sub_admin to see but not edit applications data
2 parents 94085e9 + 600fca2 commit a384e57

File tree

5 files changed

+63
-10
lines changed

5 files changed

+63
-10
lines changed

plugins/cc-global-network/admin/assets/js/script.js

+9-4
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,15 @@ jQuery(document).ready(function($){
208208
{
209209
'targets': 7,
210210
'render' : function(data, type, row, meta) {
211-
var output = '<span class="inline-buttons">';
212-
output += '<a href="?page=global-network-application-change-vouchers&user_id=' + data.ID + '" target="_blank" class="button button-icon change_vouchers" data-user-id="' + data.ID + '" title="Change Vouchers"><span class="dashicons dashicons-universal-access-alt"></span></a>';
213-
output += '<button class="button button-icon reset_vouchers" onClick="$.resetVouchers(' + data.ID + ')" data-user-id="' + data.ID + '" title="Reset Vouchers selection"><span class="dashicons dashicons-image-rotate"></span></button>';
214-
output += '</span>';
211+
var output = '';
212+
if (wpApiSettings.is_sub_admin != 'yes') {
213+
output += '<span class="inline-buttons">';
214+
output += '<a href="?page=global-network-application-change-vouchers&user_id=' + data.ID + '" target="_blank" class="button button-icon change_vouchers" data-user-id="' + data.ID + '" title="Change Vouchers"><span class="dashicons dashicons-universal-access-alt"></span></a>';
215+
output += '<button class="button button-icon reset_vouchers" onClick="$.resetVouchers(' + data.ID + ')" data-user-id="' + data.ID + '" title="Reset Vouchers selection"><span class="dashicons dashicons-image-rotate"></span></button>';
216+
output += '</span>';
217+
} else {
218+
output += 'No actions';
219+
}
215220
return output;
216221
}
217222
}

plugins/cc-global-network/admin/list-members.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ function ccgn_application_list_members_menu () {
282282
'global-network-application-approval',
283283
'List Members',
284284
'List Members',
285-
'ccgn_pre_approve',
285+
'ccgn_sub_admin_view',
286286
'global-network-list-users',
287287
'ccgn_list_members_admin_page'
288288
);

plugins/cc-global-network/admin/user-application-page.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -436,9 +436,9 @@ function ccgn_application_users_page_render_state ( $applicant_id, $state ) {
436436
echo _('<h3>Pre-Approve</h3>');
437437
ccgn_application_users_page_pre_form ( $applicant_id );
438438
} elseif ( $state == CCGN_APPLICATION_STATE_VOUCHING ) {
439-
echo _('<h3>Vote</h3>');
440-
ccgn_application_users_page_vote_form ( $applicant_id );
441-
if ( ccgn_current_user_is_final_approver() ) {
439+
if (ccgn_current_user_is_final_approver()) {
440+
echo _('<h3>Vote</h3>');
441+
ccgn_application_users_page_vote_form ( $applicant_id );
442442
echo _('<h3>Final Approval</h3>');
443443
ccgn_application_users_page_final_approval_form( $applicant_id );
444444
}

plugins/cc-global-network/cc-global-network.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ function ccgn_admin_enqueue_scripts($hook_suffix) {
365365
'current_user' => get_current_user_id(),
366366
'site_epoch' => CCGN_SITE_EPOCH,
367367
'date_now' => date("Y-m-d"),
368-
'ajax_url' => admin_url('admin-ajax.php')
368+
'ajax_url' => admin_url('admin-ajax.php'),
369+
'is_sub_admin' => (ccgn_current_user_is_sub_admin()) ? 'yes' : 'no'
369370
));
370371
}
371372
}

plugins/cc-global-network/includes/buddypress-integration.php

+48-1
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,12 @@
7373

7474
define( 'CCGN_USER_ROLE_CC_LEGAL_TEAM', 'membership-cc-legal' );
7575

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+
7682
// Which Field Groups different levels of registration/vouching can see
7783
// Admin users are handled separately
7884

@@ -135,6 +141,10 @@ function ccgn_add_roles_on_plugin_activation () {
135141
$approver->add_cap( 'ccgn_view_applications' );
136142
$legal->add_cap( 'ccgn_view_applications' );
137143

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+
138148
$council->add_cap( 'ccgn_list_applications' );
139149
$approver->add_cap( 'ccgn_list_applications' );
140150
$legal->add_cap( 'ccgn_list_applications' );
@@ -144,8 +154,34 @@ function ccgn_add_roles_on_plugin_activation () {
144154
$legal->add_cap( 'ccgn_list_applications_legal' );
145155
// The Final Approver can list but not approve legal-stage applications
146156
$approver->add_cap( 'ccgn_list_applications_legal' );
157+
//Create sub_admin role
158+
add_sub_admin_role();
147159
}
148160

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+
}
149185
function ccgn_user_is_new ( $user_id ) {
150186
$new = true;
151187
$user = get_user_by( 'ID', $user_id );
@@ -227,11 +263,22 @@ function ccgn_current_user_is_legal_team () {
227263
}
228264
return $is;
229265
}
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+
}
230276

231277
function ccgn_current_user_can_see_user_application_page () {
232278
return ccgn_current_user_is_membership_council ()
233279
|| 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();
235282
}
236283

237284
////////////////////////////////////////////////////////////////////////////////

0 commit comments

Comments
 (0)