diff --git a/js/components/ascribe_table/table_item_acl_filtered.js b/js/components/ascribe_table/table_item_acl_filtered.js
index 562f1268..b3a6adb7 100644
--- a/js/components/ascribe_table/table_item_acl_filtered.js
+++ b/js/components/ascribe_table/table_item_acl_filtered.js
@@ -5,16 +5,18 @@ import React from 'react';
let TableItemAclFiltered = React.createClass({
propTypes: {
- content: React.PropTypes.array.isRequired
+ content: React.PropTypes.object.isRequired
},
render() {
- var availableAcls = ['consign', 'loan', 'transfer', 'view', 'consign request', 'unconsign request', 'loan request'];
+ var availableAcls = ['acl_consign', 'acl_loan', 'acl_transfer', 'acl_view', 'acl_share', 'acl_unshare'];
- let filteredAcls = this.props.content.filter((v) => {
- return availableAcls.indexOf(v) > -1;
+ let filteredAcls = Object.keys(this.props.content).filter((key) => {
+ return availableAcls.indexOf(key) > -1 && this.props.content[key];
});
+ filteredAcls = filteredAcls.map((acl) => acl.split('acl_')[1]);
+
return (
{filteredAcls.join('/')}
diff --git a/js/constants/application_constants.js b/js/constants/application_constants.js
index 61955469..2a8e0807 100644
--- a/js/constants/application_constants.js
+++ b/js/constants/application_constants.js
@@ -9,11 +9,10 @@ let constants = {
'apiEndpoint': window.API_ENDPOINT,
'serverUrl': window.SERVER_URL,
'baseUrl': window.BASE_URL,
- 'aclList': ['edit', 'consign', 'consign_request', 'unconsign', 'unconsign_request', 'transfer',
- 'loan', 'loan_request', 'share', 'download', 'view', 'delete', 'del_from_collection', 'add_to_collection'],
+ 'aclList': ['acl_coa', 'acl_consign', 'acl_delete', 'acl_download', 'acl_edit', 'acl_editions', 'acl_loan', 'acl_share', 'acl_transfer', 'acl_unconsign', 'acl_unshare', 'acl_view', 'acl_withdraw_transfer'],
// in case of whitelabel cusomization, we store stuff here
'whitelabel': {}
};
-export default constants;
+export default constants;
\ No newline at end of file
diff --git a/js/utils/acl_utils.js b/js/utils/acl_utils.js
index a29aa7bf..4f287c96 100644
--- a/js/utils/acl_utils.js
+++ b/js/utils/acl_utils.js
@@ -1,23 +1,50 @@
'use strict';
+import { sanitize } from './general_utils';
+
+function intersectAcls(a, b) {
+ return a.filter((val) => b.indexOf(val) > -1);
+}
+
export function getAvailableAcls(editions) {
let availableAcls = [];
+ // if you copy a javascript array of objects using slice, then
+ // the object reference is still there.
+ // Therefore we need to do this ugly copying
+ let editionsCopy = JSON.parse(JSON.stringify(editions));
+
+ // sanitize object acls in editions
+ // so that they don't contain any falsy key-value pairs anymore
+ editionsCopy = editionsCopy.map((edition) => {
+ // acl also returns the piece id and the edition id
+ // therefore, we're going to remove it
+ edition.acl.edition = false;
+ edition.acl.piece = false;
+
+ edition.acl = sanitize(edition.acl, (val) => !val);
+ edition.acl = Object.keys(edition.acl);
+ return edition;
+ });
+
// If no edition has been selected, availableActions is empty
// If only one edition has been selected, their actions are available
// If more than one editions have been selected, their acl properties are intersected
- if(editions.length >= 1) {
- availableAcls = editions[0].acl;
+ if(editionsCopy.length >= 1) {
+ availableAcls = editionsCopy[0].acl;
}
- if(editions.length >= 2) {
- for(let i = 1; i < editions.length; i++) {
- availableAcls = intersectAcls(availableAcls, editions[i].acl);
+ if(editionsCopy.length >= 2) {
+ for(let i = 1; i < editionsCopy.length; i++) {
+ availableAcls = intersectAcls(availableAcls, editionsCopy[i].acl);
}
}
- return availableAcls;
-}
+ // convert acls back to key-value object
+ let availableAclsObj = {};
+ for(let i = 0; i < availableAcls.length; i++) {
+ availableAclsObj[availableAcls[i]] = true;
+ }
-export function intersectAcls(a, b) {
- return a.filter((val) => b.indexOf(val) > -1);
+
+ return availableAclsObj;
}
\ No newline at end of file
diff --git a/js/utils/general_utils.js b/js/utils/general_utils.js
index 0bddb765..5e5d9298 100644
--- a/js/utils/general_utils.js
+++ b/js/utils/general_utils.js
@@ -3,21 +3,22 @@
/**
* Takes an object and deletes all keys that are
*
- * - empty strings; or
- * - null; or
- * - undefined
- *
+ * tagged as false by the passed in filter function
*
* @param {object} obj regular javascript object
* @return {object} regular javascript object without null values or empty strings
*/
-export function sanitize(obj) {
+export function sanitize(obj, filterFn) {
+ if(!filterFn) {
+ // By matching null with a double equal, we can match undefined and null
+ // http://stackoverflow.com/a/15992131
+ filterFn = (val) => val == null || val === '';
+ }
+
Object
.keys(obj)
.map((key) => {
- // By matching null with a double equal, we can match undefined and null
- // http://stackoverflow.com/a/15992131
- if(obj[key] == null || obj[key] === '') {
+ if(filterFn(obj[key])) {
delete obj[key];
}
});