Skip to content

Commit

Permalink
Work on #51.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjordan committed Feb 4, 2018
1 parent 6cfb327 commit f75ac72
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
28 changes: 21 additions & 7 deletions islandora_context.module
Expand Up @@ -329,6 +329,16 @@ function islandora_context_islandora_view_object(AbstractObject $object) {
if ($plugin = context_get_plugin('condition', 'islandora_context_condition_rdf_requested')) {
$plugin->execute($object);
}
// We call this plugin here since redirection, in this case to a proxy URL, has to happen
// in this hook. Access to the object is handled in hook_islandora_object_access().
if ($plugin = context_get_plugin('reaction', 'islandora_context_reaction_restrict_by_ip')) {
$redirect = $plugin->execute($object);
if (is_array($redirect)) {
global $base_url;
$redirect_target = $redirect[0] . $base_url . '/islandora/object/' . $object->id;
drupal_goto($redirect_target);
}
}

return array();
}
Expand Down Expand Up @@ -393,22 +403,26 @@ function islandora_context_islandora_object_access($op, $object, $user) {
}
}

// Handle non-REST requests.
// Handle non-REST requests, which need to delegate redirecting to a proxy
// hook_islandora_view_object().
if (is_array($ip_is_allowed)) {
// First member will be the redirect URL, and second, if present,
// will be a boolean indicating whether to append the object's URL
// to the redirect URL.
// to the redirect URL. If this is the case, retun NULL so
// hook_islandora_view_object() can redirect the user to the proxy URL.
if (count($ip_is_allowed) == 1) {
drupal_goto($ip_is_allowed[0]);
if (is_array($ip_is_allowed)) {
return NULL;
}
else {
return FALSE;
}
}
else {
// Make an exception to the redirect for thumbnails, since
// they should be viewable by everyone.
// if (!preg_match('#datastream/TN/view|rest/v+/object/.+/datastream/TN#', $current_path)) {
if (!preg_match('#datastream/TN/view#', $current_path)) {
global $base_url;
$redirect_target = $ip_is_allowed[0] . $base_url . '/' . $current_path;
drupal_goto($redirect_target);
return NULL;
}
}
return NULL;
Expand Down
2 changes: 1 addition & 1 deletion plugins/islandora_context_reaction_restrict_by_ip.inc
Expand Up @@ -66,7 +66,7 @@ class IslandoraContextReactionRestrictByIp extends context_reaction {
public function execute() {
$is_allowed = array();
foreach ($this->get_contexts() as $context) {
if (isset($context->reactions) && (!empty($context->reactions[$this->plugin]))) {
if (isset($context->reactions) && (!empty($context->reactions[$this->plugin]['allowed_ip_ranges']))) {
$configured_ranges = $context->reactions[$this->plugin]['allowed_ip_ranges'];
$is_allowed = $this->check_ip($configured_ranges);
if (in_array(1, $is_allowed)) {
Expand Down

0 comments on commit f75ac72

Please sign in to comment.