Skip to content
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

[ACA-213] Edit Offline - permissions #911

Merged
merged 10 commits into from
Feb 5, 2019
2 changes: 1 addition & 1 deletion src/app/extensions/core.extensions.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export class CoreExtensionsModule {

extensions.setEvaluators({
'app.selection.canDelete': app.canDeleteSelection,
'app.selection.canEditLockedFile': app.canEditLockedFile,
'app.selection.canToggleEditOffline': app.canToggleEditOffline,
'app.selection.canDownload': app.canDownloadSelection,
'app.selection.notEmpty': app.hasSelection,
'app.selection.canUnshare': app.canUnshareNodes,
Expand Down
26 changes: 23 additions & 3 deletions src/app/extensions/evaluators/app.evaluators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,14 +308,34 @@ export function isWriteLocked(
);
}

export function canEditLockedFile(
export function isUserWriteLock(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would suggest isUserWriteLockOwner as name

context: AppRuleContext,
...args: RuleParameter[]
): boolean {
return !!(
!isWriteLocked(context, ...args) ||
console.log(context.profile);
return (
isWriteLocked(context, ...args) &&
(context.selection.file.entry.properties['cm:lockOwner'] &&
context.selection.file.entry.properties['cm:lockOwner'].id ===
context.profile.id)
);
}

export function isAdmin(
context: AppRuleContext,
...args: RuleParameter[]
): boolean {
return context.profile.id === 'admin';
}

export function canToggleEditOffline(
context: AppRuleContext,
...args: RuleParameter[]
): boolean {
return (
(!isWriteLocked(context, ...args) &&
canUpdateSelectedNode(context, ...args)) ||
isUserWriteLock(context, ...args) ||
isAdmin(context, ...args)
);
}
14 changes: 7 additions & 7 deletions src/assets/app.extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
"parameters": [
{ "type": "rule", "value": "app.selection.file" },
{ "type": "rule", "value": "app.navigation.isNotTrashcan" },
{ "type": "rule", "value": "app.selection.canEditLockedFile" },
{ "type": "rule", "value": "app.selection.canToggleEditOffline" },
{
"type": "rule",
"value": "core.not",
Expand Down Expand Up @@ -223,16 +223,16 @@
"type": "core.every",
"parameters": [
{ "type": "rule", "value": "app.selection.canDelete" },
{ "type": "rule", "value": "app.selection.canEditLockedFile" },
{ "type": "rule", "value": "app.selection.canToggleEditOffline" },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the tests are failing cause of this.

{ "type": "rule", "value": "app.navigation.isNotTrashcan" }
]
},
{
"id": "app.toolbar.canEditLockedFile",
"id": "app.toolbar.canToggleEditOffline",
"type": "core.every",
"parameters": [
{ "type": "rule", "value": "app.selection.file" },
{ "type": "rule", "value": "app.selection.canEditLockedFile" },
{ "type": "rule", "value": "app.selection.canToggleEditOffline" },
{ "type": "rule", "value": "app.navigation.isNotTrashcan" },
{
"type": "rule",
Expand Down Expand Up @@ -538,7 +538,7 @@
"type": "custom",
"component": "app.toolbar.toggleEditOffline",
"rules": {
"visible": "app.toolbar.canEditLockedFile"
"visible": "app.toolbar.canToggleEditOffline"
}
},
{
Expand Down Expand Up @@ -676,7 +676,7 @@
"type": "custom",
"component": "app.toolbar.toggleEditOffline",
"rules": {
"visible": "app.toolbar.canEditLockedFile"
"visible": "app.toolbar.canToggleEditOffline"
}
},
{
Expand Down Expand Up @@ -975,7 +975,7 @@
"type": "custom",
"component": "app.toolbar.toggleEditOffline",
"rules": {
"visible": "app.toolbar.canEditLockedFile"
"visible": "app.toolbar.canToggleEditOffline"
}
},
{
Expand Down