Skip to content

Commit

Permalink
Fix pointer CLPs (#1556)
Browse files Browse the repository at this point in the history
* Fix pointer CLPs

* Restore removed new lines

* Add checks

Co-authored-by: Musa Yassin-Fort <musa.yassin@bureapr.com>
  • Loading branch information
mess-lelouch and Musa Yassin-Fort authored Jul 17, 2020
1 parent db9f7e2 commit 162fdd9
Showing 1 changed file with 41 additions and 22 deletions.
63 changes: 41 additions & 22 deletions src/components/PermissionsDialog/PermissionsDialog.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@ export default class PermissionsDialog extends React.Component {
// hide suggestions to avoid ugly footer overlap
this.refEntry.current.setHidden(hidden);
// also show indicator when input is not visible
this.refScrollHint.current.toggleActive(hidden);
// this.refScrollHint.current.toggleActive(hidden);
};

this.observer = new IntersectionObserver(callback, {
Expand Down Expand Up @@ -589,13 +589,15 @@ export default class PermissionsDialog extends React.Component {
perms.delete = perms.delete || Map();
perms.addField = perms.addField || Map();

(pointerPermsSubset.get = perms.get.pointerFields || []),
(pointerPermsSubset.find = perms.find.pointerFields || []),
(pointerPermsSubset.count = perms.count.pointerFields || []),
(pointerPermsSubset.create = perms.create.pointerFields || []),
(pointerPermsSubset.update = perms.update.pointerFields || []),
(pointerPermsSubset.delete = perms.delete.pointerFields || []),
(pointerPermsSubset.addField = perms.addField.pointerFields || []);
// The double check is necessary because the permissions object seems to be empty when accessing the CLP section
// if the class was recently created.
(pointerPermsSubset.get = permissions.get && permissions.get.pointerFields || []),
(pointerPermsSubset.find = permissions.find && permissions.find.pointerFields || []),
(pointerPermsSubset.count = permissions.count && permissions.count.pointerFields || []),
(pointerPermsSubset.create = permissions.create && permissions.create.pointerFields || []),
(pointerPermsSubset.update = permissions.update && permissions.update.pointerFields || []),
(pointerPermsSubset.delete = permissions.delete && permissions.delete.pointerFields || []),
(pointerPermsSubset.addField = permissions.addField && permissions.addField.pointerFields || []);
}

let pointerPerms = {};
Expand Down Expand Up @@ -764,6 +766,7 @@ export default class PermissionsDialog extends React.Component {
let nextKeys;
let nextEntryTypes;
let nextPerms = this.state.perms;
let nextPointerPerms = this.state.pointerPerms;

if (next.user || next.role) {
id = next.user ? next.user.id : next.role.id;
Expand Down Expand Up @@ -791,17 +794,32 @@ export default class PermissionsDialog extends React.Component {
}

// create new permissions
if (this.props.advanced) {
nextPerms = nextPerms.setIn(['get', key], true);
nextPerms = nextPerms.setIn(['find', key], true);
nextPerms = nextPerms.setIn(['count', key], true);
nextPerms = nextPerms.setIn(['create', key], true);
nextPerms = nextPerms.setIn(['update', key], true);
nextPerms = nextPerms.setIn(['delete', key], true);
nextPerms = nextPerms.setIn(['addField', key], true);
if (next.pointer) {
if (this.props.advanced) {
nextPointerPerms = nextPointerPerms.setIn([entry, 'get'], true)
nextPointerPerms = nextPointerPerms.setIn([entry, 'find'], true)
nextPointerPerms = nextPointerPerms.setIn([entry, 'count'], true)
nextPointerPerms = nextPointerPerms.setIn([entry, 'create'], true)
nextPointerPerms = nextPointerPerms.setIn([entry, 'update'], true)
nextPointerPerms = nextPointerPerms.setIn([entry, 'delete'], true)
nextPointerPerms = nextPointerPerms.setIn([entry, 'addField'], true)
} else {
nextPointerPerms = nextPointerPerms.setIn([entry, 'read'], true)
nextPointerPerms = nextPointerPerms.setIn([entry, 'write'], true)
}
} else {
nextPerms = nextPerms.setIn(['read', key], true);
nextPerms = nextPerms.setIn(['write', key], true);
if (this.props.advanced) {
nextPerms = nextPerms.setIn(['get', key], true);
nextPerms = nextPerms.setIn(['find', key], true);
nextPerms = nextPerms.setIn(['count', key], true);
nextPerms = nextPerms.setIn(['create', key], true);
nextPerms = nextPerms.setIn(['update', key], true);
nextPerms = nextPerms.setIn(['delete', key], true);
nextPerms = nextPerms.setIn(['addField', key], true);
} else {
nextPerms = nextPerms.setIn(['read', key], true);
nextPerms = nextPerms.setIn(['write', key], true);
}
}

nextKeys = this.state.newKeys.concat([key]);
Expand All @@ -810,6 +828,7 @@ export default class PermissionsDialog extends React.Component {
return this.setState(
{
perms: nextPerms,
pointerPerms: nextPointerPerms,
newKeys: nextKeys,
entryTypes: nextEntryTypes,
newEntry: '',
Expand Down Expand Up @@ -911,7 +930,7 @@ export default class PermissionsDialog extends React.Component {
return;
}
if (k === 'requiresAuthentication' && !v){
// only acceppt requiresAuthentication with true
// only acceppt requiresAuthentication with true
return
}
if (v) {
Expand Down Expand Up @@ -964,7 +983,7 @@ export default class PermissionsDialog extends React.Component {
// types is immutable.js Map
const type = (types && types.get(key)) || {};

let pointer;
let pointer = this.state.pointerPerms.has(key);
let label = <span>{key}</span>;

if (type.user) {
Expand Down Expand Up @@ -996,7 +1015,7 @@ export default class PermissionsDialog extends React.Component {
</p>
</span>
);
} else if (type.pointer) {
} else if (pointer) {
// get class info from schema
let { type, targetClass } = columns[key];

Expand Down Expand Up @@ -1238,7 +1257,7 @@ export default class PermissionsDialog extends React.Component {
)}
{this.props.advanced
? this.state.pointers.map(pointer =>
this.renderRow(pointer, true)
this.renderRow(pointer, this.state.columns)
)
: null}
{this.state.newKeys.map(key =>
Expand Down

0 comments on commit 162fdd9

Please sign in to comment.