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': 'lang.users',
'comment': 'lang.adminUsersDesc',

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Alex ORLUC
committed
'route': '/administration/alfresco',
'unit': 'supervision',
'style': 'alfresco',
'angular': true,
'hasParams': false
},
{
'id': 'admin_registered_mail',
'label': 'lang.registeredMails',
'comment': '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': 'lang.viewDocHistory',
'comment': 'lang.viewHistoryDesc',

Alex ORLUC
committed
'unit': 'history'

Alex ORLUC
committed
'id': 'view_full_history',
'label': 'lang.viewFullHistory',
'comment': 'lang.viewFullHistoryDesc',

Alex ORLUC
committed
'unit': 'history'

Alex ORLUC
committed
'id': 'edit_resource',
'label': 'lang.editResource',
'comment': 'lang.editResourceDesc',

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'add_links',
'label': 'lang.addLinks',
'comment': 'lang.addLinks',

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'manage_tags_application',
'label': 'lang.manageTagsInApplication',
'comment': 'lang.manageTagsInApplicationDesc',

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'create_contacts',
'label': 'lang.manageCreateContacts',
'comment': 'lang.manageCreateContactsDesc',

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'update_contacts',
'label': 'lang.manageUpdateContacts',
'comment': 'lang.manageUpdateContactsDesc',

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'update_diffusion_indexing',
'label': 'lang.allRoles',
'comment': 'lang.updateDiffusionWhileIndexing',

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'update_diffusion_except_recipient_indexing',
'label': 'lang.rolesExceptAssignee',
'comment': 'lang.updateDiffusionExceptRecipientWhileIndexing',

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'update_diffusion_process',
'label': 'lang.allRoles',
'comment': 'lang.updateDiffusionWhileProcess',

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'update_diffusion_except_recipient_process',
'label': 'lang.rolesExceptAssignee',
'comment': 'lang.updateDiffusionExceptRecipientWhileProcess',

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'update_diffusion_details',
'label': 'lang.allRoles',
'comment': 'lang.updateDiffusionWhileDetails',

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'update_diffusion_except_recipient_details',
'label': 'lang.rolesExceptAssignee',
'comment': 'lang.updateDiffusionExceptRecipientWhileDetails',

Alex ORLUC
committed
'unit': 'diffusionList'

Alex ORLUC
committed
'id': 'sendmail',
'label': 'lang.sendmail',
'comment': 'lang.sendmail',

Alex ORLUC
committed
'unit': 'sendmail'

Alex ORLUC
committed
'id': 'use_mail_services',
'label': 'lang.useMailServices',
'comment': 'lang.useMailServices',

Alex ORLUC
committed
'unit': 'sendmail'

Alex ORLUC
committed
'id': 'view_documents_with_notes',
'label': 'lang.viewDocumentsWithNotes',
'comment': 'lang.viewDocumentsWithNotesDesc',

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'view_technical_infos',
'label': 'lang.viewTechnicalInformation',
'comment': 'lang.viewTechnicalInformation',

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'config_avis_workflow',
'label': 'lang.configAvisWorkflow',
'comment': 'lang.configAvisWorkflowDesc',

Alex ORLUC
committed
'unit': 'avis'

Alex ORLUC
committed
'id': 'config_avis_workflow_in_detail',
'label': 'lang.configAvisWorkflowInDetail',
'comment': 'lang.configAvisWorkflowInDetailDesc',

Alex ORLUC
committed
'unit': 'avis'

Alex ORLUC
committed
'id': 'avis_documents',
'label': 'lang.avisAnswer',
'comment': 'lang.avisAnswerDesc',

Alex ORLUC
committed
'unit': 'avis'

Alex ORLUC
committed
'id': 'config_visa_workflow',
'label': 'lang.configVisaWorkflow',
'comment': 'lang.configVisaWorkflowDesc',

Alex ORLUC
committed
'unit': 'visaWorkflow'

Alex ORLUC
committed
'id': 'config_visa_workflow_in_detail',
'label': 'lang.configVisaWorkflowInDetail',
'comment': 'lang.configVisaWorkflowInDetailDesc',

Alex ORLUC
committed
'unit': 'visaWorkflow'

Alex ORLUC
committed
'id': 'visa_documents',
'label': 'lang.visaAnswers',
'comment': 'lang.visaAnswersDesc',

Alex ORLUC
committed
'unit': 'visaWorkflow'

Alex ORLUC
committed
'id': 'sign_document',
'label': 'lang.signDocs',
'comment': 'lang.signDocs',

Alex ORLUC
committed
'unit': 'visaWorkflow'

Alex ORLUC
committed
'id': 'modify_visa_in_signatureBook',
'label': 'lang.modifyVisaInSignatureBook',
'comment': 'lang.modifyVisaInSignatureBookDesc',

Alex ORLUC
committed
'unit': 'visaWorkflow'

Alex ORLUC
committed
'id': 'print_folder_doc',
'label': 'lang.printFolderDoc',
'comment': 'lang.printFolderDoc',

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

Alex ORLUC
committed
'id': 'manage_attachments',
'label': 'lang.manageAttachments',
'comment': 'lang.manageAttachments',

Alex ORLUC
committed
'unit': 'application'

Alex ORLUC
committed
'id': 'view_personal_data',
'label': 'lang.viewPersonalData',
'comment': 'lang.viewPersonalData',

Alex ORLUC
committed
'unit': 'confidentialityAndSecurity'

Alex ORLUC
committed
'id': 'manage_personal_data',
'label': 'lang.managePersonalData',
'comment': 'lang.managePersonalData',

Alex ORLUC
committed
'unit': 'confidentialityAndSecurity'
},
'id': 'include_folders_and_followed_resources_perimeter',
'label': 'lang.includeFolderPerimeter',
'comment': 'lang.includeFolderPerimeter',
'unit': 'application'
},

Alex ORLUC
committed
'id': 'admin',
'label': 'lang.administration',
'comment': 'lang.administration',

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

Alex ORLUC
committed
'style': 'fa fa-search',
'unit': 'application',

Alex ORLUC
committed
'shortcut': true
},
{
'id': 'entities_print_sep_mlb',
'label': 'lang.entitiesSeparator',
'comment': 'lang.entitiesSeparator',

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

Alex ORLUC
committed
'route': '/saveNumericPackage',
'style': 'fa fa-file-archive',
'unit': 'sendmail',
'angular': true,
'shortcut': false
},
{
'id': 'registered_mail_receive_ar',
'label': 'lang.arReception',
'comment': 'lang.arReception',
'route': '/registeredMail/acknowledgement',
Guillaume Heurtier
committed
'style': 'fa fa-barcode',
'unit': 'registeredMails',
'angular': true,
'shortcut': false
},
{
'id': 'registered_mail_mass_import',
'label': 'lang.importRegisteredMails',
'comment': 'lang.importRegisteredMails',
'route': 'RegisteredMailImportComponent__modal',
'style': 'fas fa-dolly-flatbed',
'unit': 'registeredMails',
'angular': true,
'shortcut': false
shortcuts: any[] = [
{

Alex ORLUC
committed
'id': 'followed',
'label': 'lang.followedMail',
'comment': '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': 'lang.recordMail',
'comment': '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': 'lang.followedMail',
'comment': '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': 'lang.recordMail',
'comment': '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;
}