Skip to content

Commit 9f84f3e

Browse files
committed
1C-Company#701 Отсутствует обязательная роль
Добавлена новая проверка метаданных role-missing
1 parent 1f43436 commit 9f84f3e

37 files changed

+585
-4
lines changed

CHANGELOG.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#### Метаданные
1313

1414
- Превышена максимальная длина числовых данных (31 знак). #82
15-
15+
- Отсутствует обязательная роль #701
1616

1717
#### Формы
1818

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Required role missing
2+
3+
In configuration should be declared three required roles:
4+
1. FullAccess
5+
2. SystemAdministrator
6+
3. InteractiveOpenExternalReportsAndDataProcessors
7+
8+
9+
## Noncompliant Code Example
10+
11+
## Compliant Solution
12+
13+
## See
14+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Отсутствует обязательная роль
2+
3+
В конфигурации должны быть определены три обязательные роли:
4+
1. ПолныеПрава
5+
2. АдминистраторСистемы
6+
3. ИнтерактивноеОткрытиеВнешнихОтчетовИОбработок
7+
8+
9+
## Неправильно
10+
11+
## Правильно
12+
13+
## См.
14+
15+
[Стандартные роли](https://its.1c.ru/db/v8std#content:488:hdoc:2)

bundles/com.e1c.v8codestyle.md/plugin.xml

+4
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@
134134
category="com.e1c.v8codestyle.md"
135135
class="com.e1c.v8codestyle.md.functionoption.check.FunctionalOptionPrivilegedGetModeCheck">
136136
</check>
137+
<check
138+
category="com.e1c.v8codestyle.md"
139+
class="com.e1c.v8codestyle.md.role.check.RoleMissingCheck">
140+
</check>
137141
</extension>
138142

139143
</plugin>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2025, 1C-Soft LLC and others.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* 1C-Soft LLC - initial API and implementation
12+
*******************************************************************************/
13+
package com.e1c.v8codestyle.md.role.check;
14+
15+
import org.eclipse.osgi.util.NLS;
16+
17+
/**
18+
* @author Aleksey Kalugin
19+
*
20+
*/
21+
final class Messages
22+
extends NLS
23+
{
24+
private static final String BUNDLE_NAME = Messages.class.getPackageName() + ".messages"; //$NON-NLS-1$
25+
26+
public static String RoleMissing_description;
27+
public static String RoleMissing_message;
28+
public static String RoleMissing_title;
29+
30+
static
31+
{
32+
// initialize resource bundle
33+
NLS.initializeMessages(BUNDLE_NAME, Messages.class);
34+
}
35+
36+
private Messages()
37+
{
38+
}
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2025, 1C-Soft LLC and others.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* 1C-Soft LLC - initial API and implementation
12+
*******************************************************************************/
13+
package com.e1c.v8codestyle.md.role.check;
14+
15+
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION;
16+
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION__ROLES;
17+
import static com._1c.g5.v8.dt.metadata.mdclass.MdClassPackage.Literals.CONFIGURATION__SCRIPT_VARIANT;
18+
import static java.util.Map.entry;
19+
20+
import java.text.MessageFormat;
21+
import java.util.List;
22+
import java.util.Map;
23+
24+
import org.eclipse.core.runtime.IProgressMonitor;
25+
26+
import com._1c.g5.v8.dt.metadata.mdclass.Configuration;
27+
import com._1c.g5.v8.dt.metadata.mdclass.ScriptVariant;
28+
import com.e1c.g5.v8.dt.check.CheckComplexity;
29+
import com.e1c.g5.v8.dt.check.ICheckParameters;
30+
import com.e1c.g5.v8.dt.check.components.BasicCheck;
31+
import com.e1c.g5.v8.dt.check.components.TopObjectFilterExtension;
32+
import com.e1c.g5.v8.dt.check.settings.IssueSeverity;
33+
import com.e1c.g5.v8.dt.check.settings.IssueType;
34+
import com.e1c.v8codestyle.check.StandardCheckExtension;
35+
import com.e1c.v8codestyle.internal.md.CorePlugin;
36+
import com.e1c.v8codestyle.md.check.SkipAdoptedInExtensionMdObjectExtension;
37+
38+
/**
39+
* The check that the configuration has required roles.
40+
*
41+
* @author Aleksey Kalugin
42+
*
43+
*/
44+
public class RoleMissingCheck
45+
extends BasicCheck<Object>
46+
{
47+
private static final String CHECK_ID = "role-missing"; //$NON-NLS-1$
48+
49+
//@formatter:off
50+
private static final Map<ScriptVariant, List<String>> ROLE_NAMES = Map.ofEntries(
51+
entry(ScriptVariant.ENGLISH,
52+
List.of("FullAccess", "SystemAdministrator", "InteractiveOpenExternalReportsAndDataProcessors")), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
53+
entry(ScriptVariant.RUSSIAN,
54+
List.of("ПолныеПрава", "АдминистраторСистемы", "ИнтерактивноеОткрытиеВнешнихОтчетовИОбработок")) //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
55+
);
56+
//@formatter:on
57+
58+
@Override
59+
protected void check(Object object, ResultAcceptor resultAceptor, ICheckParameters parameters,
60+
IProgressMonitor monitor)
61+
{
62+
if (monitor.isCanceled() || !(object instanceof Configuration))
63+
{
64+
return;
65+
}
66+
67+
var configuration = (Configuration)object;
68+
var roles = configuration.getRoles();
69+
for (var roleName : ROLE_NAMES.get(configuration.getScriptVariant()))
70+
{
71+
if (monitor.isCanceled()) {
72+
return;
73+
}
74+
75+
if (roles.stream().noneMatch(role -> roleName.equals(role.getName())))
76+
{
77+
resultAceptor.addIssue(
78+
MessageFormat.format(Messages.RoleMissing_message, roleName),
79+
CONFIGURATION__ROLES);
80+
}
81+
}
82+
}
83+
84+
@Override
85+
public String getCheckId()
86+
{
87+
return CHECK_ID;
88+
}
89+
90+
@Override
91+
protected void configureCheck(CheckConfigurer builder)
92+
{
93+
builder.title(Messages.RoleMissing_title)
94+
.description(Messages.RoleMissing_description)
95+
.complexity(CheckComplexity.NORMAL)
96+
.severity(IssueSeverity.TRIVIAL)
97+
.issueType(IssueType.WARNING)
98+
.extension(new TopObjectFilterExtension())
99+
.extension(new StandardCheckExtension(488, getCheckId(), CorePlugin.PLUGIN_ID))
100+
.extension(new SkipAdoptedInExtensionMdObjectExtension())
101+
.topObject(CONFIGURATION)
102+
.checkTop()
103+
.features(CONFIGURATION__SCRIPT_VARIANT, CONFIGURATION__ROLES);
104+
}
105+
106+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
RoleMissing_description = Required role is missing
3+
RoleMissing_message = Required role "{0}" is missing
4+
RoleMissing_title = Role is missing
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#Generated by ResourceBundle Editor (http://essiembre.github.io/eclipse-rbe/)
2+
3+
RoleMissing_description = Отсутствует обязательная роль
4+
RoleMissing_message = Отсутствует обязательная роль "{0}"
5+
RoleMissing_title = Отсутствует роль

bundles/com.e1c.v8codestyle/plugin.launch

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<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"/>
2424
<stringAttribute key="org.eclipse.jdt.launching.PROGRAM_ARGUMENTS" value="-os ${target.os} -ws ${target.ws} -arch ${target.arch} -nl ${target.nl} -consoleLog -clean"/>
2525
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.pde.ui.workbenchClasspathProvider"/>
26-
<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="/>
26+
<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"/>
2727
<stringAttribute key="pde.version" value="3.3"/>
2828
<stringAttribute key="product" value="com._1c.g5.v8.dt.product.application.rcp"/>
2929
<booleanAttribute key="show_selected_only" value="false"/>
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
eclipse.preferences.version=1
2-
groovy.compiler.level=30
2+
groovy.compiler.level=40

docs/checks/md.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,4 @@
3232
| [scheduled-job-periodicity-too-short](../../bundles/com.e1c.v8codestyle.md/markdown/ru/scheduled-job-periodicity-too-short.md) | Периодичность выполнения регламентного задания меньше одной минуты. |
3333
| [subsystem-synonym-too-long](../../bundles/com.e1c.v8codestyle.md/markdown/ru/subsystem-synonym-too-long.md) | Длина названия раздела превышает 35 символов |
3434
| [unsafe-password-ib-storage](../../bundles/com.e1c.v8codestyle.md/markdown/ru/unsafe-password-ib-storage.md) | Небезопасное хранение паролей в информационной базе |
35+
| [role-missing](../../bundles/com.e1c.v8codestyle.md/markdown/ru/role-missing.md) | Отсутствует обязательная роль |

docs/contributing/environment.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
- `ResourceBundle Editor` - редактирование интерфейсных локализируемых файлов `*.properties` на нескольких языках
1414
- `Enhanced Class Decompiler` - удобный просмотр классов без исходного кода
1515
- `LiClipseText` - редактор поддерживающий множество синтаксиса, например Markdown
16-
- `EclEmma Java Code Covarage` - Запуск тестов со снятием покрытия кода
16+
- `EclEmma Java Code Coverage` - Запуск тестов со снятием покрытия кода
1717
- `PDE Source Lookup` - Автоматическая подгрузка исходников для бандлов из целевой платформы из открытых источников
1818

1919
## Настройки JDT и проекта
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*******************************************************************************
2+
* Copyright (C) 2025, 1C-Soft LLC and others.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* 1C-Soft LLC - initial API and implementation
12+
*******************************************************************************/
13+
package com.e1c.v8codestyle.md.role.check.itests;
14+
15+
import static org.junit.Assert.assertEquals;
16+
import static org.junit.Assert.assertNotNull;
17+
import static org.junit.Assert.assertNull;
18+
19+
import java.util.Arrays;
20+
21+
import org.junit.Test;
22+
23+
import com._1c.g5.v8.dt.core.platform.IDtProject;
24+
import com._1c.g5.v8.dt.validation.marker.Marker;
25+
import com.e1c.g5.v8.dt.testing.check.CheckTestBase;
26+
import com.e1c.v8codestyle.md.role.check.RoleMissingCheck;
27+
28+
/**
29+
* The test for class {@link RoleMissingCheck}.
30+
*
31+
* @author Aleksey Kalugin
32+
*
33+
*/
34+
public class RoleMissingCheckTest
35+
extends CheckTestBase
36+
{
37+
private static final String CHECK_ID = "role-missing"; //$NON-NLS-1$
38+
39+
private static final String PROJECT_NAME_ROLES_MISSING = "RoleMissingCheck";
40+
private static final String PROJECT_NAME_ROLES_EXIST = "RoleMissingCheck_RolesExist";
41+
42+
/**
43+
* Test configuration doesn't have required roles.
44+
*
45+
* @throws Exception the exception
46+
*/
47+
@Test
48+
public void testRolesMissing() throws Exception
49+
{
50+
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME_ROLES_MISSING);
51+
assertNotNull(dtProject);
52+
53+
var project = dtProject.getWorkspaceProject();
54+
assertNotNull(project);
55+
56+
Long id = getTopObjectIdByFqn("Configuration", dtProject);
57+
58+
var markerCount = Arrays.stream(markerManager.getMarkers(project, id))
59+
.filter(marker -> id.equals(marker.getSourceObjectId())
60+
&& CHECK_ID.equals(getCheckIdFromMarker(marker, dtProject)))
61+
.count();
62+
63+
assertEquals(3, markerCount);
64+
}
65+
66+
/**
67+
* Test configuration has required roles.
68+
*
69+
* @throws Exception the exception
70+
*/
71+
@Test
72+
public void testRolesExist() throws Exception
73+
{
74+
IDtProject dtProject = openProjectAndWaitForValidationFinish(PROJECT_NAME_ROLES_EXIST);
75+
assertNotNull(dtProject);
76+
77+
long id = getTopObjectIdByFqn("Configuration", dtProject);
78+
Marker marker = getFirstMarker(CHECK_ID, id, dtProject);
79+
assertNull(marker);
80+
}
81+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>RoleMissingCheck</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
16+
<nature>com._1c.g5.v8.dt.core.V8ConfigurationNature</nature>
17+
</natures>
18+
</projectDescription>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
topObjects=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
addModuleStrictTypesAnnotation=false
2+
createModuleStructure=false
3+
eclipse.preferences.version=1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
commonChecks=true
2+
eclipse.preferences.version=1
3+
standardChecks=true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
eclipse.preferences.version=1
2+
encoding/<project>=UTF-8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Manifest-Version: 1.0
2+
Runtime-Version: 8.3.19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<cmi:CommandInterface xmlns:cmi="http://g5.1c.ru/v8/dt/cmi"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<mdclass:Configuration xmlns:mdclass="http://g5.1c.ru/v8/dt/metadata/mdclass" uuid="d17dd2ba-20c0-451c-8678-3e726ab3be52">
3+
<name>RoleMissingCheck</name>
4+
<synonym>
5+
<key>en</key>
6+
<value>Role missing check</value>
7+
</synonym>
8+
<containedObjects classId="9cd510cd-abfc-11d4-9434-004095e12fc7" objectId="4dc745b5-c56e-435d-955a-14b4e45407dc"/>
9+
<containedObjects classId="9fcd25a0-4822-11d4-9414-008048da11f9" objectId="7f08df2b-4cd2-4449-8cab-07b21414a95a"/>
10+
<containedObjects classId="e3687481-0a87-462c-a166-9f34594f9bba" objectId="cff1d624-2a0e-4b53-9e87-ca41ed6b9276"/>
11+
<containedObjects classId="9de14907-ec23-4a07-96f0-85521cb6b53b" objectId="bb9c0acb-f58e-41d3-8be3-b1dd9a343fd4"/>
12+
<containedObjects classId="51f2d5d8-ea4d-4064-8892-82951750031e" objectId="9e2ab934-03cc-423d-a705-fa35900b9aec"/>
13+
<containedObjects classId="e68182ea-4237-4383-967f-90c1e3370bc7" objectId="8c4612c2-4f69-426c-aafd-0892d6b1c559"/>
14+
<containedObjects classId="fb282519-d103-4dd3-bc12-cb271d631dfc" objectId="c25dca65-7e43-4f90-9f27-3462e05ef3d8"/>
15+
<configurationExtensionCompatibilityMode>8.3.19</configurationExtensionCompatibilityMode>
16+
<defaultRunMode>ManagedApplication</defaultRunMode>
17+
<usePurposes>PersonalComputer</usePurposes>
18+
<usedMobileApplicationFunctionalities>
19+
<functionality>
20+
<use>true</use>
21+
</functionality>
22+
<functionality>
23+
<functionality>OSBackup</functionality>
24+
<use>true</use>
25+
</functionality>
26+
</usedMobileApplicationFunctionalities>
27+
<defaultLanguage>Language.English</defaultLanguage>
28+
<dataLockControlMode>Managed</dataLockControlMode>
29+
<objectAutonumerationMode>NotAutoFree</objectAutonumerationMode>
30+
<modalityUseMode>DontUse</modalityUseMode>
31+
<synchronousPlatformExtensionAndAddInCallUseMode>DontUse</synchronousPlatformExtensionAndAddInCallUseMode>
32+
<compatibilityMode>8.3.19</compatibilityMode>
33+
<languages uuid="05f6bcf5-ba46-44f2-8e01-e85b253ab8cc">
34+
<name>English</name>
35+
<synonym>
36+
<key>en</key>
37+
<value>English</value>
38+
</synonym>
39+
<languageCode>en</languageCode>
40+
</languages>
41+
</mdclass:Configuration>

0 commit comments

Comments
 (0)