Skip to content

Commit d2dd7df

Browse files
authored
Расширения информации о правах (#465)
* add feature #108 Для MDO\MDC добавлена возможность понять можно ли управлять правами доступа и какими * add feature #108 Добавлены методы определения наличия нужного права и списка ролей с ныжным правом
1 parent 280e7d0 commit d2dd7df

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1385
-92
lines changed

src/main/java/com/github/_1c_syntax/bsl/mdclasses/CF.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
import java.util.Map;
3939
import java.util.Optional;
4040

41-
public interface CF extends MDClass, ConfigurationTree {
41+
public interface CF extends MDClass, ConfigurationTree, CFAccess {
4242

4343
/**
4444
* Язык приложения по умолчанию
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*
2+
* This file is a part of MDClasses.
3+
*
4+
* Copyright (c) 2019 - 2024
5+
* Tymko Oleg <olegtymko@yandex.ru>, Maximov Valery <maximovvalery@gmail.com> and contributors
6+
*
7+
* SPDX-License-Identifier: LGPL-3.0-or-later
8+
*
9+
* MDClasses is free software; you can redistribute it and/or
10+
* modify it under the terms of the GNU Lesser General Public
11+
* License as published by the Free Software Foundation; either
12+
* version 3.0 of the License, or (at your option) any later version.
13+
*
14+
* MDClasses is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
* Lesser General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Lesser General Public
20+
* License along with MDClasses.
21+
*/
22+
package com.github._1c_syntax.bsl.mdclasses;
23+
24+
25+
import com.github._1c_syntax.bsl.mdclasses.helpers.Rights;
26+
import com.github._1c_syntax.bsl.mdo.AccessRightsOwner;
27+
import com.github._1c_syntax.bsl.mdo.MD;
28+
import com.github._1c_syntax.bsl.mdo.Role;
29+
import com.github._1c_syntax.bsl.mdo.support.RoleRight;
30+
import com.github._1c_syntax.bsl.types.MdoReference;
31+
32+
import java.util.List;
33+
34+
/**
35+
* Расширение - права доступа
36+
*/
37+
public interface CFAccess extends AccessRightsOwner {
38+
39+
/**
40+
* Проверяет наличие указанного разрешения хотя бы у одной роли для конфигурации/расширения
41+
*
42+
* @param roleRight Право доступа
43+
* @return Наличие права доступа
44+
*/
45+
default boolean rightAccess(RoleRight roleRight) {
46+
return Rights.rightAccess((CF) this, roleRight);
47+
}
48+
49+
/**
50+
* Проверяет наличие указанного разрешения хотя бы у одной роли для MD
51+
*
52+
* @param roleRight Право доступа
53+
* @param md Любой объект md
54+
* @return Наличие права доступа
55+
*/
56+
default boolean rightAccess(RoleRight roleRight, MD md) {
57+
return Rights.rightAccess((CF) this, roleRight, md);
58+
}
59+
60+
/**
61+
* Проверяет наличие указанного разрешения хотя бы у одной роли для ссылки
62+
*
63+
* @param roleRight Право доступа
64+
* @param mdoReference Ссылка mdo reference
65+
* @return Наличие права доступа
66+
*/
67+
default boolean rightAccess(RoleRight roleRight, MdoReference mdoReference) {
68+
return Rights.rightAccess((CF) this, roleRight, mdoReference);
69+
}
70+
71+
/**
72+
* Возвращает список ролей, имеющих указанное разрешения для конфигурации/расширения
73+
*
74+
* @param roleRight Право доступа
75+
* @return Список ролей с правом
76+
*/
77+
default List<Role> rolesAccess(RoleRight roleRight) {
78+
return Rights.rolesAccess((CF) this, roleRight);
79+
}
80+
81+
/**
82+
* Возвращает список ролей, имеющих указанное разрешения для md
83+
*
84+
* @param roleRight Право доступа
85+
* @param md Любой объект md
86+
* @return Список ролей с правом
87+
*/
88+
default List<Role> rolesAccess(RoleRight roleRight, MD md) {
89+
return Rights.rolesAccess((CF) this, roleRight, md);
90+
}
91+
92+
/**
93+
* Возвращает список ролей, имеющих указанное разрешения для ссылки
94+
*
95+
* @param roleRight Право доступа
96+
* @param mdoReference Ссылка mdo reference
97+
* @return Список ролей с правом
98+
*/
99+
default List<Role> rolesAccess(RoleRight roleRight, MdoReference mdoReference) {
100+
return Rights.rolesAccess((CF) this, roleRight, mdoReference);
101+
}
102+
}

src/main/java/com/github/_1c_syntax/bsl/mdclasses/Configuration.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import com.github._1c_syntax.bsl.mdo.support.DataLockControlMode;
7575
import com.github._1c_syntax.bsl.mdo.support.MultiLanguageString;
7676
import com.github._1c_syntax.bsl.mdo.support.ObjectBelonging;
77+
import com.github._1c_syntax.bsl.mdo.support.RoleRight;
7778
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant;
7879
import com.github._1c_syntax.bsl.mdo.support.UseMode;
7980
import com.github._1c_syntax.bsl.mdo.support.UsePurposes;
@@ -112,6 +113,8 @@ public class Configuration implements CF {
112113
*/
113114
public static final Configuration EMPTY = createEmptyConfiguration();
114115

116+
private static final List<RoleRight> POSSIBLE_RIGHTS = computePossibleRighs();
117+
115118
/*
116119
* CF
117120
*/
@@ -342,6 +345,13 @@ public Map<URI, Module> getModulesByURI() {
342345
return modulesByURI.getOrCompute();
343346
}
344347

348+
/**
349+
* Возвращает перечень возможных прав доступа
350+
*/
351+
public static List<RoleRight> possibleRights() {
352+
return POSSIBLE_RIGHTS;
353+
}
354+
345355
private List<MD> computePlainChildren() {
346356
return LazyLoader.computePlainChildren(this);
347357
}
@@ -371,4 +381,35 @@ private static Configuration createEmptyConfiguration() {
371381
.uuid(emptyString)
372382
.build();
373383
}
384+
385+
private static List<RoleRight> computePossibleRighs() {
386+
return List.of(
387+
RoleRight.ADMINISTRATION,
388+
RoleRight.DATA_ADMINISTRATION,
389+
RoleRight.UPDATE_DATA_BASE_CONFIGURATION,
390+
RoleRight.EXCLUSIVE_MODE,
391+
RoleRight.ACTIVE_USERS,
392+
RoleRight.EVENT_LOG,
393+
RoleRight.THIN_CLIENT,
394+
RoleRight.WEB_CLIENT,
395+
RoleRight.MOBILE_CLIENT,
396+
RoleRight.THICK_CLIENT,
397+
RoleRight.EXTERNAL_CONNECTION,
398+
RoleRight.AUTOMATION,
399+
RoleRight.TECHNICAL_SPECIALIST_MODE,
400+
RoleRight.COLLABORATION_SYSTEM_INFO_BASE_REGISTRATION,
401+
RoleRight.MAIN_WINDOW_MODE_EMBEDDED_WORKPLACE,
402+
RoleRight.MAIN_WINDOW_MODE_KIOSK,
403+
RoleRight.MAIN_WINDOW_MODE_NORMAL,
404+
RoleRight.MAIN_WINDOW_MODE_FULLSCREEN_WORKPLACE,
405+
RoleRight.MAIN_WINDOW_MODE_WORKPLACE,
406+
RoleRight.ANALYTICS_SYSTEM_CLIENT,
407+
RoleRight.EXCLUSIVE_MODE_TERMINATION_AT_SESSION_START,
408+
RoleRight.SAVE_USER_DATA,
409+
RoleRight.CONFIGURATION_EXTENSIONS_ADMINISTRATION,
410+
RoleRight.INTERACTIVE_OPEN_EXT_DATA_PROCESSORS,
411+
RoleRight.INTERACTIVE_OPEN_EXT_REPORTS,
412+
RoleRight.OUTPUT
413+
);
414+
}
374415
}

src/main/java/com/github/_1c_syntax/bsl/mdclasses/ConfigurationExtension.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import com.github._1c_syntax.bsl.mdo.support.ConfigurationExtensionPurpose;
7575
import com.github._1c_syntax.bsl.mdo.support.MultiLanguageString;
7676
import com.github._1c_syntax.bsl.mdo.support.ObjectBelonging;
77+
import com.github._1c_syntax.bsl.mdo.support.RoleRight;
7778
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant;
7879
import com.github._1c_syntax.bsl.mdo.support.UsePurposes;
7980
import com.github._1c_syntax.bsl.mdo.utils.LazyLoader;
@@ -289,6 +290,13 @@ public Map<URI, Module> getModulesByURI() {
289290
return modulesByURI.getOrCompute();
290291
}
291292

293+
/**
294+
* Возвращает перечень возможных прав доступа
295+
*/
296+
public static List<RoleRight> possibleRights() {
297+
return Configuration.possibleRights();
298+
}
299+
292300
private List<MD> computePlainChildren() {
293301
return LazyLoader.computePlainChildren(this);
294302
}
@@ -301,7 +309,6 @@ private Map<URI, MD> computeModulesByObject() {
301309
return LazyLoader.computeModulesByObject(this);
302310
}
303311

304-
305312
private List<Module> computeAllModules() {
306313
return LazyLoader.computeAllModules(this);
307314
}

0 commit comments

Comments
 (0)