-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
embargo roles whitelist #232
Changes from all commits
1f9eae7
bfc85f2
b90ac10
ce16056
ec41b8f
420aa12
ba4026a
cb20e6d
8070e7e
8dcf23c
35a2baf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<?php | ||
|
||
/** | ||
* @file | ||
* Admin form for setting embargo view/manage roles. | ||
*/ | ||
|
||
/** | ||
* Embargo roles admin management form. | ||
* | ||
* @param array $form | ||
* The Drupal form. | ||
* @param array $form_state | ||
* The Drupal form state. | ||
* | ||
* @return array | ||
* The form definition. | ||
*/ | ||
function islandora_scholar_embargo_manage_roles_admin_form($form, $form_state) { | ||
module_load_include('inc', 'islandora_scholar_embargo', 'includes/embargo'); | ||
return array( | ||
'roles_wrapper' => array( | ||
'#type' => 'fieldset', | ||
'#title' => t('Roles'), | ||
'#collapsible' => FALSE, | ||
'islandora_scholar_embargo_whitelisted_roles' => array( | ||
'#type' => 'checkboxes', | ||
'#description' => t('Check off all the roles that should have access to embargoed items. <strong>NOTE:</strong> since embargo XACML role entries are whitelists, embargoed objects in a Fedora repository shared between Drupal sites will be visible to the same role in both sites. Consider using site-unique roles when dealing with shared repositories.'), | ||
'#options' => user_roles(TRUE, ISLANDORA_SCHOLAR_EMBARGO_CAN_EMBARGO_ANY), | ||
'#default_value' => array_keys(variable_get('islandora_scholar_embargo_whitelisted_roles', array())), | ||
), | ||
), | ||
'note' => array( | ||
'#markup' => t('Saving and applying will initiate a batch to modify the XACML policies of all embargoed objects. Bear in mind that this can take a long time to execute depending on the number of items to be embargoed, and that it may be more prudent to run the Drush command <code>islandora_scholar_embargo_apply_roles_to_embargoed_objects</code> instead. Number of embargoed objects at time of page load: <strong>@number</strong>', array( | ||
'@number' => number_format(islandora_scholar_embargo_get_all_embargoed(TRUE)), | ||
)), | ||
), | ||
'submit_buttons' => array( | ||
'#type' => 'actions', | ||
'save' => array( | ||
'#type' => 'submit', | ||
'#value' => t('Save Without Applying'), | ||
'#name' => 'save', | ||
), | ||
'save_and_apply' => array( | ||
'#type' => 'submit', | ||
'#value' => t('Save And Apply'), | ||
'#name' => 'save_and_apply', | ||
), | ||
), | ||
); | ||
} | ||
|
||
/** | ||
* Submit handler for the roles management form. | ||
* | ||
* @param array $form | ||
* The submitted roles admin form. | ||
* @param array $form_state | ||
* The state of the submitted form. | ||
*/ | ||
function islandora_scholar_embargo_manage_roles_admin_form_submit($form, &$form_state) { | ||
// Attach role names to role IDs to make it more useful as a variable. | ||
$whitelist = array(); | ||
foreach (array_filter($form_state['values']['islandora_scholar_embargo_whitelisted_roles']) as $rid => $checked) { | ||
$whitelist[$rid] = $form['roles_wrapper']['islandora_scholar_embargo_whitelisted_roles']['#options'][$rid]; | ||
} | ||
variable_set('islandora_scholar_embargo_whitelisted_roles', $whitelist); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. whooops There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, still? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 420aa12 |
||
|
||
// Kick off the batch if we were asked. | ||
if ($form_state['triggering_element']['#name'] == 'save_and_apply') { | ||
module_load_include('inc', 'islandora_scholar_embargo', 'includes/batch'); | ||
batch_set(islandora_scholar_embargo_reapply_embargoes_batch()); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm... not sure I understand what's going on here. If there's an entry in
$options
, we reset its value to itself?Are we looking for something more like:
instead of this
foreach
over$selected
?... Actually... This was some craziness to establish the "desired" ordering or something, was it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's just because it's possible for those options not to be returned in
islandora_get_content_models()
due to XACML or other what-have-ye's, so$options[$cmodel]
may not exist. But yeah, there's probably a more PHP-weird-array-business way to do it?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it wasn't so much the
isset()
, but the whole: "options = one of it's items + the rest of it"... Which would only have the affect of (re)ordering the array...?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps the intention was to place the current config at the top? Because ... UI design? I dunno?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shrug. Is fine.