Skip to content

Commit

Permalink
check permission when creating annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
sprklinginfo committed Jan 5, 2016
1 parent 5bf20d7 commit 7ed2718
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
27 changes: 20 additions & 7 deletions includes/annotation.inc
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,26 @@ function _retrieve_web_annotations(AbstractObject $object) {
*/
function _create_web_annotation() {
// @todo: add a new annotation.
// Retrieve our POST DATA
$data = $_POST['annotation'];
debug($_POST);
// return drupal_json_output(array('message' => 'posted', 'results' => $_POST));
// return drupal_json_output($_POST);
// return 'A new annotation is added.';
return drupal_json_output(array('annotation' => $_POST, 'response' => 'success'));
if (user_access(ISLANDORA_WEB_ANNOTATION_CREATE)) {

return drupal_json_output(array(
'annotation' => $_POST,
'response' => array(
'code' => 'success',
'message' => 'New annotation is created'
)
));

}
else {
return drupal_json_output(array(
'response' => array(
'code' => 'error',
'message' => 'No permission to create annotation'
)
));
}

}

/**
Expand Down
2 changes: 1 addition & 1 deletion js/annotationApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
data: annotation,
success: (function (data) {
console.log(data);
if (data.response == 'success') {
if (data.response.code == 'success') {
arr.push(annotation);
this.setState({ annotations: arr });
this.setState({ adding: false }); // Hide the form after submission
Expand Down
2 changes: 1 addition & 1 deletion js/source/annotationApp.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
data: annotation,
success: function(data) {
console.log(data);
if (data.response == 'success') {
if (data.response.code == 'success') {
arr.push(annotation);
this.setState({annotations: arr});
this.setState({adding: false}); // Hide the form after submission
Expand Down

0 comments on commit 7ed2718

Please sign in to comment.