Skip to content

#701 Отсутствует обязательная роль #1484

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#### Метаданные

- Превышена максимальная длина числовых данных (31 знак). #82

- Отсутствует обязательная роль #701

#### Формы

Expand Down
14 changes: 14 additions & 0 deletions bundles/com.e1c.v8codestyle.md/markdown/role-missing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Required role missing

In configuration should be declared three required roles:
1. FullAccess
2. SystemAdministrator
3. InteractiveOpenExternalReportsAndDataProcessors


## Noncompliant Code Example

## Compliant Solution

## See

15 changes: 15 additions & 0 deletions bundles/com.e1c.v8codestyle.md/markdown/ru/role-missing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Отсутствует обязательная роль

В конфигурации должны быть определены три обязательные роли:
1. ПолныеПрава
2. АдминистраторСистемы
3. ИнтерактивноеОткрытиеВнешнихОтчетовИОбработок


## Неправильно

## Правильно

## См.

[Стандартные роли](https://its.1c.ru/db/v8std#content:488:hdoc:2)
4 changes: 4 additions & 0 deletions bundles/com.e1c.v8codestyle.md/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@
category="com.e1c.v8codestyle.md"
class="com.e1c.v8codestyle.md.functionoption.check.FunctionalOptionPrivilegedGetModeCheck">
</check>
<check
category="com.e1c.v8codestyle.md"
class="com.e1c.v8codestyle.md.role.check.RoleMissingCheck">
</check>
</extension>

</plugin>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*******************************************************************************
* 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:
* 1C-Soft LLC - initial API and implementation
*******************************************************************************/
package com.e1c.v8codestyle.md.role.check;

import org.eclipse.osgi.util.NLS;

/**
* @author Aleksey Kalugin
*
*/
final class Messages
extends NLS
{
private static final String BUNDLE_NAME = Messages.class.getPackageName() + ".messages"; //$NON-NLS-1$

public static String RoleMissing_description;
public static String RoleMissing_message;
public static String RoleMissing_title;

static
{
// initialize resource bundle
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
}

private Messages()
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*******************************************************************************
* 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:
* 1C-Soft LLC - initial API and implementation
*******************************************************************************/
package com.e1c.v8codestyle.md.role.check;

import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION;
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION__ROLES;
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION__SCRIPT_VARIANT;
import static java.util.Map.entry;

import java.text.MessageFormat;
import java.util.List;
import java.util.Map;

import org.eclipse.core.runtime.IProgressMonitor;

import com._1c.g5.v8.dt.metadata.mdclass.Configuration;
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
import com.e1c.g5.v8.dt.check.CheckComplexity;
import com.e1c.g5.v8.dt.check.ICheckParameters;
import com.e1c.g5.v8.dt.check.components.BasicCheck;
import com.e1c.g5.v8.dt.check.components.TopObjectFilterExtension;
import com.e1c.g5.v8.dt.check.settings.IssueSeverity;
import com.e1c.g5.v8.dt.check.settings.IssueType;
import com.e1c.v8codestyle.check.StandardCheckExtension;
import com.e1c.v8codestyle.internal.md.CorePlugin;
import com.e1c.v8codestyle.md.check.SkipAdoptedInExtensionMdObjectExtension;

/**
* The check that the configuration has required roles.
*
* @author Aleksey Kalugin
*
*/
public class RoleMissingCheck
extends BasicCheck<Object>
{
private static final String CHECK_ID = "role-missing"; //$NON-NLS-1$

//@formatter:off
private static final Map<ScriptVariant, List<String>> ROLE_NAMES = Map.ofEntries(
entry(ScriptVariant.ENGLISH,
List.of("FullAccess", "SystemAdministrator", "InteractiveOpenExternalReportsAndDataProcessors")), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
entry(ScriptVariant.RUSSIAN,
List.of("ПолныеПрава", "АдминистраторСистемы", "ИнтерактивноеОткрытиеВнешнихОтчетовИОбработок")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
);
//@formatter:on

@Override
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
IProgressMonitor monitor)
{
if (monitor.isCanceled() || !(object instanceof Configuration))
{
return;
}

var configuration = (Configuration)object;
var roles = configuration.getRoles();
for (var roleName : ROLE_NAMES.get(configuration.getScriptVariant()))
{
if (monitor.isCanceled()) {
return;
}

if (roles.stream().noneMatch(role -> roleName.equals(role.getName())))
{
resultAceptor.addIssue(
MessageFormat.format(Messages.RoleMissing_message, roleName),
CONFIGURATION__ROLES);
}
}
}

@Override
public String getCheckId()
{
return CHECK_ID;
}

@Override
protected void configureCheck(CheckConfigurer builder)
{
builder.title(Messages.RoleMissing_title)
.description(Messages.RoleMissing_description)
.complexity(CheckComplexity.NORMAL)
.severity(IssueSeverity.TRIVIAL)
.issueType(IssueType.WARNING)
.extension(new TopObjectFilterExtension())
.extension(new StandardCheckExtension(488, getCheckId(), CorePlugin.PLUGIN_ID))
.extension(new SkipAdoptedInExtensionMdObjectExtension())
.topObject(CONFIGURATION)
.checkTop()
.features(CONFIGURATION__SCRIPT_VARIANT, CONFIGURATION__ROLES);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

RoleMissing_description = Required role is missing
RoleMissing_message = Required role "{0}" is missing
RoleMissing_title = Role is missing
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)

RoleMissing_description = Отсутствует обязательная роль
RoleMissing_message = Отсутствует обязательная роль "{0}"
RoleMissing_title = Отсутствует роль
2 changes: 1 addition & 1 deletion bundles/com.e1c.v8codestyle/plugin.launch
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<stringAttribute key="org.eclipse.jdt.launching.JRE_CONTAINER" value="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17"/>
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -clean"/>
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx6G&#13;&#10;-Dlog4j.configuration=platform:/plugin/com._1c.g5.v8.dt.logging/log4j.properties&#13;&#10;-DmigrationEnabled=true&#13;&#10;-DmigrationNotificationEnabled=true&#10;-Dosgi.framework.extensions=org.eclipse.fx.osgi&#13;&#10;-De1c.dt.monitoring.host="/>
<stringAttribute key="org.eclipse.jdt.launching.VM_ARGUMENTS" value="-Xmx6G&#13;&#10;-Dlog4j.configuration=platform:/plugin/com._1c.g5.v8.dt.logging/log4j.properties&#13;&#10;-DmigrationEnabled=true&#13;&#10;-DmigrationNotificationEnabled=true&#10;-Dosgi.framework.extensions=org.eclipse.fx.osgi&#13;&#10;-De1c.dt.monitoring.host=&#13;&#10;-Dosgi.requiredJavaVersion=17&#13;&#10;--add-modules=ALL-SYSTEM&#13;&#10;--add-opens=java.base/java.lang.constant=ALL-UNNAMED&#13;&#10;--add-opens=java.base/java.lang=ALL-UNNAMED&#13;&#10;--add-opens=java.base/java.lang.ref=ALL-UNNAMED&#13;&#10;--add-opens=java.base/java.nio=ALL-UNNAMED&#13;&#10;--add-opens=java.base/java.time=ALL-UNNAMED&#13;&#10;--add-opens=java.base/sun.nio.ch=ALL-UNNAMED&#13;&#10;--add-opens=java.base/java.net=ALL-UNNAMED"/>
<stringAttribute key="pde.version" value="3.3"/>
<stringAttribute key="product" value="com._1c.g5.v8.dt.product.application.rcp"/>
<booleanAttribute key="show_selected_only" value="false"/>
Expand Down
2 changes: 1 addition & 1 deletion docs/.settings/org.eclipse.jdt.groovy.core.prefs
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
eclipse.preferences.version=1
groovy.compiler.level=30
groovy.compiler.level=40
1 change: 1 addition & 0 deletions docs/checks/md.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
| [scheduled-job-periodicity-too-short](../../bundles/com.e1c.v8codestyle.md/markdown/ru/scheduled-job-periodicity-too-short.md) | Периодичность выполнения регламентного задания меньше одной минуты. |
| [subsystem-synonym-too-long](../../bundles/com.e1c.v8codestyle.md/markdown/ru/subsystem-synonym-too-long.md) | Длина названия раздела превышает 35 символов |
| [unsafe-password-ib-storage](../../bundles/com.e1c.v8codestyle.md/markdown/ru/unsafe-password-ib-storage.md) | Небезопасное хранение паролей в информационной базе |
| [role-missing](../../bundles/com.e1c.v8codestyle.md/markdown/ru/role-missing.md) | Отсутствует обязательная роль |
2 changes: 1 addition & 1 deletion docs/contributing/environment.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
- `ResourceBundle Editor` - редактирование интерфейсных локализируемых файлов `*.properties` на нескольких языках
- `Enhanced Class Decompiler` - удобный просмотр классов без исходного кода
- `LiClipseText` - редактор поддерживающий множество синтаксиса, например Markdown
- `EclEmma Java Code Covarage` - Запуск тестов со снятием покрытия кода
- `EclEmma Java Code Coverage` - Запуск тестов со снятием покрытия кода
- `PDE Source Lookup` - Автоматическая подгрузка исходников для бандлов из целевой платформы из открытых источников

## Настройки JDT и проекта
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*******************************************************************************
* 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:
* 1C-Soft LLC - initial API and implementation
*******************************************************************************/
package com.e1c.v8codestyle.md.role.check.itests;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;

import java.util.Collections;

import org.junit.Test;

import com._1c.g5.v8.dt.core.platform.IDtProject;
import com._1c.g5.v8.dt.validation.marker.Marker;
import com.e1c.g5.v8.dt.testing.check.CheckTestBase;
import com.e1c.v8codestyle.md.role.check.RoleMissingCheck;

/**
* The test for class {@link RoleMissingCheck}.
*
* @author Aleksey Kalugin
*
*/
public class RoleMissingCheckTest
extends CheckTestBase
{
private static final String CHECK_ID = "role-missing"; //$NON-NLS-1$

private static final String PROJECT_NAME_ROLES_MISSING = "RoleMissingCheck";
private static final String PROJECT_NAME_ROLES_EXIST = "RoleMissingCheck_RolesExist";

/**
* Test configuration doesn't have required roles.
*
* @throws Exception the exception
*/
@Test
public void testRolesMissing() throws Exception
{
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME_ROLES_MISSING);
assertNotNull(dtProject);

var configuration = getTopObjectByFqn("Configuration", dtProject);
var markers = getMarkersByCheckIds(Collections.singleton(CHECK_ID), configuration, dtProject);

assertEquals(3, markers.size());
}

/**
* Test configuration has required roles.
*
* @throws Exception the exception
*/
@Test
public void testRolesExist() throws Exception
{
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME_ROLES_EXIST);
assertNotNull(dtProject);

long id = getTopObjectIdByFqn("Configuration", dtProject);
Marker marker = getFirstMarker(CHECK_ID, id, dtProject);
assertNull(marker);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>RoleMissingCheck</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.V8ConfigurationNature</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,2 @@
Manifest-Version: 1.0
Runtime-Version: 8.3.19
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,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<mdclass:Configuration xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="d17dd2ba-20c0-451c-8678-3e726ab3be52">
<name>RoleMissingCheck</name>
<synonym>
<key>en</key>
<value>Role missing check</value>
</synonym>
<containedObjects classId="9cd510cd-abfc-11d4-9434-004095e12fc7" objectId="4dc745b5-c56e-435d-955a-14b4e45407dc"/>
<containedObjects classId="9fcd25a0-4822-11d4-9414-008048da11f9" objectId="7f08df2b-4cd2-4449-8cab-07b21414a95a"/>
<containedObjects classId="e3687481-0a87-462c-a166-9f34594f9bba" objectId="cff1d624-2a0e-4b53-9e87-ca41ed6b9276"/>
<containedObjects classId="9de14907-ec23-4a07-96f0-85521cb6b53b" objectId="bb9c0acb-f58e-41d3-8be3-b1dd9a343fd4"/>
<containedObjects classId="51f2d5d8-ea4d-4064-8892-82951750031e" objectId="9e2ab934-03cc-423d-a705-fa35900b9aec"/>
<containedObjects classId="e68182ea-4237-4383-967f-90c1e3370bc7" objectId="8c4612c2-4f69-426c-aafd-0892d6b1c559"/>
<containedObjects classId="fb282519-d103-4dd3-bc12-cb271d631dfc" objectId="c25dca65-7e43-4f90-9f27-3462e05ef3d8"/>
<configurationExtensionCompatibilityMode>8.3.19</configurationExtensionCompatibilityMode>
<defaultRunMode>ManagedApplication</defaultRunMode>
<usePurposes>PersonalComputer</usePurposes>
<usedMobileApplicationFunctionalities>
<functionality>
<use>true</use>
</functionality>
<functionality>
<functionality>OSBackup</functionality>
<use>true</use>
</functionality>
</usedMobileApplicationFunctionalities>
<defaultLanguage>Language.English</defaultLanguage>
<dataLockControlMode>Managed</dataLockControlMode>
<objectAutonumerationMode>NotAutoFree</objectAutonumerationMode>
<modalityUseMode>DontUse</modalityUseMode>
<synchronousPlatformExtensionAndAddInCallUseMode>DontUse</synchronousPlatformExtensionAndAddInCallUseMode>
<compatibilityMode>8.3.19</compatibilityMode>
<languages uuid="05f6bcf5-ba46-44f2-8e01-e85b253ab8cc">
<name>English</name>
<synonym>
<key>en</key>
<value>English</value>
</synonym>
<languageCode>en</languageCode>
</languages>
</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"/>
Loading