Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.stream.Collectors;

Expand All @@ -54,12 +55,15 @@
import com._1c.g5.v8.dt.bm.index.rights.IRightsDescription;
import com._1c.g5.v8.dt.common.StringUtils;
import com._1c.g5.v8.dt.core.platform.IBmModelManager;
import com._1c.g5.v8.dt.core.platform.IExtensionProject;
import com._1c.g5.v8.dt.core.platform.IResourceLookup;
import com._1c.g5.v8.dt.core.platform.IV8Project;
import com._1c.g5.v8.dt.core.platform.IV8ProjectManager;
import com._1c.g5.v8.dt.mcore.NamedElement;
import com._1c.g5.v8.dt.md.MdUtil;
import com._1c.g5.v8.dt.metadata.mdclass.Configuration;
import com._1c.g5.v8.dt.metadata.mdclass.MdObject;
import com._1c.g5.v8.dt.metadata.mdclass.ObjectBelonging;
import com._1c.g5.v8.dt.metadata.mdclass.Role;
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
import com._1c.g5.v8.dt.rights.IRightInfosService;
Expand Down Expand Up @@ -164,13 +168,18 @@ protected void configureCheck(CheckConfigurer builder)
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
IProgressMonitor monitor)
{
if (!(object instanceof EObject eObject))
{
return;
}
IV8Project v8Project = v8ProjectManager.getProject(eObject);
if (object instanceof RoleDescription)
{
check((RoleDescription)object, resultAceptor, parameters, monitor);
check((RoleDescription)eObject, resultAceptor, parameters, v8Project, monitor);
}
else if (object instanceof ObjectRight)
{
check((ObjectRight)object, resultAceptor, parameters, monitor);
check((ObjectRight)eObject, resultAceptor, parameters, v8Project, monitor);
}
}

Expand All @@ -195,13 +204,13 @@ protected IBmModelManager getBmModelManager()
* Creates formated issue message for the right and the MD object.
*
* @param mdObject the MD object that has forbidden right, cannot be {@code null}.
* @param v8Project the v8-project, cannot be {@code null}
* @return the formatted issue message that right set for the object, cannot return {@code null}.
*/
protected String getIssueMessage(MdObject mdObject)
protected String getIssueMessage(MdObject mdObject, IV8Project v8Project)
{
IV8Project project = mdObject == null ? null : v8ProjectManager.getProject(mdObject);
String rightName = getRightName(project);
String mdObjectName = getMdObjectName(mdObject, project);
String rightName = getRightName(v8Project);
String mdObjectName = getMdObjectName(mdObject, v8Project);
return MessageFormat.format(Messages.RoleRightSetCheck_Role_right__0__set_for__1, rightName, mdObjectName);
}

Expand All @@ -216,7 +225,7 @@ protected boolean needCheckObjectRight()
}

private void check(RoleDescription object, ResultAcceptor resultAceptor, ICheckParameters parameters,
IProgressMonitor monitor)
IV8Project v8Project, IProgressMonitor monitor)
{
if (!object.isSetForNewObjects())
{
Expand All @@ -225,6 +234,9 @@ private void check(RoleDescription object, ResultAcceptor resultAceptor, ICheckP

Collection<MdObject> mdObjects = getDefaultObjectsWithRight(object, monitor);

IBmModel model = bmModelManager.getModel(object);
Role role = RightsModelUtil.getOwner(object, model);

List<ObjectRights> rights = object.getRights();
for (MdObject mdObject : mdObjects)
{
Expand All @@ -241,8 +253,12 @@ private void check(RoleDescription object, ResultAcceptor resultAceptor, ICheckP
continue;
}
}
String message = getIssueMessage(mdObject);
ObjectRights objectRights = RightsModelUtil.filterObjectRightsByEObject(mdObject, rights);
if (skipCheck(mdObject, v8Project, role, objectRights))
{
continue;
}
String message = getIssueMessage(mdObject, v8Project);
if (objectRights == null)
{
resultAceptor.addIssue(message, ROLE_DESCRIPTION__RIGHTS);
Expand All @@ -256,7 +272,7 @@ private void check(RoleDescription object, ResultAcceptor resultAceptor, ICheckP
}

private void check(ObjectRight object, ResultAcceptor resultAceptor, ICheckParameters parameters,
IProgressMonitor monitor)
IV8Project v8Project, IProgressMonitor monitor)
{
Right right = object.getRight();

Expand Down Expand Up @@ -296,7 +312,7 @@ private void check(ObjectRight object, ResultAcceptor resultAceptor, ICheckParam
}
}

String message = getIssueMessage(mdObject);
String message = getIssueMessage(mdObject, v8Project);
resultAceptor.addIssue(message, OBJECT_RIGHT__RIGHT);
}

Expand Down Expand Up @@ -429,6 +445,55 @@ private boolean hasRight(EClass eClass, EObject context)
return rightNames.contains(getRightName().getName());
}

private boolean skipCheck(MdObject mdObject, IV8Project v8Project, Role role,
ObjectRights objectRights)
{
// Role always 'Allow all except... ' (role.isSetForNewObjects() == true)
if (v8Project instanceof IExtensionProject extensionProject)
{
// Extension role cannot contain configuration rights.
if (mdObject instanceof Configuration)
{
return true;
}

Configuration extensionConfiguration = extensionProject.getConfiguration();
Set<Role> defaultRoles = Set.copyOf(extensionConfiguration.getDefaultRoles());
boolean isAdoptedObject = RightsModelUtil.isAdoptedMdObject(mdObject);

// Default native extension role cannot contain adopted object rights.
if (role.getObjectBelonging() == ObjectBelonging.NATIVE && defaultRoles.contains(role) && isAdoptedObject)
{
return true;
}

RightValue rightValue = null;
if (objectRights != null)
{
rightValue = objectRights.getRights()
.stream()
.filter(Objects::nonNull)
.filter(objectRight -> getRightName().getName().equals(objectRight.getRight().getName())
|| getRightName().getNameRu().equals(objectRight.getRight().getNameRu()))
.findFirst()
.map(ObjectRight::getValue)
.orElse(null);
}

if (rightValue == null)
{
rightValue = RightsModelUtil.getDefaultRightValue(mdObject, role);
}

if (!RightsModelUtil.getBooleanRightValue(rightValue))
{
return true;
}
}

return false;
}

/**
* This extension is combining all changes in containments of RoleDescription and schedule TOP object if needed.
* Also it reacts on adding or removing TOP MD-objects and schedule all role descriptions with SetForNewObjects.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*******************************************************************************
* Copyright (C) 2025, 1C-Soft LLC and others.
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Andrey Volkov - initial API and implementation
*******************************************************************************/
package com.e1c.v8codestyle.right.check.itests;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import org.eclipse.core.runtime.CoreException;
import org.junit.Test;

import com._1c.g5.v8.bm.core.IBmObject;
import com._1c.g5.v8.dt.core.platform.IDtProject;
import com._1c.g5.v8.dt.validation.marker.Marker;
import com.e1c.v8codestyle.internal.right.itests.CheckRights;
import com.e1c.v8codestyle.right.check.RoleRightSetCheck;

/**
* Tests for {@link RoleRightSetCheck} check.
*
* @author Andrey Volkov
*/
public class RoleRightSetCheckTest
extends CheckRights
{
@Test
public void testMainProjectRolesCorrect() throws Exception
{
IDtProject dtProject = openProjectAndWaitForValidationFinish("RoleRightSetCheckTest");
assertNotNull(dtProject);

checkMarkerCount(dtProject, "Role.Роль1AllowAll.Rights", 0);
checkMarkerCount(dtProject, "Role.Роль2DisableAll.Rights", 0);
}

@Test
public void testExtensionProjectRolesCorrect() throws Exception
{
IDtProject dtProject =
openProjectAndWaitForValidationFinish("RoleRightSetCheckTest.RoleRightSetCheckExtensionTest");
assertNotNull(dtProject);

checkMarkerCount(dtProject, "Role.Расш1_ОсновнаяРоль.Rights", 6);
checkMarkerCount(dtProject, "Role.Расш1_Роль1AllowAll.Rights", 0);
checkMarkerCount(dtProject, "Role.Расш1_Роль2DisableAll.Rights", 0);
checkMarkerCount(dtProject, "Role.Роль1AllowAll.Rights", 0);
checkMarkerCount(dtProject, "Role.Роль2DisableAll.Rights", 0);
}

private void checkMarkerCount(IDtProject dtProject, String roleDescriptionFqn, int markerCount) throws CoreException
{
IBmObject bmRoleDescription = getTopObjectByFqn(roleDescriptionFqn, dtProject);
assertNotNull(bmRoleDescription);

Object extractedMarkerContainerId = extractMarkerContainerId(bmRoleDescription.bmGetId());
Marker[] markers = markerManager.getMarkers(dtProject.getWorkspaceProject(), extractedMarkerContainerId);

assertTrue(markers.length == markerCount);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RoleRightSetCheckTest.RoleRightSetCheckExtensionTest</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
<nature>com._1c.g5.v8.dt.core.V8ExtensionNature</nature>
</natures>
</projectDescription>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
topObjects=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
addModuleStrictTypesAnnotation=false
createModuleStructure=false
eclipse.preferences.version=1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
commonChecks=true
eclipse.preferences.version=1
standardChecks=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Runtime-Version: 8.5.1
Base-Project: RoleRightSetCheckTest
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:Catalog xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" xmlns:mdclassExtension="http://g5.1c.ru/v8/dt/metadata/mdclass/extension" uuid="27f4a355-000a-433a-baa0-58c5b47959ec" extendedConfigurationObject="46d1a1c3-6ac8-47a9-ac0c-018c51269269">
<producedTypes>
<objectType typeId="9f63adc1-393f-4345-bbf4-f4f84aa140f7" valueTypeId="9f076cd8-1014-4662-b961-b618140ff3ab"/>
<refType typeId="5a905cf9-bf94-4af6-b4c7-fbbe506bfee8" valueTypeId="f41701af-0fe4-4378-abbf-2979fbe51f1c"/>
<selectionType typeId="b16ad2c1-a621-4237-a1a2-786bf7f05c56" valueTypeId="16643fd6-9c5c-4256-aaf3-60fb128a4bb9"/>
<listType typeId="009f970c-6226-4c6d-be7a-c76d4143523a" valueTypeId="13b826ff-90d0-48c1-9e90-ecc8249fbaa2"/>
<managerType typeId="fb5586fe-5683-495b-aa8c-9a1d3b5fc0ba" valueTypeId="48afaec7-d940-4fc3-8801-fa74497f68e9"/>
</producedTypes>
<name>MainCatalog1</name>
<objectBelonging>Adopted</objectBelonging>
<extension xsi:type="mdclassExtension:CatalogExtension">
<extendedConfigurationObject>Checked</extendedConfigurationObject>
</extension>
<useStandardCommands>true</useStandardCommands>
<checkUnique>true</checkUnique>
</mdclass:Catalog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:Catalog xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="ecc774ee-5c25-4d4e-a1b7-51d8edfa3bc7">
<producedTypes>
<objectType typeId="c662ee6f-1c75-4d0c-8d30-f3e3a9a05520" valueTypeId="917d3818-a86e-4ba8-8b01-1b0a15371ffa"/>
<refType typeId="d4532488-ac75-4006-b4f1-42e2758b75d2" valueTypeId="cfae989e-d787-474d-9634-85bba48381ab"/>
<selectionType typeId="388bc769-c456-469e-9a34-5f537ec15516" valueTypeId="97f83a60-12ec-4881-8af4-c5e94d059d7f"/>
<listType typeId="ede8b06c-3a3d-4fde-a1aa-78adc1d7bd51" valueTypeId="7ad61f70-3188-463b-bbaf-ecd42d7171ce"/>
<managerType typeId="357dc744-0ab4-4c5e-9fba-e882fd3154fa" valueTypeId="4ac2a988-6d6a-4636-a875-e2d739b66d4c"/>
</producedTypes>
<name>Расш1_Справочник2</name>
<synonym>
<key>ru</key>
<value>Справочник2</value>
</synonym>
<useStandardCommands>true</useStandardCommands>
<inputByString>Catalog.Расш1_Справочник2.StandardAttribute.Code</inputByString>
<inputByString>Catalog.Расш1_Справочник2.StandardAttribute.Description</inputByString>
<fullTextSearchOnInputByString>DontUse</fullTextSearchOnInputByString>
<createOnInput>Use</createOnInput>
<fullTextSearch>Use</fullTextSearch>
<objectPresentation>
<key>ru</key>
<value>Расш1_Справочник2</value>
</objectPresentation>
<levelCount>2</levelCount>
<foldersOnTop>true</foldersOnTop>
<codeLength>9</codeLength>
<descriptionLength>25</descriptionLength>
<codeType>String</codeType>
<codeAllowedLength>Variable</codeAllowedLength>
<checkUnique>true</checkUnique>
<autonumbering>true</autonumbering>
<defaultPresentation>AsDescription</defaultPresentation>
<editType>InDialog</editType>
<choiceMode>BothWays</choiceMode>
</mdclass:Catalog>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<cmi:CommandInterface xmlns:cmi="http://g5.1c.ru/v8/dt/cmi"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:Configuration xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" xmlns:mdclassExtension="http://g5.1c.ru/v8/dt/metadata/mdclass/extension" uuid="24876c18-25a8-48c3-a78d-444012ad00c8">
<name>RoleRightSetCheckExtensionTest</name>
<synonym>
<key>ru</key>
<value>Role right set check extension test</value>
</synonym>
<objectBelonging>Adopted</objectBelonging>
<extension xsi:type="mdclassExtension:ConfigurationExtension">
<defaultRunMode>Checked</defaultRunMode>
<usePurposes>Checked</usePurposes>
<commandInterface>Extended</commandInterface>
<mainSectionCommandInterface>Extended</mainSectionCommandInterface>
<defaultLanguage>Checked</defaultLanguage>
<interfaceCompatibilityMode>Checked</interfaceCompatibilityMode>
<compatibilityMode>Checked</compatibilityMode>
<defaultStyle>Extended</defaultStyle>
<defaultRoles>Extended</defaultRoles>
</extension>
<containedObjects classId="9cd510cd-abfc-11d4-9434-004095e12fc7" objectId="22a6d2f8-97ab-4c17-aad5-25f33ba1be7b"/>
<containedObjects classId="9fcd25a0-4822-11d4-9414-008048da11f9" objectId="b8e507d3-51f9-4335-a795-3e5d919f4816"/>
<containedObjects classId="e3687481-0a87-462c-a166-9f34594f9bba" objectId="39e2123c-7648-4618-acf1-4cd928747cc5"/>
<containedObjects classId="9de14907-ec23-4a07-96f0-85521cb6b53b" objectId="75bbcada-b272-4165-82e9-00249200efe0"/>
<containedObjects classId="51f2d5d8-ea4d-4064-8892-82951750031e" objectId="8f512a86-1ca6-41bc-93e0-34201815227c"/>
<containedObjects classId="e68182ea-4237-4383-967f-90c1e3370bc7" objectId="b801de59-5310-48d9-ab46-de7ff4d99ecc"/>
<containedObjects classId="fb282519-d103-4dd3-bc12-cb271d631dfc" objectId="540a2fe3-933f-4b67-821d-d78f9b8a4ce2"/>
<keepMappingToExtendedConfigurationObjectsByIDs>true</keepMappingToExtendedConfigurationObjectsByIDs>
<namePrefix>Расш1_</namePrefix>
<configurationExtensionCompatibilityMode>8.5.1</configurationExtensionCompatibilityMode>
<configurationExtensionPurpose>Customization</configurationExtensionPurpose>
<defaultRunMode>ManagedApplication</defaultRunMode>
<usePurposes>PersonalComputer</usePurposes>
<scriptVariant>Russian</scriptVariant>
<defaultRoles>Role.Расш1_ОсновнаяРоль</defaultRoles>
<defaultLanguage>Language.Русский</defaultLanguage>
<compatibilityMode>8.5.1</compatibilityMode>
<languages uuid="62ab7f89-11ea-4f32-b505-b1e5013908ad" extendedConfigurationObject="d46adc3f-7518-45d7-88fe-477752c605b7">
<name>Русский</name>
<objectBelonging>Adopted</objectBelonging>
<extension xsi:type="mdclassExtension:LanguageExtension">
<extendedConfigurationObject>Checked</extendedConfigurationObject>
<languageCode>Checked</languageCode>
</extension>
<languageCode>ru</languageCode>
</languages>
<roles>Role.Расш1_ОсновнаяРоль</roles>
<roles>Role.Расш1_Роль1AllowAll</roles>
<roles>Role.Расш1_Роль2DisableAll</roles>
<roles>Role.Роль1AllowAll</roles>
<roles>Role.Роль2DisableAll</roles>
<catalogs>Catalog.MainCatalog1</catalogs>
<catalogs>Catalog.Расш1_Справочник2</catalogs>
</mdclass:Configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<cmi:CommandInterface xmlns:cmi="http://g5.1c.ru/v8/dt/cmi"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Rights xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://v8.1c.ru/8.2/roles" xsi:type="Rights">
<setForNewObjects>true</setForNewObjects>
<setForAttributesByDefault>true</setForAttributesByDefault>
<independentRightsOfChildObjects>false</independentRightsOfChildObjects>
</Rights>
Loading
Loading