Skip to content

Commit

Permalink
Расширения информации о правах (#465)
Browse files Browse the repository at this point in the history
* add feature #108

Для MDO\MDC добавлена возможность понять можно ли управлять правами доступа и какими

* add feature #108

Добавлены методы определения наличия нужного права и списка ролей с ныжным правом
  • Loading branch information
theshadowco authored Jul 8, 2024
1 parent 280e7d0 commit d2dd7df
Show file tree
Hide file tree
Showing 50 changed files with 1,385 additions and 92 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/github/_1c_syntax/bsl/mdclasses/CF.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.Map;
import java.util.Optional;

public interface CF extends MDClass, ConfigurationTree {
public interface CF extends MDClass, ConfigurationTree, CFAccess {

/**
* Язык приложения по умолчанию
Expand Down
102 changes: 102 additions & 0 deletions src/main/java/com/github/_1c_syntax/bsl/mdclasses/CFAccess.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* This file is a part of MDClasses.
*
* Copyright (c) 2019 - 2024
* Tymko Oleg <[email protected]>, Maximov Valery <[email protected]> and contributors
*
* SPDX-License-Identifier: LGPL-3.0-or-later
*
* MDClasses is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* MDClasses is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with MDClasses.
*/
package com.github._1c_syntax.bsl.mdclasses;


import com.github._1c_syntax.bsl.mdclasses.helpers.Rights;
import com.github._1c_syntax.bsl.mdo.AccessRightsOwner;
import com.github._1c_syntax.bsl.mdo.MD;
import com.github._1c_syntax.bsl.mdo.Role;
import com.github._1c_syntax.bsl.mdo.support.RoleRight;
import com.github._1c_syntax.bsl.types.MdoReference;

import java.util.List;

/**
* Расширение - права доступа
*/
public interface CFAccess extends AccessRightsOwner {

/**
* Проверяет наличие указанного разрешения хотя бы у одной роли для конфигурации/расширения
*
* @param roleRight Право доступа
* @return Наличие права доступа
*/
default boolean rightAccess(RoleRight roleRight) {
return Rights.rightAccess((CF) this, roleRight);
}

/**
* Проверяет наличие указанного разрешения хотя бы у одной роли для MD
*
* @param roleRight Право доступа
* @param md Любой объект md
* @return Наличие права доступа
*/
default boolean rightAccess(RoleRight roleRight, MD md) {
return Rights.rightAccess((CF) this, roleRight, md);
}

/**
* Проверяет наличие указанного разрешения хотя бы у одной роли для ссылки
*
* @param roleRight Право доступа
* @param mdoReference Ссылка mdo reference
* @return Наличие права доступа
*/
default boolean rightAccess(RoleRight roleRight, MdoReference mdoReference) {
return Rights.rightAccess((CF) this, roleRight, mdoReference);
}

/**
* Возвращает список ролей, имеющих указанное разрешения для конфигурации/расширения
*
* @param roleRight Право доступа
* @return Список ролей с правом
*/
default List<Role> rolesAccess(RoleRight roleRight) {
return Rights.rolesAccess((CF) this, roleRight);
}

/**
* Возвращает список ролей, имеющих указанное разрешения для md
*
* @param roleRight Право доступа
* @param md Любой объект md
* @return Список ролей с правом
*/
default List<Role> rolesAccess(RoleRight roleRight, MD md) {
return Rights.rolesAccess((CF) this, roleRight, md);
}

/**
* Возвращает список ролей, имеющих указанное разрешения для ссылки
*
* @param roleRight Право доступа
* @param mdoReference Ссылка mdo reference
* @return Список ролей с правом
*/
default List<Role> rolesAccess(RoleRight roleRight, MdoReference mdoReference) {
return Rights.rolesAccess((CF) this, roleRight, mdoReference);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import com.github._1c_syntax.bsl.mdo.support.DataLockControlMode;
import com.github._1c_syntax.bsl.mdo.support.MultiLanguageString;
import com.github._1c_syntax.bsl.mdo.support.ObjectBelonging;
import com.github._1c_syntax.bsl.mdo.support.RoleRight;
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant;
import com.github._1c_syntax.bsl.mdo.support.UseMode;
import com.github._1c_syntax.bsl.mdo.support.UsePurposes;
Expand Down Expand Up @@ -112,6 +113,8 @@ public class Configuration implements CF {
*/
public static final Configuration EMPTY = createEmptyConfiguration();

private static final List<RoleRight> POSSIBLE_RIGHTS = computePossibleRighs();

/*
* CF
*/
Expand Down Expand Up @@ -342,6 +345,13 @@ public Map<URI, Module> getModulesByURI() {
return modulesByURI.getOrCompute();
}

/**
* Возвращает перечень возможных прав доступа
*/
public static List<RoleRight> possibleRights() {
return POSSIBLE_RIGHTS;
}

private List<MD> computePlainChildren() {
return LazyLoader.computePlainChildren(this);
}
Expand Down Expand Up @@ -371,4 +381,35 @@ private static Configuration createEmptyConfiguration() {
.uuid(emptyString)
.build();
}

private static List<RoleRight> computePossibleRighs() {
return List.of(
RoleRight.ADMINISTRATION,
RoleRight.DATA_ADMINISTRATION,
RoleRight.UPDATE_DATA_BASE_CONFIGURATION,
RoleRight.EXCLUSIVE_MODE,
RoleRight.ACTIVE_USERS,
RoleRight.EVENT_LOG,
RoleRight.THIN_CLIENT,
RoleRight.WEB_CLIENT,
RoleRight.MOBILE_CLIENT,
RoleRight.THICK_CLIENT,
RoleRight.EXTERNAL_CONNECTION,
RoleRight.AUTOMATION,
RoleRight.TECHNICAL_SPECIALIST_MODE,
RoleRight.COLLABORATION_SYSTEM_INFO_BASE_REGISTRATION,
RoleRight.MAIN_WINDOW_MODE_EMBEDDED_WORKPLACE,
RoleRight.MAIN_WINDOW_MODE_KIOSK,
RoleRight.MAIN_WINDOW_MODE_NORMAL,
RoleRight.MAIN_WINDOW_MODE_FULLSCREEN_WORKPLACE,
RoleRight.MAIN_WINDOW_MODE_WORKPLACE,
RoleRight.ANALYTICS_SYSTEM_CLIENT,
RoleRight.EXCLUSIVE_MODE_TERMINATION_AT_SESSION_START,
RoleRight.SAVE_USER_DATA,
RoleRight.CONFIGURATION_EXTENSIONS_ADMINISTRATION,
RoleRight.INTERACTIVE_OPEN_EXT_DATA_PROCESSORS,
RoleRight.INTERACTIVE_OPEN_EXT_REPORTS,
RoleRight.OUTPUT
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
import com.github._1c_syntax.bsl.mdo.support.ConfigurationExtensionPurpose;
import com.github._1c_syntax.bsl.mdo.support.MultiLanguageString;
import com.github._1c_syntax.bsl.mdo.support.ObjectBelonging;
import com.github._1c_syntax.bsl.mdo.support.RoleRight;
import com.github._1c_syntax.bsl.mdo.support.ScriptVariant;
import com.github._1c_syntax.bsl.mdo.support.UsePurposes;
import com.github._1c_syntax.bsl.mdo.utils.LazyLoader;
Expand Down Expand Up @@ -289,6 +290,13 @@ public Map<URI, Module> getModulesByURI() {
return modulesByURI.getOrCompute();
}

/**
* Возвращает перечень возможных прав доступа
*/
public static List<RoleRight> possibleRights() {
return Configuration.possibleRights();
}

private List<MD> computePlainChildren() {
return LazyLoader.computePlainChildren(this);
}
Expand All @@ -301,7 +309,6 @@ private Map<URI, MD> computeModulesByObject() {
return LazyLoader.computeModulesByObject(this);
}


private List<Module> computeAllModules() {
return LazyLoader.computeAllModules(this);
}
Expand Down
Loading

0 comments on commit d2dd7df

Please sign in to comment.