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 18, 2020
1 parent 69f162c commit fbd4e9d
Show file tree
Hide file tree
Showing 22 changed files with 431 additions and 91 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, RecordPermission } 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,29 +35,41 @@ export class HoldingItemComponent {
/** Event for delete Item */
@Output() deleteItem = new EventEmitter();

/** Availables action */
/** Item permissions */
permissions: RecordPermission;

/** Availables actions */
get isAvailableActions() {
return this.userService.getCurrentUser().currentLibrary
return this._userService.getCurrentUser().currentLibrary
= this.holding.metadata.library.pid;
}

/**
* Constructor
* @param recordUiService - RecordUiService
* @param _recordUiService - RecordUiService
* @param _userService - UserService
* @param recordPermissionMessage - RecordPermissionMessageService
*/
constructor(
private recordUiService: RecordUiService,
private recordPermissionMessage: RecordPermissionMessageService,
private userService: UserService
private _recordUiService: RecordUiService,
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
*/
delete(itemPid: string) {
this.recordUiService.deleteRecord('items', itemPid).subscribe((success: any) => {
this._recordUiService.deleteRecord('items', itemPid).subscribe((success: any) => {
if (success) {
this.deleteItem.emit(itemPid);
}
Expand All @@ -69,8 +80,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);
this.recordUiService.showDeleteMessage(message);
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
7 changes: 5 additions & 2 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 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
Loading

0 comments on commit fbd4e9d

Please sign in to comment.