Newer
Older
import { Injectable } from '@angular/core';
import { LANG } from '../app/translate.component';
import { HeaderService } from './header.service';
'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 {
'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
}
interface privilege {
'id': string, // identifier
'label': string, // title
'unit': string //category of administration
'comment': string, // description
}
@Injectable()
export class PrivilegeService {
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
lang: any = LANG;
private administrations: administration[] = [
{
"id": "admin_users",
"label": this.lang.users,
"comment": this.lang.adminUsersDesc,
"route": "/administration/users",
"unit": "organisation",
"style": "fa fa-user",
"angular" : true
},
{
"id": "admin_groups",
"label": this.lang.groups,
"comment": this.lang.adminGroupsDesc,
"route": "/administration/groups",
"unit": "organisation",
"style": "fa fa-users",
"angular" : true
},
{
"id": "manage_entities",
"label": this.lang.entities,
"comment": this.lang.adminEntitiesDesc,
"route": "/administration/entities",
"unit": "organisation",
"style": "fa fa-sitemap",
"angular" : true
},
{
"id": "admin_listmodels",
"label": this.lang.workflowModels,
"comment": this.lang.adminWorkflowModelsDesc,
"route": "/administration/diffusionModels",
"unit": "organisation",
"style": "fa fa-th-list",
"angular" : true
},
{
"id": "admin_architecture",
"label": this.lang.documentTypes,
"comment": this.lang.adminDocumentTypesDesc,
"route": "/administration/doctypes",
"unit": "classement",
"style": "fa fa-suitcase",
"angular" : true
},
{
"id": "admin_tag",
"label": this.lang.tags,
"comment": this.lang.adminTagsDesc,

Florian Azizian
committed
"route": "index.php?page=manage_tag_list_controller&module=tags",
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
"unit": "classement",
"style": "fa fa-tags",
"angular" : false
},
{
"id": "admin_baskets",
"label": this.lang.baskets,
"comment": this.lang.adminBasketsDesc,
"route": "/administration/baskets",
"unit": "production",
"style": "fa fa-inbox",
"angular" : true
},
{
"id": "admin_status",
"label": this.lang.statuses,
"comment": this.lang.statusesAdmin,
"route": "/administration/statuses",
"unit": "production",
"style": "fa fa-check-circle",
"angular" : true
},
{
"id": "admin_actions",
"label": this.lang.actions,
"comment": this.lang.actionsAdmin,
"route": "/administration/actions",
"unit": "production",
"style": "fa fa-exchange-alt",
"angular" : true
},
{
"id": "admin_contacts",
"label": this.lang.contacts,
"comment": this.lang.contactsAdmin,

Florian Azizian
committed
"route": "index.php?page=admin_contacts&admin=contacts",
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"unit": "production",
"style": "fa fa-book",
"angular" : false
},
{
"id": "admin_priorities",
"label": this.lang.prioritiesAlt,
"comment": this.lang.prioritiesAlt,
"route": "/administration/priorities",
"unit": "production",
"style": "fa fa-clock",
"angular" : true
},
{
"id": "admin_templates",
"label": this.lang.templates,
"comment": this.lang.templatesAdmin,
"route": "/administration/templates",
"unit": "production",
"style": "fa fa-file-alt",
"angular" : true
},
{
"id": "admin_indexing_models",
"label": this.lang.indexingModels,
"comment": this.lang.indexingModels,
"route": "/administration/indexingModels",
"unit": "production",
"style": "fab fa-wpforms",
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
"angular" : true
},
{
"id": "admin_custom_fields",
"label": this.lang.customFieldsAdmin,
"comment": this.lang.customFieldsAdmin,
"route": "/administration/customFields",
"unit": "production",
"style": "fa fa-code",
"angular" : true
},
{
"id": "admin_notif",
"label": this.lang.notifications,
"comment": this.lang.notificationsAdmin,
"route": "/administration/notifications",
"unit": "production",
"style": "fa fa-bell",
"angular" : true
},
{
"id": "update_status_mail",
"label": this.lang.updateStatus,
"comment": this.lang.updateStatus,
"route": "/administration/update-status",
"unit": "supervision",
"style": "fa fa-envelope-square",
"angular" : true
},
{
"id": "admin_docservers",
"label": this.lang.docservers,
"comment": this.lang.docserversAdmin,
"route": "/administration/docservers",
"unit": "supervision",
"style": "fa fa-hdd",
"angular" : true
},
{
"id": "admin_parameters",
"label": this.lang.parameters,
"comment": this.lang.parameters,
"route": "/administration/parameters",
"unit": "supervision",
"style": "fa fa-wrench",
"angular" : true
},
{
"id": "admin_password_rules",
"label": this.lang.securities,
"comment": this.lang.securities,
"route": "/administration/securities",
"unit": "supervision",
"style": "fa fa-lock",
"angular" : true
},
{
"id": "admin_email_server",
"label": this.lang.emailServerParam,
"comment": this.lang.emailServerParamDesc,
"route": "/administration/sendmail",
"unit": "supervision",
"style": "fa fa-mail-bulk",
"angular" : true
},
{
"id": "admin_shippings",
"label": this.lang.mailevaAdmin,
"comment": this.lang.mailevaAdminDesc,
"route": "/administration/shippings",
"unit": "supervision",
"style": "fa fa-shipping-fast",
"angular" : true
},
{
"id": "admin_reports",
"label": this.lang.reports,
"comment": this.lang.reportsAdmin,
"route": "/administration/reports",
"unit": "supervision",
"style": "fa fa-chart-area",
"angular" : true
},
{
"id": "view_history",
"label": this.lang.history,
"comment": this.lang.viewHistoryDesc,
"route": "/administration/history",
"unit": "supervision",
"style": "fa fa-history",
"angular" : true
},
{
"id": "view_history_batch",
"label": this.lang.historyBatch,
"comment": this.lang.historyBatchAdmin,
"route": "/administration/history",
"unit": "supervision",
"style": "fa fa-history",
"angular" : true
},
{
"id": "admin_update_control",
"label": this.lang.updateControl,
"comment": this.lang.updateControlDesc,
"route": "/administration/versions-update",
"unit": "supervision",
"style": "fa fa-sync",
"angular" : true
}
];
private privileges: privilege[] = [
{
"id": "view_doc_history",
"label": this.lang.viewDocHistory,
"comment": this.lang.viewHistoryDesc,
},
{
"id": "view_full_history",
"label": this.lang.viewFullHistory,
"comment": this.lang.viewFullHistoryDesc,
},
{
"id": "edit_document_in_detail",
"label": this.lang.editDocumentInDetail,
"comment": this.lang.editDocumentInDetailDesc,
"unit": 'application'
},
{
"id": "delete_document_in_detail",
"label": this.lang.deleteDocumentInDetail,
"comment": this.lang.deleteDocumentInDetail,
"unit": 'application'
},
{
"id": "manage_tags_application",
"label": this.lang.manageTagsInApplication,
"comment": this.lang.manageTagsInApplicationDesc,
"unit": 'application'
},
{
"id": "update_diffusion_indexing",
"comment": this.lang.updateDiffusionWhileIndexing,
},
{
"id": "update_diffusion_except_recipient_indexing",
"label": this.lang.rolesExceptAssignee,
"comment": this.lang.updateDiffusionExceptRecipientWhileIndexing,
},
{
"id": "update_diffusion_details",
"comment": this.lang.updateDiffusionWhileDetails,
},
{
"id": "update_diffusion_except_recipient_details",
"label": this.lang.rolesExceptAssignee,
"comment": this.lang.updateDiffusionExceptRecipientWhileDetails,
},
{
"id": "sendmail",
"label": this.lang.sendmail,
"comment": this.lang.sendmail,
},
{
"id": "use_mail_services",
"label": this.lang.useMailServices,
"comment": this.lang.useMailServices,
},
{
"id": "view_documents_with_notes",
"label": this.lang.viewDocumentsWithNotes,
"comment": this.lang.viewDocumentsWithNotesDesc,
"unit": 'application'
},
{
"id": "view_technical_infos",
"label": this.lang.viewTechnicalInformation,
"comment": this.lang.viewTechnicalInformation,
"unit": 'application'
},
{
"id": "config_avis_workflow",
"label": this.lang.configAvisWorkflow,
"comment": this.lang.configAvisWorkflowDesc,
},
{
"id": "config_avis_workflow_in_detail",
"label": this.lang.configAvisWorkflowInDetail,
"comment": this.lang.configAvisWorkflowInDetailDesc,
},
{
"id": "avis_documents",
"label": this.lang.avisAnswer,
"comment": this.lang.avisAnswerDesc,
},
{
"id": "config_visa_workflow",
"label": this.lang.configVisaWorkflow,
"comment": this.lang.configVisaWorkflowDesc,
},
{
"id": "config_visa_workflow_in_detail",
"label": this.lang.configVisaWorkflowInDetail,
"comment": this.lang.configVisaWorkflowInDetailDesc,
},
{
"id": "visa_documents",
"label": this.lang.visaAnswers,
"comment": this.lang.visaAnswersDesc,
},
{
"id": "sign_document",
"label": this.lang.signDocs,
"comment": this.lang.signDocs,
},
{
"id": "modify_visa_in_signatureBook",
"label": this.lang.modifyVisaInSignatureBook,
"comment": this.lang.modifyVisaInSignatureBookDesc,
},
{
"id": "use_date_in_signBlock",
"label": this.lang.useDateInSignBlock,
"comment": this.lang.useDateInSignBlockDesc,
},
{
"id": "print_folder_doc",
"label": this.lang.printFolderDoc,
"comment": this.lang.printFolderDoc,
"unit": 'application'
},
{
"id": "manage_attachments",
"label": this.lang.manageAttachments,
"comment": this.lang.manageAttachments,
"unit": 'application'
},
{
"id": "manage_own_attachments_in_details",
"label": this.lang.manageOwnAttachmentsInDetails,
"comment": this.lang.manageOwnAttachmentsInDetails,
"unit": 'application'
},
{
"id": "view_personal_data",
"label": this.lang.viewPersonalData,
"comment": this.lang.viewPersonalData,
"unit": 'application'
},
{
"id": "manage_personal_data",
"label": this.lang.managePersonalData,
"comment": this.lang.managePersonalData,
"unit": 'application'
private menus: menu[] = [
{
"id": "admin",
"label": this.lang.administration,
"comment": this.lang.administration,
"route": "/administration",
"style": "fa fa-cogs",
"unit": "application",
"angular": true,
'shortcut' : true
},
{
"id": "adv_search_mlb",
"label": this.lang.search,
"comment": this.lang.search,

Florian Azizian
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.lang.entitiesSeparator,
"comment": this.lang.entitiesSeparator,
"route": "/separators/print",
"style": "fa fa-print",
"unit": "entities",
"angular": true,
'shortcut' : false
},
{
"id": "reports",
"label": this.lang.reports,
"comment": this.lang.reports,

Florian Azizian
committed
"route": "index.php?page=reports&module=reports",
"style": "fa fa-chart-area",
"unit": "reports",
"angular": false,
'shortcut' : false
},
{
"id": "save_numeric_package",
"label": this.lang.saveNumericPackage,
"comment": this.lang.saveNumericPackage,
"route": "/saveNumericPackage",
"style": "fa fa-file-archive",
"unit": "sendmail",
"angular": true,
'shortcut' : false
}
];
constructor(public headerService: HeaderService) { }
getPrivileges(ids: string[]=null) {
if (ids !== null) {
return this.privileges.filter(elem => ids.indexOf(elem.id) > -1);
} else {
return this.privileges;
}
getUnitsPrivileges(): Array<string> {
return this.privileges.map(elem => elem.unit).filter((elem, pos, arr) => arr.indexOf(elem) === pos);
}
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 = {
"id": "indexing",
"label": this.lang.recordMail,
"comment": this.lang.recordMail,
"route": "/indexing/"+indexingGroups[0].id,
"style": "fa fa-file-medical",
"unit": "application",
"angular": true,
'shortcut' : true,
"groups": indexingGroups
};
menus.push(indexingmenu);
}
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);
}
getCurrentUserShortcuts(): Array<menu> {
let shortcuts: any[] = [
{
"id": "home",
"label": this.lang.home,
"comment": this.lang.home,
"route": "/home",
"style": "fa fa-home",
"unit": "application",
"angular": true,
"shortcut" : true
}
];
shortcuts = 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 = {
"id": "indexing",
"label": this.lang.recordMail,
"comment": this.lang.recordMail,
"style": "fa fa-file-medical",
"unit": "application",
"angular": true,
'shortcut' : true,
"groups": indexingGroups
};
shortcuts.push(indexingShortcut);
}
return shortcuts;
}
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);
}
hasCurrentUserPrivilege(privilegeId: string) {
return this.headerService.user.privileges.indexOf(privilegeId) > -1;
}