diff --git a/demo-shell/resources/i18n/en.json b/demo-shell/resources/i18n/en.json
index 7a780718f5..ad91af01e7 100644
--- a/demo-shell/resources/i18n/en.json
+++ b/demo-shell/resources/i18n/en.json
@@ -153,5 +153,8 @@
"LIST":"List Tags Content Services",
"INSERT":"Insert Node ID",
"NODE_LIST":"Tag list By Node ID"
+ },
+ "DEMO_PERMISSION": {
+ "INHERIT_PERMISSION_BUTTON" :"Inherit Permission"
}
}
diff --git a/demo-shell/src/app/components/permissions/demo-permissions.component.html b/demo-shell/src/app/components/permissions/demo-permissions.component.html
index de8658fa88..39c20fe6da 100644
--- a/demo-shell/src/app/components/permissions/demo-permissions.component.html
+++ b/demo-shell/src/app/components/permissions/demo-permissions.component.html
@@ -1,2 +1,11 @@
-
-
+
+
+
+
+
diff --git a/demo-shell/src/app/components/permissions/demo-permissions.component.scss b/demo-shell/src/app/components/permissions/demo-permissions.component.scss
index e69de29bb2..a6da03dab0 100644
--- a/demo-shell/src/app/components/permissions/demo-permissions.component.scss
+++ b/demo-shell/src/app/components/permissions/demo-permissions.component.scss
@@ -0,0 +1,6 @@
+.inherit_permission_button {
+ padding-top: 20px;
+ display: flex;
+ justify-content: space-evenly;
+ padding-bottom: 20px;
+}
diff --git a/demo-shell/src/app/components/permissions/demo-permissions.component.ts b/demo-shell/src/app/components/permissions/demo-permissions.component.ts
index 294aab1f9d..ff24985340 100644
--- a/demo-shell/src/app/components/permissions/demo-permissions.component.ts
+++ b/demo-shell/src/app/components/permissions/demo-permissions.component.ts
@@ -15,8 +15,10 @@
* limitations under the License.
*/
-import { Component, Optional, OnInit } from '@angular/core';
+import { Component, Optional, OnInit, ViewChild } from '@angular/core';
import { ActivatedRoute, Params} from '@angular/router';
+import { PermissionListComponent } from '@alfresco/adf-content-services';
+import { MinimalNodeEntryEntity } from 'alfresco-js-api';
@Component({
selector: 'app-permissions',
@@ -25,6 +27,9 @@ import { ActivatedRoute, Params} from '@angular/router';
})
export class DemoPermissionComponent implements OnInit {
+ @ViewChild(PermissionListComponent)
+ displayPermissionComponent: PermissionListComponent;
+
nodeId: string;
constructor(@Optional() private route: ActivatedRoute) {
@@ -40,4 +45,8 @@ export class DemoPermissionComponent implements OnInit {
}
}
+ onUpdatedPermissions(node: MinimalNodeEntryEntity) {
+ this.displayPermissionComponent.reload();
+ }
+
}
diff --git a/docs/content-services/inherit-permission-directive.md b/docs/content-services/inherit-permission-directive.md
new file mode 100644
index 0000000000..18590ea05d
--- /dev/null
+++ b/docs/content-services/inherit-permission-directive.md
@@ -0,0 +1,32 @@
+---
+Added: v2.3.0
+Status: Active
+---
+# Inherit Permission directive
+
+Update the current node by adding/removing the inherited permissions.
+
+## Basic Usage
+
+```html
+
+```
+
+### Properties
+
+| Name | Type | Default value | Description |
+| ---- | ---- | ------------- | ----------- |
+| nodeId | `string` | | nodeId where to add/remove inherited permissions |
+
+### Events
+
+| Name | Type | Description |
+| ---- | ---- | ----------- |
+| updated | `EventEmitter` | Emitted when the node is updated. |
+
+## Details
+This directive switches on/off the inheritance on the permission based on what is set on the node entity.
+So if the node has inherited permissions, this will remove them viceversa if the node does not have the inherited permission this will add them.
\ No newline at end of file
diff --git a/lib/content-services/mock/inherited-permission.component.mock.ts b/lib/content-services/mock/inherited-permission.component.mock.ts
new file mode 100644
index 0000000000..cfe2b46eaf
--- /dev/null
+++ b/lib/content-services/mock/inherited-permission.component.mock.ts
@@ -0,0 +1,41 @@
+/*!
+ * @license
+ * Copyright 2016 Alfresco Software, Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { Component } from '@angular/core';
+
+@Component({
+ template: `
+
+ NODE UPDATED
+ `
+})
+
+export class SimpleInheritedPermissionTestComponent {
+
+ message: string = '';
+ nodeId: string = 'fake-node-id';
+ updatedNode: boolean = false;
+
+ constructor() {
+ }
+
+ onUpdate(node: any) {
+ this.updatedNode = node.permissions.isInheritanceEnabled;
+ }
+
+}
diff --git a/lib/content-services/permission-manager/components/inherited-button.directive.spec.ts b/lib/content-services/permission-manager/components/inherited-button.directive.spec.ts
new file mode 100644
index 0000000000..2722987ceb
--- /dev/null
+++ b/lib/content-services/permission-manager/components/inherited-button.directive.spec.ts
@@ -0,0 +1,102 @@
+/*!
+ * @license
+ * Copyright 2016 Alfresco Software, Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { SimpleInheritedPermissionTestComponent } from '../../mock/inherited-permission.component.mock';
+import { async, ComponentFixture, TestBed } from '@angular/core/testing';
+import { PermissionManagerModule } from '../../index';
+import { NodesApiService } from '@alfresco/adf-core';
+import { Observable } from 'rxjs/Observable';
+
+const fakeNodeWithInherit: any = { id: 'fake-id', permissions : {isInheritanceEnabled : true}};
+const fakeNodeNoInherit: any = { id: 'fake-id', permissions : {isInheritanceEnabled : false}};
+
+describe('InheritPermissionDirective', () => {
+
+ let fixture: ComponentFixture;
+ let element: HTMLElement;
+ let component: SimpleInheritedPermissionTestComponent;
+ let nodeService: NodesApiService;
+
+ beforeEach(async(() => {
+ TestBed.configureTestingModule({
+ imports: [
+ PermissionManagerModule
+ ],
+ declarations: [
+ SimpleInheritedPermissionTestComponent
+ ]
+ }).compileComponents().then(() => {
+ fixture = TestBed.createComponent(SimpleInheritedPermissionTestComponent);
+ component = fixture.componentInstance;
+ element = fixture.nativeElement;
+ nodeService = TestBed.get(NodesApiService);
+ });
+ }));
+
+ afterEach(async(() => {
+ fixture.destroy();
+ TestBed.resetTestingModule();
+ }));
+
+ it('should be able to render the simple component', async(() => {
+ fixture.detectChanges();
+ expect(element.querySelector('#sample-button-permission')).not.toBeNull();
+ expect(element.querySelector('#update-notification')).toBeNull();
+ }));
+
+ it('should be able to add inherited permission', async(() => {
+ spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeNoInherit));
+ spyOn(nodeService, 'updateNode').and.callFake((nodeId, nodeBody) => {
+ if (nodeBody.permissions.isInheritanceEnabled) {
+ return Observable.of(fakeNodeWithInherit);
+ } else {
+ return Observable.of(fakeNodeNoInherit);
+ }
+ });
+ fixture.detectChanges();
+ const buttonPermission: HTMLButtonElement = element.querySelector('#sample-button-permission');
+ expect(buttonPermission).not.toBeNull();
+ expect(element.querySelector('#update-notification')).toBeNull();
+ buttonPermission.click();
+ fixture.detectChanges();
+ fixture.whenStable().then(() => {
+ expect(element.querySelector('#update-notification')).not.toBeNull();
+ });
+ }));
+
+ it('should be able to remove inherited permission', async(() => {
+ spyOn(nodeService, 'getNode').and.returnValue(Observable.of(fakeNodeWithInherit));
+ spyOn(nodeService, 'updateNode').and.callFake((nodeId, nodeBody) => {
+ if (nodeBody.permissions.isInheritanceEnabled) {
+ return Observable.of(fakeNodeWithInherit);
+ } else {
+ return Observable.of(fakeNodeNoInherit);
+ }
+ });
+ component.updatedNode = true;
+ fixture.detectChanges();
+ const buttonPermission: HTMLButtonElement = element.querySelector('#sample-button-permission');
+ expect(buttonPermission).not.toBeNull();
+ expect(element.querySelector('#update-notification')).not.toBeNull();
+ buttonPermission.click();
+ fixture.detectChanges();
+ fixture.whenStable().then(() => {
+ expect(element.querySelector('#update-notification')).toBeNull();
+ });
+ }));
+
+});
diff --git a/lib/content-services/permission-manager/components/inherited-button.directive.ts b/lib/content-services/permission-manager/components/inherited-button.directive.ts
new file mode 100644
index 0000000000..e0f219dbb7
--- /dev/null
+++ b/lib/content-services/permission-manager/components/inherited-button.directive.ts
@@ -0,0 +1,50 @@
+/*!
+ * @license
+ * Copyright 2016 Alfresco Software, Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/* tslint:disable:no-input-rename */
+import { Directive, Input, Output, EventEmitter } from '@angular/core';
+import { NodesApiService } from '@alfresco/adf-core';
+import { MinimalNodeEntryEntity } from 'alfresco-js-api';
+
+@Directive({
+ selector: 'button[adf-inherit-permission], mat-button-toggle[adf-inherit-permission]',
+ host: {
+ 'role': 'button',
+ '(click)': 'onInheritPermissionClicked()'
+ }
+})
+export class InheritPermissionDirective {
+
+ @Input()
+ nodeId: string;
+
+ @Output()
+ updated: EventEmitter = new EventEmitter();
+
+ constructor(private nodeService: NodesApiService) {
+ }
+
+ onInheritPermissionClicked() {
+ this.nodeService.getNode(this.nodeId).subscribe((node: MinimalNodeEntryEntity) => {
+ const nodeBody = { permissions : {isInheritanceEnabled : !node.permissions.isInheritanceEnabled} };
+ this.nodeService.updateNode(this.nodeId, nodeBody).subscribe((nodeUpdated: MinimalNodeEntryEntity) => {
+ this.updated.emit(nodeUpdated);
+ });
+ });
+ }
+
+}
diff --git a/lib/content-services/permission-manager/components/permission-display/permission-list.component.html b/lib/content-services/permission-manager/components/permission-list/permission-list.component.html
similarity index 100%
rename from lib/content-services/permission-manager/components/permission-display/permission-list.component.html
rename to lib/content-services/permission-manager/components/permission-list/permission-list.component.html
diff --git a/lib/content-services/permission-manager/components/permission-display/permission-list.component.scss b/lib/content-services/permission-manager/components/permission-list/permission-list.component.scss
similarity index 100%
rename from lib/content-services/permission-manager/components/permission-display/permission-list.component.scss
rename to lib/content-services/permission-manager/components/permission-list/permission-list.component.scss
diff --git a/lib/content-services/permission-manager/components/permission-display/permission-list.component.spec.ts b/lib/content-services/permission-manager/components/permission-list/permission-list.component.spec.ts
similarity index 100%
rename from lib/content-services/permission-manager/components/permission-display/permission-list.component.spec.ts
rename to lib/content-services/permission-manager/components/permission-list/permission-list.component.spec.ts
diff --git a/lib/content-services/permission-manager/components/permission-display/permission-list.component.ts b/lib/content-services/permission-manager/components/permission-list/permission-list.component.ts
similarity index 94%
rename from lib/content-services/permission-manager/components/permission-display/permission-list.component.ts
rename to lib/content-services/permission-manager/components/permission-list/permission-list.component.ts
index df154ccd6f..f7e8327153 100644
--- a/lib/content-services/permission-manager/components/permission-display/permission-list.component.ts
+++ b/lib/content-services/permission-manager/components/permission-list/permission-list.component.ts
@@ -38,6 +38,14 @@ export class PermissionListComponent implements OnInit {
}
ngOnInit() {
+ this.fetchNodePermissions();
+ }
+
+ reload() {
+ this.fetchNodePermissions();
+ }
+
+ private fetchNodePermissions() {
this.nodeService.getNode(this.nodeId).subscribe((node: MinimalNodeEntryEntity) => {
this.permissionList = this.getPermissionList(node);
});
diff --git a/lib/content-services/permission-manager/permission-manager.module.ts b/lib/content-services/permission-manager/permission-manager.module.ts
index 1088f7a688..370edef4ce 100644
--- a/lib/content-services/permission-manager/permission-manager.module.ts
+++ b/lib/content-services/permission-manager/permission-manager.module.ts
@@ -20,8 +20,9 @@ import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { TranslateModule } from '@ngx-translate/core';
import { MaterialModule } from '../material.module';
-import { PermissionListComponent } from './components/permission-display/permission-list.component';
+import { PermissionListComponent } from './components/permission-list/permission-list.component';
import { DataTableModule, DataColumnModule } from '@alfresco/adf-core';
+import { InheritPermissionDirective } from './components/inherited-button.directive';
@NgModule({
imports: [
@@ -34,10 +35,12 @@ import { DataTableModule, DataColumnModule } from '@alfresco/adf-core';
DataColumnModule
],
declarations: [
- PermissionListComponent
+ PermissionListComponent,
+ InheritPermissionDirective
],
exports: [
- PermissionListComponent
+ PermissionListComponent,
+ InheritPermissionDirective
]
})
export class PermissionManagerModule {}
diff --git a/lib/content-services/permission-manager/public-api.ts b/lib/content-services/permission-manager/public-api.ts
index d795356379..7ad71379e1 100644
--- a/lib/content-services/permission-manager/public-api.ts
+++ b/lib/content-services/permission-manager/public-api.ts
@@ -15,6 +15,7 @@
* limitations under the License.
*/
- export * from './components/permission-display/permission-list.component';
+ export * from './components/permission-list/permission-list.component';
+ export * from './components/inherited-button.directive';
export * from './models/permission.model';
diff --git a/lib/content-services/styles/_index.scss b/lib/content-services/styles/_index.scss
index 256f56c9f6..bf8be12a5d 100644
--- a/lib/content-services/styles/_index.scss
+++ b/lib/content-services/styles/_index.scss
@@ -14,7 +14,7 @@
@import '../content-node-selector/content-node-selector.component';
@import '../content-metadata/content-metadata.module';
-@import '../permission-manager/components/permission-display/permission-list.component';
+@import '../permission-manager/components/permission-list/permission-list.component';
@mixin adf-content-services-theme($theme) {
@include adf-breadcrumb-theme($theme);