BrightSide Workbench Full Report + Source Code
ContactPermissions.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2022 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Affero General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 package org.turro.security;
20 
21 import java.util.HashSet;
22 import org.turro.contacts.profile.ProfileContext;
23 import org.turro.plugin.contacts.IContact;
24 import org.turro.plugin.contacts.IProfile;
25 
30 public class ContactPermissions extends FlatPermissions {
31 
32  private final IContact contact;
33 
34  public ContactPermissions(IContact contact) {
35  this.contact = contact;
36  init();
37  }
38 
39  private void init() {
40  putAll(Permissions.from(new HashSet<>(contact.getSyndications())));
41  if(contact.isUser()) {
42  IProfile profile = contact.getProfile();
43  if(contact.isAdmin()) {
44  put("@admin", Permissions.IS_SET);
45  }
46  if(profile.isWorker()) {
47  put("@worker", Permissions.IS_SET);
48  }
49  if(profile.isStudent()) {
50  put("@student", Permissions.IS_SET);
51  }
52  if(profile.isResponsible()) {
53  put("@responsible", Permissions.IS_SET);
54  }
55  if(profile.isHHRR()) {
56  put("@hhrr", Permissions.IS_SET);
57  }
58  if(profile.isCompanyHHRR()) {
59  put("@companyhhrr", Permissions.IS_SET);
60  }
61  if(profile.isCenterHHRR()) {
62  put("@centerhhrr", Permissions.IS_SET);
63  }
64  if(profile.isTranslator()) {
65  put("@translator", Permissions.IS_SET);
66  }
67  if(profile.isSingleton()) {
68  put("@singleton", Permissions.IS_SET);
69  }
70  if(isInRole(ProfileContext.getNetworkingRoles())) {
71  put("@networking", Permissions.IS_SET);
72  }
73  if(isInRole(ProfileContext.getPremiumNetworkingRoles())) {
74  put("@premium", Permissions.IS_SET);
75  }
76  }
77  }
78 
79 }
static FlatPermissions from(Set< String > securityGroups)