Skip to content

Commit

Permalink
Добавлена поддержка прав доступа хранящихся в ролях
Browse files Browse the repository at this point in the history
  • Loading branch information
Viktor Gukov committed Oct 13, 2020
1 parent 74bcca0 commit 404fced
Show file tree
Hide file tree
Showing 8 changed files with 263 additions and 74 deletions.
45 changes: 45 additions & 0 deletions src/main/java/com/github/_1c_syntax/mdclasses/mdo/ObjectRight.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* This file is a part of MDClasses.
*
* Copyright © 2019 - 2020
* 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.mdclasses.mdo;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Collections;
import java.util.List;

/**
* POJO представление прав доступа объекта метаданных, содержащихся в конкретной роли
*/
@Getter
@Setter
@NoArgsConstructor
public class ObjectRight {
private String name = "";

@XStreamAlias("right")
@XStreamImplicit
List<Right> rights = Collections.emptyList();
}
37 changes: 37 additions & 0 deletions src/main/java/com/github/_1c_syntax/mdclasses/mdo/Right.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* This file is a part of MDClasses.
*
* Copyright © 2019 - 2020
* 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.mdclasses.mdo;

import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
* POJO представление конкретного права доступа, находящегося в роли
*/
@Getter
@Setter
@NoArgsConstructor
public class Right {
private String name = "";
private boolean value = false;
}
6 changes: 4 additions & 2 deletions src/main/java/com/github/_1c_syntax/mdclasses/mdo/Role.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,19 @@

import com.github._1c_syntax.mdclasses.mdo.wrapper.DesignerMDO;
import com.github._1c_syntax.mdclasses.metadata.additional.MDOType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;
import lombok.Value;

@Value
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true, onlyExplicitlyIncluded = true)
@NoArgsConstructor
public class Role extends MDObjectBase {

private RoleData roleData;

public Role(DesignerMDO designerMDO) {
super(designerMDO);
}
Expand Down
52 changes: 52 additions & 0 deletions src/main/java/com/github/_1c_syntax/mdclasses/mdo/RoleData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* This file is a part of MDClasses.
*
* Copyright © 2019 - 2020
* 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.mdclasses.mdo;

import com.thoughtworks.xstream.annotations.XStreamAlias;
import com.thoughtworks.xstream.annotations.XStreamImplicit;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.Collections;
import java.util.List;


/**
* POJO представление данных конкретной роли
*/
@NoArgsConstructor
@Getter
@Setter
public class RoleData {

@XStreamAlias("setForNewObjects")
private boolean setForNewObjects = false;
@XStreamAlias("setForAttributesByDefault")
private boolean setForAttributesByDefault = false;
@XStreamAlias("independentRightsOfChildObjects")
private boolean independentRightsOfChildObjects = false;

@XStreamAlias("object")
@XStreamImplicit
List<ObjectRight> objectRights = Collections.emptyList();
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,7 @@
*/
package com.github._1c_syntax.mdclasses.unmarshal;

import com.github._1c_syntax.mdclasses.mdo.AccountingRegister;
import com.github._1c_syntax.mdclasses.mdo.AccumulationRegister;
import com.github._1c_syntax.mdclasses.mdo.BusinessProcess;
import com.github._1c_syntax.mdclasses.mdo.CalculationRegister;
import com.github._1c_syntax.mdclasses.mdo.Catalog;
import com.github._1c_syntax.mdclasses.mdo.ChartOfAccounts;
import com.github._1c_syntax.mdclasses.mdo.ChartOfCalculationTypes;
import com.github._1c_syntax.mdclasses.mdo.ChartOfCharacteristicTypes;
import com.github._1c_syntax.mdclasses.mdo.CommandGroup;
import com.github._1c_syntax.mdclasses.mdo.CommonAttribute;
import com.github._1c_syntax.mdclasses.mdo.CommonCommand;
import com.github._1c_syntax.mdclasses.mdo.CommonForm;
import com.github._1c_syntax.mdclasses.mdo.CommonModule;
import com.github._1c_syntax.mdclasses.mdo.CommonPicture;
import com.github._1c_syntax.mdclasses.mdo.CommonTemplate;
import com.github._1c_syntax.mdclasses.mdo.Constant;
import com.github._1c_syntax.mdclasses.mdo.DataProcessor;
import com.github._1c_syntax.mdclasses.mdo.DefinedType;
import com.github._1c_syntax.mdclasses.mdo.Document;
import com.github._1c_syntax.mdclasses.mdo.DocumentJournal;
import com.github._1c_syntax.mdclasses.mdo.DocumentNumerator;
import com.github._1c_syntax.mdclasses.mdo.EventSubscription;
import com.github._1c_syntax.mdclasses.mdo.ExchangePlan;
import com.github._1c_syntax.mdclasses.mdo.FilterCriterion;
import com.github._1c_syntax.mdclasses.mdo.FunctionalOption;
import com.github._1c_syntax.mdclasses.mdo.FunctionalOptionsParameter;
import com.github._1c_syntax.mdclasses.mdo.HTTPService;
import com.github._1c_syntax.mdclasses.mdo.InformationRegister;
import com.github._1c_syntax.mdclasses.mdo.MDOConfiguration;
import com.github._1c_syntax.mdclasses.mdo.MDOEnum;
import com.github._1c_syntax.mdclasses.mdo.MDObjectComplex;
import com.github._1c_syntax.mdclasses.mdo.Report;
import com.github._1c_syntax.mdclasses.mdo.Role;
import com.github._1c_syntax.mdclasses.mdo.ScheduledJob;
import com.github._1c_syntax.mdclasses.mdo.Sequence;
import com.github._1c_syntax.mdclasses.mdo.SessionParameter;
import com.github._1c_syntax.mdclasses.mdo.SettingsStorage;
import com.github._1c_syntax.mdclasses.mdo.Style;
import com.github._1c_syntax.mdclasses.mdo.StyleItem;
import com.github._1c_syntax.mdclasses.mdo.Subsystem;
import com.github._1c_syntax.mdclasses.mdo.TabularSection;
import com.github._1c_syntax.mdclasses.mdo.Task;
import com.github._1c_syntax.mdclasses.mdo.WSReference;
import com.github._1c_syntax.mdclasses.mdo.WebService;
import com.github._1c_syntax.mdclasses.mdo.XDTOPackage;
import com.github._1c_syntax.mdclasses.mdo.*;
import com.github._1c_syntax.mdclasses.mdo.wrapper.DesignerChildObjects;
import com.github._1c_syntax.mdclasses.mdo.wrapper.DesignerWrapper;
import com.github._1c_syntax.mdclasses.metadata.additional.ConfigurationExtensionPurpose;
Expand Down Expand Up @@ -250,6 +206,7 @@ private void addClassAliases(XStream xStream) {
xStream.alias("mdclass:Enum", MDOEnum.class);
xStream.alias("mdclass:Report", Report.class);
xStream.alias("mdclass:Role", Role.class);
xStream.alias("Rights", RoleData.class);
xStream.alias("mdclass:ScheduledJob", ScheduledJob.class);
xStream.alias("mdclass:Sequence", Sequence.class);
xStream.alias("mdclass:SessionParameter", SessionParameter.class);
Expand Down
53 changes: 26 additions & 27 deletions src/main/java/com/github/_1c_syntax/mdclasses/utils/MDOFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,40 +21,17 @@
*/
package com.github._1c_syntax.mdclasses.utils;

import com.github._1c_syntax.mdclasses.mdo.Command;
import com.github._1c_syntax.mdclasses.mdo.Form;
import com.github._1c_syntax.mdclasses.mdo.HTTPService;
import com.github._1c_syntax.mdclasses.mdo.HTTPServiceURLTemplate;
import com.github._1c_syntax.mdclasses.mdo.Language;
import com.github._1c_syntax.mdclasses.mdo.MDOAttribute;
import com.github._1c_syntax.mdclasses.mdo.MDOConfiguration;
import com.github._1c_syntax.mdclasses.mdo.MDObjectBSL;
import com.github._1c_syntax.mdclasses.mdo.MDObjectBase;
import com.github._1c_syntax.mdclasses.mdo.MDObjectComplex;
import com.github._1c_syntax.mdclasses.mdo.Subsystem;
import com.github._1c_syntax.mdclasses.mdo.TabularSection;
import com.github._1c_syntax.mdclasses.mdo.Template;
import com.github._1c_syntax.mdclasses.mdo.WEBServiceOperation;
import com.github._1c_syntax.mdclasses.mdo.WebService;
import com.github._1c_syntax.mdclasses.mdo.*;
import com.github._1c_syntax.mdclasses.mdo.wrapper.DesignerWrapper;
import com.github._1c_syntax.mdclasses.metadata.additional.ConfigurationSource;
import com.github._1c_syntax.mdclasses.metadata.additional.MDOModule;
import com.github._1c_syntax.mdclasses.metadata.additional.MDOReference;
import com.github._1c_syntax.mdclasses.metadata.additional.MDOType;
import com.github._1c_syntax.mdclasses.metadata.additional.ModuleType;
import com.github._1c_syntax.mdclasses.metadata.additional.ScriptVariant;
import com.github._1c_syntax.mdclasses.metadata.additional.*;
import com.github._1c_syntax.mdclasses.unmarshal.XStreamFactory;
import io.vavr.control.Either;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;

import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand Down Expand Up @@ -125,11 +102,33 @@ public Optional<MDObjectBase> readMDObject(ConfigurationSource configurationSour
setIncludedSubsystems((MDOConfiguration) mdoValue);
});
}

// загрузка данных роли
if (mdoValue instanceof Role) {
var roleDataPath = MDOPathUtils.getRoleDataPath(configurationSource,
mdoPath.getParent().toString(), mdoValue.getName());
var roleDataOptional = readRoleData(roleDataPath);
roleDataOptional.ifPresent(((Role) mdoValue)::setRoleData);
}
});

return mdo;
}

/**
* Читает данные роли из файла Rights
*
* @param roleDataPath - путь к файлу прав роли.
* @return {@code Optional} POJO представление данных ролей
*/
private static Optional<RoleData> readRoleData(Path roleDataPath) {
if (Files.notExists(roleDataPath)) {
return Optional.empty();
}

return Optional.ofNullable((RoleData) XStreamFactory.fromXML(roleDataPath.toFile()));
}

/**
* Читает объект по его файлу описания, но не выполняет чтение дочерних элементов
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,23 @@ private Path getModulePathDesigner(Path folder, String name, ModuleType moduleTy
return Paths.get(folder.toString(), subdirectory, moduleType.getFileName());
}

/**
* Получает путь к файлу прав роли для любого формата относительного базового каталога,
* и имени объекта
*
* @param configurationSource - формат данных, конфигуратор или EDT
* @param basePath - базовый каталог конфигурации
* @param mdoName - имя объекта метаданных, без расширения
* @return - путь к файлу прав конкретной роли
*/
public static Path getRoleDataPath(ConfigurationSource configurationSource, String basePath, String mdoName) {
Path path;
if (configurationSource == ConfigurationSource.EDT) {
path = Path.of(basePath, "Rights.rights");
} else {
path = Path.of(basePath, mdoName, "Ext", "Rights.xml");
}

return path;
}
}
Loading

0 comments on commit 404fced

Please sign in to comment.