Newer
Older
import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { HeaderService } from './header.service';

Alex ORLUC
committed
'id': string; // identifier
'label': string; // title
'comment': string; // description
'route': string; // navigate to interface
'style': string; // icon used interface
'unit': string; // category of administration
'angular': boolean; // to navigate in V1 <=>V2
'shortcut': boolean; // show in panel
}
interface administration {

Alex ORLUC
committed
'id': string; // identifier
'label': string; // title
'comment': string; // description
'route': string; // navigate to interface
'style': string; // icone used interface
'unit': 'organisation' | 'classement' | 'production' | 'supervision'; // category of administration
'angular': boolean; // to navigate in V1 <=>V2
'hasParams': boolean;

Alex ORLUC
committed
'id': string; // identifier
'label': string; // title
'unit': string; // category of administration
'comment': string; // description
@Injectable()
export class PrivilegeService {
private administrations: administration[] = [
{

Alex ORLUC
committed
'id': 'admin_users',
'label': this.translate.instant('lang.users'),
'comment': this.translate.instant('lang.adminUsersDesc'),

Alex ORLUC
committed
'route': '/administration/users',
'unit': 'organisation',
'style': 'fa fa-user',
'angular': true,
'hasParams': true
},
{
'id': 'admin_groups',
'label': this.translate.instant('lang.groups'),
'comment': this.translate.instant('lang.adminGroupsDesc'),

Alex ORLUC
committed
'route': '/administration/groups',
'unit': 'organisation',
'style': 'fa fa-users',
'angular': true,
'hasParams': false
},
{
'id': 'manage_entities',
'label': this.translate.instant('lang.entities'),
'comment': this.translate.instant('lang.adminEntitiesDesc'),

Alex ORLUC
committed
'route': '/administration/entities',
'unit': 'organisation',
'style': 'fa fa-sitemap',
'angular': true,
'hasParams': false
},
{
'id': 'admin_listmodels',
'label': this.translate.instant('lang.workflowModels'),
'comment': this.translate.instant('lang.adminWorkflowModelsDesc'),

Alex ORLUC
committed
'route': '/administration/diffusionModels',
'unit': 'organisation',
'style': 'fa fa-th-list',
'angular': true,
'hasParams': false
},
{
'id': 'admin_architecture',
'label': this.translate.instant('lang.documentTypes'),
'comment': this.translate.instant('lang.adminDocumentTypesDesc'),

Alex ORLUC
committed
'route': '/administration/doctypes',
'unit': 'classement',
'style': 'fa fa-suitcase',
'angular': true,
'hasParams': false
},
{
'id': 'admin_tag',
'label': this.translate.instant('lang.tags'),
'comment': this.translate.instant('lang.adminTagsDesc'),

Alex ORLUC
committed
'route': '/administration/tags',
'unit': 'classement',
'style': 'fa fa-tags',
'angular': true,
'hasParams': false
},
{
'id': 'admin_baskets',
'label': this.translate.instant('lang.baskets'),
'comment': this.translate.instant('lang.adminBasketsDesc'),

Alex ORLUC
committed
'route': '/administration/baskets',
'unit': 'production',
'style': 'fa fa-inbox',
'angular': true,
'hasParams': false
},
{
'id': 'admin_status',
'label': this.translate.instant('lang.statuses'),
'comment': this.translate.instant('lang.statusesAdmin'),

Alex ORLUC
committed
'route': '/administration/statuses',
'unit': 'production',
'style': 'fa fa-check-circle',
'angular': true,
'hasParams': false
},
{
'id': 'admin_actions',
'label': this.translate.instant('lang.actions'),
'comment': this.translate.instant('lang.actionsAdmin'),

Alex ORLUC
committed
'route': '/administration/actions',
'unit': 'production',
'style': 'fa fa-exchange-alt',
'angular': true,
'hasParams': false
},
{
'id': 'admin_contacts',
'label': this.translate.instant('lang.contacts'),
'comment': this.translate.instant('lang.contactsAdmin'),

Alex ORLUC
committed
'route': '/administration/contacts',
'unit': 'production',
'style': 'fa fa-address-book',
'angular': true,
'hasParams': false
},
{
'id': 'admin_priorities',
'label': this.translate.instant('lang.prioritiesAlt'),
'comment': this.translate.instant('lang.prioritiesAlt'),

Alex ORLUC
committed
'route': '/administration/priorities',
'unit': 'production',
'style': 'fa fa-clock',
'angular': true,
'hasParams': false
},
{
'id': 'admin_templates',
'label': this.translate.instant('lang.templates'),
'comment': this.translate.instant('lang.templatesAdmin'),

Alex ORLUC
committed
'route': '/administration/templates',
'unit': 'production',
'style': 'fa fa-file-alt',
'angular': true,
'hasParams': false
},
{
'id': 'admin_indexing_models',
'label': this.translate.instant('lang.indexingModels'),
'comment': this.translate.instant('lang.indexingModels'),

Alex ORLUC
committed
'route': '/administration/indexingModels',
'unit': 'production',
'style': 'fab fa-wpforms',
'angular': true,
'hasParams': false
},
{
'id': 'admin_custom_fields',
'label': this.translate.instant('lang.customFieldsAdmin'),
'comment': this.translate.instant('lang.customFieldsAdmin'),

Alex ORLUC
committed
'route': '/administration/customFields',
'unit': 'production',
'style': 'fa fa-code',
'angular': true,
'hasParams': false
},
{
'id': 'admin_notif',
'label': this.translate.instant('lang.notifications'),
'comment': this.translate.instant('lang.notificationsAdmin'),

Alex ORLUC
committed
'route': '/administration/notifications',
'unit': 'production',
'style': 'fa fa-bell',
'angular': true,
'hasParams': false
},
{
'id': 'update_status_mail',
'label': this.translate.instant('lang.updateStatus'),
'comment': this.translate.instant('lang.updateStatus'),

Alex ORLUC
committed
'route': '/administration/update-status',
'unit': 'supervision',
'style': 'fa fa-envelope-square',
'angular': true,
'hasParams': false
},
{
'id': 'admin_docservers',
'label': this.translate.instant('lang.docservers'),
'comment': this.translate.instant('lang.docserversAdmin'),

Alex ORLUC
committed
'route': '/administration/docservers',
'unit': 'supervision',
'style': 'fa fa-hdd',
'angular': true,
'hasParams': false
},
{
'id': 'admin_parameters',
'label': this.translate.instant('lang.parameters'),
'comment': this.translate.instant('lang.parameters'),

Alex ORLUC
committed
'route': '/administration/parameters',
'unit': 'supervision',
'style': 'fa fa-wrench',
'angular': true,
'hasParams': false
},
{
'id': 'admin_password_rules',
'label': this.translate.instant('lang.securities'),
'comment': this.translate.instant('lang.securities'),

Alex ORLUC
committed
'route': '/administration/securities',
'unit': 'supervision',
'style': 'fa fa-lock',
'angular': true,
'hasParams': false
},
{
'id': 'admin_email_server',
'label': this.translate.instant('lang.emailServerParam'),
'comment': this.translate.instant('lang.emailServerParamDesc'),

Alex ORLUC
committed
'route': '/administration/sendmail',
'unit': 'supervision',
'style': 'fa fa-mail-bulk',
'angular': true,
'hasParams': false
},
{
'id': 'admin_shippings',
'label': this.translate.instant('lang.mailevaAdmin'),
'comment': this.translate.instant('lang.mailevaAdminDesc'),

Alex ORLUC
committed
'route': '/administration/shippings',
'unit': 'supervision',
'style': 'fa fa-shipping-fast',
'angular': true,
'hasParams': false
},
{
'id': 'view_history',
'label': this.translate.instant('lang.history'),
'comment': this.translate.instant('lang.viewHistoryDesc'),

Alex ORLUC
committed
'route': '/administration/history',
'unit': 'supervision',
'style': 'fa fa-history',
'angular': true,
'hasParams': false
},
{
'id': 'view_history_batch',
'label': this.translate.instant('lang.historyBatch'),
'comment': this.translate.instant('lang.historyBatchAdmin'),

Alex ORLUC
committed
'route': '/administration/history-batch',
'unit': 'supervision',
'style': 'fa fa-history',
'angular': true,
'hasParams': false
},
{
'id': 'admin_update_control',
'label': this.translate.instant('lang.updateControl'),
'comment': this.translate.instant('lang.updateControlDesc'),

Alex ORLUC
committed
'route': '/administration/versions-update',
'unit': 'supervision',
'style': 'fa fa-sync',
'angular': true,
'hasParams': false
},
{
'id': 'admin_alfresco',
'label': this.translate.instant('lang.alfresco'),
'comment': this.translate.instant('lang.adminAlfrescoDesc'),

Alex ORLUC
committed
'route': '/administration/alfresco',
'unit': 'supervision',
'style': 'alfresco',
'angular': true,
'hasParams': false
},
{
'id': 'admin_registered_mail',
'label': this.translate.instant('lang.registeredMail'),
'comment': this.translate.instant('lang.adminRegisteredMailDesc'),
'route': '/administration/registeredMails',
'unit': 'supervision',
'style': 'fas fa-dolly-flatbed',
'angular': true,
'hasParams': false
}
];
private privileges: privilege[] = [
{

Alex ORLUC
committed
'id': 'view_doc_history',
'label': this.translate.instant('lang.viewDocHistory'),
'comment': this.translate.instant('lang.viewHistoryDesc'),

Alex ORLUC
committed
'unit': 'history'

Alex ORLUC
committed
'id': 'view_full_history',
'label': this.translate.instant('lang.viewFullHistory'),
'comment': this.translate.instant('lang.viewFullHistoryDesc'),

Alex ORLUC
committed
'unit': 'history'

Alex ORLUC
committed
'id': 'edit_resource',
'label': this.translate.instant('lang.editResource'),
'comment': this.translate.instant('lang.editResourceDesc'),

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'add_links',
'label': this.translate.instant('lang.addLinks'),
'comment': this.translate.instant('lang.addLinks'),

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'manage_tags_application',
'label': this.translate.instant('lang.manageTagsInApplication'),
'comment': this.translate.instant('lang.manageTagsInApplicationDesc'),

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'create_contacts',
'label': this.translate.instant('lang.manageCreateContacts'),
'comment': this.translate.instant('lang.manageCreateContactsDesc'),

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'update_contacts',
'label': this.translate.instant('lang.manageUpdateContacts'),
'comment': this.translate.instant('lang.manageUpdateContactsDesc'),

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'update_diffusion_indexing',
'label': this.translate.instant('lang.allRoles'),
'comment': this.translate.instant('lang.updateDiffusionWhileIndexing'),

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'update_diffusion_except_recipient_indexing',
'label': this.translate.instant('lang.rolesExceptAssignee'),
'comment': this.translate.instant('lang.updateDiffusionExceptRecipientWhileIndexing'),

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'update_diffusion_process',
'label': this.translate.instant('lang.allRoles'),
'comment': this.translate.instant('lang.updateDiffusionWhileProcess'),

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'update_diffusion_except_recipient_process',
'label': this.translate.instant('lang.rolesExceptAssignee'),
'comment': this.translate.instant('lang.updateDiffusionExceptRecipientWhileProcess'),

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'update_diffusion_details',
'label': this.translate.instant('lang.allRoles'),
'comment': this.translate.instant('lang.updateDiffusionWhileDetails'),

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'update_diffusion_except_recipient_details',
'label': this.translate.instant('lang.rolesExceptAssignee'),
'comment': this.translate.instant('lang.updateDiffusionExceptRecipientWhileDetails'),

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'sendmail',
'label': this.translate.instant('lang.sendmail'),
'comment': this.translate.instant('lang.sendmail'),

Alex ORLUC
committed
'unit': 'sendmail'

Alex ORLUC
committed
'id': 'use_mail_services',
'label': this.translate.instant('lang.useMailServices'),
'comment': this.translate.instant('lang.useMailServices'),

Alex ORLUC
committed
'unit': 'sendmail'

Alex ORLUC
committed
'id': 'view_documents_with_notes',
'label': this.translate.instant('lang.viewDocumentsWithNotes'),
'comment': this.translate.instant('lang.viewDocumentsWithNotesDesc'),

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'view_technical_infos',
'label': this.translate.instant('lang.viewTechnicalInformation'),
'comment': this.translate.instant('lang.viewTechnicalInformation'),

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'config_avis_workflow',
'label': this.translate.instant('lang.configAvisWorkflow'),
'comment': this.translate.instant('lang.configAvisWorkflowDesc'),

Alex ORLUC
committed
'unit': 'avis'

Alex ORLUC
committed
'id': 'config_avis_workflow_in_detail',
'label': this.translate.instant('lang.configAvisWorkflowInDetail'),
'comment': this.translate.instant('lang.configAvisWorkflowInDetailDesc'),

Alex ORLUC
committed
'unit': 'avis'

Alex ORLUC
committed
'id': 'avis_documents',
'label': this.translate.instant('lang.avisAnswer'),
'comment': this.translate.instant('lang.avisAnswerDesc'),

Alex ORLUC
committed
'unit': 'avis'

Alex ORLUC
committed
'id': 'config_visa_workflow',
'label': this.translate.instant('lang.configVisaWorkflow'),
'comment': this.translate.instant('lang.configVisaWorkflowDesc'),

Alex ORLUC
committed
'unit': 'visaWorkflow'

Alex ORLUC
committed
'id': 'config_visa_workflow_in_detail',
'label': this.translate.instant('lang.configVisaWorkflowInDetail'),
'comment': this.translate.instant('lang.configVisaWorkflowInDetailDesc'),

Alex ORLUC
committed
'unit': 'visaWorkflow'

Alex ORLUC
committed
'id': 'visa_documents',
'label': this.translate.instant('lang.visaAnswers'),
'comment': this.translate.instant('lang.visaAnswersDesc'),

Alex ORLUC
committed
'unit': 'visaWorkflow'

Alex ORLUC
committed
'id': 'sign_document',
'label': this.translate.instant('lang.signDocs'),
'comment': this.translate.instant('lang.signDocs'),

Alex ORLUC
committed
'unit': 'visaWorkflow'

Alex ORLUC
committed
'id': 'modify_visa_in_signatureBook',
'label': this.translate.instant('lang.modifyVisaInSignatureBook'),
'comment': this.translate.instant('lang.modifyVisaInSignatureBookDesc'),

Alex ORLUC
committed
'unit': 'visaWorkflow'

Alex ORLUC
committed
'id': 'print_folder_doc',
'label': this.translate.instant('lang.printFolderDoc'),
'comment': this.translate.instant('lang.printFolderDoc'),

Alex ORLUC
committed
'unit': 'application'
},
{

Alex ORLUC
committed
'id': 'manage_attachments',
'label': this.translate.instant('lang.manageAttachments'),
'comment': this.translate.instant('lang.manageAttachments'),

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'view_personal_data',
'label': this.translate.instant('lang.viewPersonalData'),
'comment': this.translate.instant('lang.viewPersonalData'),

Alex ORLUC
committed
'unit': 'confidentialityAndSecurity'

Alex ORLUC
committed
'id': 'manage_personal_data',
'label': this.translate.instant('lang.managePersonalData'),
'comment': this.translate.instant('lang.managePersonalData'),

Alex ORLUC
committed
'unit': 'confidentialityAndSecurity'
},
'id': 'include_folders_and_followed_resources_perimeter',
'label': this.translate.instant('lang.includeFolderPerimeter'),
'comment': this.translate.instant('lang.includeFolderPerimeter'),
'unit': 'application'
},

Alex ORLUC
committed
'id': 'admin',
'label': this.translate.instant('lang.administration'),
'comment': this.translate.instant('lang.administration'),

Alex ORLUC
committed
'route': '/administration',
'style': 'fa fa-cogs',
'unit': 'application',
'angular': true,
'shortcut': true
},
{
'id': 'adv_search_mlb',
'label': this.translate.instant('lang.search'),
'comment': this.translate.instant('lang.search'),

Alex ORLUC
committed
'route': 'index.php?page=search_adv&dir=indexing_searching',
'style': 'fa fa-search',
'unit': 'application',
'angular': false,
'shortcut': true
},
{
'id': 'entities_print_sep_mlb',
'label': this.translate.instant('lang.entitiesSeparator'),
'comment': this.translate.instant('lang.entitiesSeparator'),

Alex ORLUC
committed
'route': '/separators/print',
'style': 'fa fa-print',
'unit': 'entities',
'angular': true,
'shortcut': false
},
{
'id': 'manage_numeric_package',
'label': this.translate.instant('lang.manageNumericPackage'),
'comment': this.translate.instant('lang.manageNumericPackage'),

Alex ORLUC
committed
'route': '/saveNumericPackage',
'style': 'fa fa-file-archive',
'unit': 'sendmail',
'angular': true,
'shortcut': false
shortcuts: any[] = [
{

Alex ORLUC
committed
'id': 'followed',
'label': this.translate.instant('lang.followedMail'),
'comment': this.translate.instant('lang.followedMail'),

Alex ORLUC
committed
'route': '/followed',
'style': 'fas fa-star',
'unit': 'application',
'angular': true,
'shortcut': true
}
];
constructor(public translate: TranslateService, public headerService: HeaderService) { }
getAllPrivileges() {
let priv: any[] = [];

Alex ORLUC
committed
priv = priv.concat(this.privileges.map(elem => elem.id));
priv = priv.concat(this.administrations.map(elem => elem.id));
priv = priv.concat(this.menus.map(elem => elem.id));
return priv;
}

Alex ORLUC
committed
getPrivileges(ids: string[] = null) {
if (ids !== null) {
return this.privileges.filter(elem => ids.indexOf(elem.id) > -1);
} else {
return this.privileges;
}

Alex ORLUC
committed
getUnitsPrivileges(): Array<string> {
return this.privileges.map(elem => elem.unit).filter((elem, pos, arr) => arr.indexOf(elem) === pos);
}

Alex ORLUC
committed
getPrivilegesByUnit(unit: string): Array<privilege> {
return this.privileges.filter(elem => elem.unit === unit);
}
getMenus(): Array<menu> {
return this.menus;
}
getCurrentUserMenus() {
let menus = this.menus.filter(elem => this.headerService.user.privileges.indexOf(elem.id) > -1);
if (this.headerService.user.groups.filter((group: any) => group.can_index === true).length > 0) {
const indexingGroups: any[] = [];
this.headerService.user.groups.filter((group: any) => group.can_index === true).forEach((group: any) => {
indexingGroups.push({
id: group.id,
label: group.group_desc
});
});
const indexingmenu: any = {

Alex ORLUC
committed
'id': 'indexing',
'label': this.translate.instant('lang.recordMail'),
'comment': this.translate.instant('lang.recordMail'),

Alex ORLUC
committed
'route': '/indexing/' + indexingGroups[0].id,
'style': 'fa fa-file-medical',
'unit': 'application',
'angular': true,
'shortcut': true,
'groups': indexingGroups
};
menus.push(indexingmenu);
}

Alex ORLUC
committed
return menus;
}
getMenusByUnit(unit: string): Array<menu> {
return this.menus.filter(elem => elem.unit === unit);
}
getUnitsMenus(): Array<string> {
return this.menus.map(elem => elem.unit).filter((elem, pos, arr) => arr.indexOf(elem) === pos);
}
resfreshUserShortcuts() {
this.shortcuts = [

Alex ORLUC
committed
'id': 'followed',
'label': this.translate.instant('lang.followedMail'),
'comment': this.translate.instant('lang.followedMail'),

Alex ORLUC
committed
'route': '/followed',
'style': 'fas fa-star',
'unit': 'application',
'angular': true,
'shortcut': true

Alex ORLUC
committed
this.shortcuts = this.shortcuts.concat(this.menus.filter(elem => elem.shortcut === true).filter(elem => this.headerService.user.privileges.indexOf(elem.id) > -1));
if (this.headerService.user.groups.filter((group: any) => group.can_index === true).length > 0) {
const indexingGroups: any[] = [];
this.headerService.user.groups.filter((group: any) => group.can_index === true).forEach((group: any) => {
indexingGroups.push({
id: group.id,
label: group.group_desc
});
});
const indexingShortcut: any = {

Alex ORLUC
committed
'id': 'indexing',
'label': this.translate.instant('lang.recordMail'),
'comment': this.translate.instant('lang.recordMail'),

Alex ORLUC
committed
'route': '/indexing',
'style': 'fa fa-file-medical',
'unit': 'application',
'angular': true,
'shortcut': true,
'groups': indexingGroups
this.shortcuts.push(indexingShortcut);
}
}
getAdministrations(): Array<administration> {
return this.administrations;
}
getCurrentUserAdministrationsByUnit(unit: string): Array<administration> {
if (this.hasCurrentUserPrivilege('view_history') && this.hasCurrentUserPrivilege('view_history_batch')) {
return this.administrations.filter(elem => elem.unit === unit).filter(elem => this.headerService.user.privileges.indexOf(elem.id) > -1).filter(priv => priv.id !== 'view_history_batch');
} else {
return this.administrations.filter(elem => elem.unit === unit).filter(elem => this.headerService.user.privileges.indexOf(elem.id) > -1);
}

Alex ORLUC
committed
hasCurrentUserPrivilege(privilegeId: string) {
return this.headerService.user.privileges.indexOf(privilegeId) > -1;
}