Skip to content

Commit

Permalink
general: implement new service record permission
Browse files Browse the repository at this point in the history
* Adds new service record permission.
* Fixes organisation active budget switch only with role system_librarian.

Co-Authored-by: Bertrand Zuchuat <bertrand.zuchuat@rero.ch>
  • Loading branch information
Garfield-fr committed Feb 17, 2020
1 parent 455c594 commit b5e1c5c
Show file tree
Hide file tree
Showing 22 changed files with 429 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
 You should have received a copy of the GNU Affero General Public License
 along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<ng-container *ngIf="item && permissions">
<div class="col-sm-4">
<a [routerLink]="['/records', 'items', 'detail', item.metadata.pid]">
{{ item.metadata.barcode }}
Expand All @@ -28,17 +28,17 @@
</div>
<div class="col-sm-4 text-right">
<ng-container *ngIf="isAvailableActions; else noactions">
<button *ngIf="!item.permissions.cannot_update" type="button" class="btn btn-primary btn-sm"
<button *ngIf="permissions.update.can" type="button" class="btn btn-primary btn-sm"
[routerLink]="['/records', 'items', 'edit', item.metadata.pid]">
<i class="fa fa-pencil"></i> {{ 'Edit' | translate }}
</button>

<button *ngIf="!item.permissions.cannot_delete; else notDelete" type="button" class="btn btn-primary btn-sm ml-1"
<button *ngIf="permissions.delete.can; else notDelete" type="button" class="btn btn-primary btn-sm ml-1"
(click)="delete(item.metadata.pid)">
<i class="fa fa-trash"></i> {{ 'Delete' | translate }}
</button>
<ng-template #notDelete>
<button type="button" class="btn btn-dark btn-sm ml-1" (click)="showDeleteMessage(item)">
<button type="button" class="btn btn-dark btn-sm ml-1" (click)="showDeleteMessage()">
<i class="fa fa-trash"></i> {{ 'Delete' | translate }}
</button>
</ng-template>
Expand All @@ -47,3 +47,4 @@
&nbsp;
</ng-template>
</div>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import { Component, EventEmitter, Input, Output } from '@angular/core';
import { Component, EventEmitter, Input, Output, OnInit } from '@angular/core';
import { RecordUiService } from '@rero/ng-core';
import { RecordPermissionMessageService } from 'projects/admin/src/app/service/record-permission-message.service';
import { UserService } from 'projects/admin/src/app/service/user.service';
import { UserService } from '../../../../service/user.service';
import { RecordPermissionService, RecordPermissionInterface } from '../../../../service/record-permission.service';

@Component({
selector: 'admin-holding-item',
templateUrl: './holding-item.component.html',
styles: []
templateUrl: './holding-item.component.html'
})
export class HoldingItemComponent {
export class HoldingItemComponent implements OnInit {

/** Holding record */
@Input() holding: any;
Expand All @@ -36,6 +35,9 @@ export class HoldingItemComponent {
/** Event for delete Item */
@Output() deleteItem = new EventEmitter();

/** Item permissions */
permissions: RecordPermissionInterface;

/** Availables action */
get isAvailableActions() {
return this.userService.getCurrentUser().currentLibrary
Expand All @@ -49,10 +51,18 @@ export class HoldingItemComponent {
*/
constructor(
private recordUiService: RecordUiService,
private recordPermissionMessage: RecordPermissionMessageService,
private userService: UserService
private userService: UserService,
private _recordPermissionService: RecordPermissionService
) { }

/**
* Init
*/
ngOnInit() {
this._recordPermissionService.getPermission('items', this.item.metadata.pid)
.subscribe(permissions => this.permissions = permissions);
}

/**
* Delete item
* @param itemPid - Item pid
Expand All @@ -69,8 +79,10 @@ export class HoldingItemComponent {
* Display message if the record cannot be deleted
* @param item - Item record
*/
public showDeleteMessage(item: object) {
const message = this.recordPermissionMessage.generateMessage(item);
public showDeleteMessage() {
const message = this._recordPermissionService.generateDeleteMessage(
this.permissions.delete.reasons
);
this.recordUiService.showDeleteMessage(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ <h1>{{ record.metadata.name }}</h1>
<!-- ACTIVE BUDGET -->
<dt class="col-sm-3 offset-sm-2 offset-md-0 label-title">Active budget</dt>
<dd class="col-sm-7 col-md-8 mb-0">
<admin-budget-select [organisation]="record"></admin-budget-select>
<admin-budget-select *ngIf="isSystemLibrarian; else librarian" [organisation]="record"></admin-budget-select>
<ng-template #librarian>
{{ record.metadata.current_budget_pid | getRecord: 'budgets' : 'field' : 'name' | async }}
</ng-template>
</dd>
</dl>
</ng-container>
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import { Component } from '@angular/core';
import { DetailRecord } from '@rero/ng-core/lib/record/detail/view/detail-record';
import { Observable } from 'rxjs';
import { UserService } from '../../../service/user.service';

@Component({
selector: 'admin-organisation-detail-view',
Expand All @@ -33,4 +34,11 @@ export class OrganisationDetailViewComponent implements DetailRecord {
* Type
*/
type: string;

get isSystemLibrarian() {
return this._userService.hasRole('system_librarian');

}

constructor(private _userService: UserService) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export class AcquisitionOrderLinesRoute extends BaseRoute implements RouteInterf
/** Route name */
readonly name = 'acq_order_lines';

/** Record type */
readonly recordType = 'acq_order_lines';

/**
* Get Configuration
* @return Object
Expand All @@ -48,9 +51,9 @@ export class AcquisitionOrderLinesRoute extends BaseRoute implements RouteInterf
key: this.name,
label: 'Order lines',
detailComponent: AcquisitionOrderLineDetailViewComponent,
canAdd: () => this._routeToolService.canAddSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canDelete: (record: any) => this._routeToolService.canDelete(record),
canAdd: () => this._routeToolService.canSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: (record: any) => this._routeToolService.canDelete(record, this.recordType),
preCreateRecord: (data: any) => {
data.acq_order = {
$ref: this._routeToolService.apiService.getRefEndpoint(
Expand Down
7 changes: 5 additions & 2 deletions projects/admin/src/app/routes/acquisition-orders-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export class AcquisitionOrdersRoute extends BaseRoute implements RouteInterface
/** Route name */
readonly name = 'acq_orders';

/** Record type */
readonly recordType = 'acq_orders';

/**
* Get Configuration
* @return Object
Expand All @@ -48,8 +51,8 @@ export class AcquisitionOrdersRoute extends BaseRoute implements RouteInterface
label: 'Orders',
component: AcquisitionOrderBriefViewComponent,
detailComponent: AcquisitionOrderDetailViewComponent,
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canDelete: (record: any) => this._routeToolService.canDelete(record),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: (record: any) => this._routeToolService.canDelete(record, this.recordType),
preCreateRecord: (data: any) => {
const user = this._routeToolService.userService.getCurrentUser();
data.order_date = formatDate(
Expand Down
7 changes: 5 additions & 2 deletions projects/admin/src/app/routes/budgets-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class BudgetsRoute extends BaseRoute implements RouteInterface {
/** Route name */
readonly name = 'budgets';

/** Record type */
readonly recordType = 'budgets';

/**
* Get Configuration
* @return Object
Expand All @@ -45,8 +48,8 @@ export class BudgetsRoute extends BaseRoute implements RouteInterface {
label: 'Budgets',
component: BudgetsBriefViewComponent,
detailComponent: BudgetDetailViewComponent,
canAdd: () => this._routeToolService.canAddSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canAdd: () => this._routeToolService.canSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: () => this._routeToolService.canNot(),
preCreateRecord: (data: any) => {
const user = this._routeToolService.userService.getCurrentUser();
Expand Down
9 changes: 6 additions & 3 deletions projects/admin/src/app/routes/circulation-policies-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export class CirculationPoliciesRoute extends BaseRoute implements RouteInterfac
/** Route name */
readonly name = 'circ_policies';

/** Record type */
readonly recordType = 'circ_policies';

/**
* Get Configuration
* @return Object
Expand All @@ -46,9 +49,9 @@ export class CirculationPoliciesRoute extends BaseRoute implements RouteInterfac
label: 'Circulation policies',
component: CircPoliciesBriefViewComponent,
detailComponent: CircPolicyDetailViewComponent,
canAdd: () => this._routeToolService.canAddSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canDelete: (record: any) => this._routeToolService.canDelete(record)
canAdd: () => this._routeToolService.canSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: (record: any) => this._routeToolService.canDelete(record, this.recordType)
}
]
}
Expand Down
9 changes: 6 additions & 3 deletions projects/admin/src/app/routes/documents-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export class DocumentsRoute extends BaseRoute implements RouteInterface {
/** Route name */
readonly name = 'documents';

/** Record type */
readonly recordType = 'documents';

/**
* Get Configuration
* @return Object
Expand All @@ -48,8 +51,8 @@ export class DocumentsRoute extends BaseRoute implements RouteInterface {
editorLongMode: true,
component: DocumentsBriefViewComponent,
detailComponent: DocumentDetailViewComponent,
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canDelete: (record: any) => this._routeToolService.canDelete(record),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: (record: any) => this._routeToolService.canDelete(record, this.recordType),
preprocessRecordEditor: (record: any) => {
return this.removeKey(record, '_text');
},
Expand All @@ -70,7 +73,7 @@ export class DocumentsRoute extends BaseRoute implements RouteInterface {
aggregationsExpand: ['document_type'],
aggregationsBucketSize: 10,
itemHeaders: {
Accept: 'application/rero+json, application/json'
Accept: 'application/rero+json'
}
}
]
Expand Down
9 changes: 6 additions & 3 deletions projects/admin/src/app/routes/item-types-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class ItemTypesRoute extends BaseRoute implements RouteInterface {
/** Route name */
readonly name = 'item_types';

/** Record type */
readonly recordType = 'item_types';

/**
* Get Configuration
* @return Object
Expand All @@ -45,9 +48,9 @@ export class ItemTypesRoute extends BaseRoute implements RouteInterface {
label: 'Item types',
component: ItemTypesBriefViewComponent,
detailComponent: ItemTypeDetailViewComponent,
canAdd: () => this._routeToolService.canAddSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canDelete: (record: any) => this._routeToolService.canDelete(record),
canAdd: () => this._routeToolService.canSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: (record: any) => this._routeToolService.canDelete(record, this.recordType),
preCreateRecord: (data: any) => {
const user = this._routeToolService.userService.getCurrentUser();
data.organisation = {
Expand Down
7 changes: 5 additions & 2 deletions projects/admin/src/app/routes/items-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export class ItemsRoute extends BaseRoute implements RouteInterface {
/** Route name */
readonly name = 'items';

/** Record type */
readonly recordType = 'items';

/**
* Get Configuration
* @return Object
Expand All @@ -48,8 +51,8 @@ export class ItemsRoute extends BaseRoute implements RouteInterface {
label: 'Items',
detailComponent: ItemDetailViewComponent,
canRead: (record: any) => this.canReadItem(record),
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canDelete: (record: any) => this._routeToolService.canDelete(record),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: (record: any) => this._routeToolService.canDelete(record, this.recordType),
preCreateRecord: (data: any) => {
data.document = {
$ref: this._routeToolService.apiService.getRefEndpoint(
Expand Down
9 changes: 6 additions & 3 deletions projects/admin/src/app/routes/libraries-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ export class LibrariesRoute extends BaseRoute implements RouteInterface {
/** Route name */
readonly name = 'libraries';

/** Record type */
readonly recordType = 'libraries';

/**
* Get Configuration
* @return Object
Expand All @@ -46,9 +49,9 @@ export class LibrariesRoute extends BaseRoute implements RouteInterface {
label: 'Libraries',
component: LibrariesBriefViewComponent,
detailComponent: LibraryDetailViewComponent,
canAdd: () => this._routeToolService.canAddSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canDelete: (record: any) => this._routeToolService.canDelete(record),
canAdd: () => this._routeToolService.canSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: (record: any) => this._routeToolService.canDelete(record, this.recordType),
preCreateRecord: (data: any) => {
const user = this._routeToolService.userService.getCurrentUser();
data.organisation = {
Expand Down
9 changes: 6 additions & 3 deletions projects/admin/src/app/routes/locations-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ export class LocationsRoute extends BaseRoute implements RouteInterface {
/** Route name */
readonly name = 'locations';

/** Record type */
readonly recordType = 'libraries';

/**
* Get Configuration
* @return Object
Expand All @@ -42,9 +45,9 @@ export class LocationsRoute extends BaseRoute implements RouteInterface {
key: this.name,
label: 'Locations',
detailComponent: LocationDetailViewComponent,
canAdd: () => this._routeToolService.canAddSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canDelete: (record: any) => this._routeToolService.canDelete(record),
canAdd: () => this._routeToolService.canSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: (record: any) => this._routeToolService.canDelete(record, this.recordType),
preCreateRecord: (record: any) => {
record.library = {
$ref: this._routeToolService.apiService.getRefEndpoint(
Expand Down
9 changes: 6 additions & 3 deletions projects/admin/src/app/routes/patron-types-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class PatronTypesRoute extends BaseRoute implements RouteInterface {
/** Route name */
readonly name = 'patron_types';

/** Record type */
readonly recordType = 'patron_types';

/**
* Get Configuration
* @return Object
Expand All @@ -45,9 +48,9 @@ export class PatronTypesRoute extends BaseRoute implements RouteInterface {
label: 'Patron types',
component: PatronTypesBriefViewComponent,
detailComponent: PatronTypesDetailViewComponent,
canAdd: () => this._routeToolService.canAddSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canDelete: (record: any) => this._routeToolService.canDelete(record),
canAdd: () => this._routeToolService.canSystemLibrarian(),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: (record: any) => this._routeToolService.canDelete(record, this.recordType),
preCreateRecord: (data: any) => {
const user = this._routeToolService.userService.getCurrentUser();
data.organisation = {
Expand Down
7 changes: 5 additions & 2 deletions projects/admin/src/app/routes/patrons-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ export class PatronsRoute extends BaseRoute implements RouteInterface {
/** Route name */
readonly name = 'patrons';

/** Record type */
readonly recordType = 'patrons';

/**
* Get Configuration
* @return Object
Expand All @@ -45,8 +48,8 @@ export class PatronsRoute extends BaseRoute implements RouteInterface {
label: 'Patrons',
component: PatronsBriefViewComponent,
detailComponent: PatronDetailViewComponent,
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canDelete: (record: any) => this._routeToolService.canDelete(record),
canUpdate: (record: any) => this._routeToolService.canUpdate(record, this.recordType),
canDelete: (record: any) => this._routeToolService.canDelete(record, this.recordType),
aggregationsExpand: ['roles']
}
]
Expand Down
2 changes: 0 additions & 2 deletions projects/admin/src/app/routes/persons-route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ export class PersonsRoute extends BaseRoute implements RouteInterface {
label: 'Persons',
component: PersonsBriefViewComponent,
detailComponent: PersonDetailViewComponent,
canUpdate: (record: any) => this._routeToolService.canUpdate(record),
canDelete: (record: any) => this._routeToolService.canDelete(record),
aggregationsExpand: ['sources']
}
]
Expand Down
Loading

0 comments on commit b5e1c5c

Please sign in to comment.