-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
84 changed files
with
5,093 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>ch.sbb.polarion.extensions.interceptor-hooks</groupId> | ||
<artifactId>ch.sbb.polarion.extension.interceptor-hooks.only-assignee-can-delete</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<ch.sbb.polarion.extension.interceptor.version>1.0.0-SNAPSHOT</ch.sbb.polarion.extension.interceptor.version> | ||
|
||
<maven-jar-plugin.Automatic-Module-Name>ch.sbb.polarion.extension.interceptor_hooks.only_assignee_can_delete</maven-jar-plugin.Automatic-Module-Name> | ||
<maven-jar-plugin.Extension-Context>only-assignee-can-delete</maven-jar-plugin.Extension-Context> | ||
|
||
<interceptor.artifactId>ch.sbb.polarion.extension.interceptor</interceptor.artifactId> | ||
<hooks.folder.name>hooks</hooks.folder.name> | ||
|
||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<polarion.version>2310</polarion.version> | ||
|
||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<maven.build.timestamp.format>yyyy-MM-dd HH:mm</maven.build.timestamp.format> | ||
|
||
<!-- Maven plugins --> | ||
<maven-clean-plugin.version>3.3.2</maven-clean-plugin.version> | ||
<maven-jar-plugin.version>3.3.0</maven-jar-plugin.version> | ||
<maven-dependency-plugin.version>3.6.1</maven-dependency-plugin.version> | ||
|
||
<!-- Others --> | ||
<jetbrains.api.version>24.0.1</jetbrains.api.version> | ||
|
||
<!--suppress UnresolvedMavenProperty --> | ||
<maven-jar-plugin.Bundle-Version>${project.artifact.selectedVersion.majorVersion}.${project.artifact.selectedVersion.minorVersion}.${project.artifact.selectedVersion.incrementalVersion}</maven-jar-plugin.Bundle-Version> | ||
</properties> | ||
|
||
<profiles> | ||
<profile> | ||
<id>install-to-local-polarion</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-clean-plugin</artifactId> | ||
<version>${maven-clean-plugin.version}</version> | ||
<configuration> | ||
<filesets> | ||
<fileset> | ||
<directory>${env.POLARION_HOME}/polarion/extensions/${interceptor.artifactId}/eclipse/plugins/${hooks.folder.name}</directory> | ||
<includes> | ||
<include>*${maven-jar-plugin.Extension-Context}*.jar</include> | ||
</includes> | ||
<followSymlinks>false</followSymlinks> | ||
</fileset> | ||
</filesets> | ||
</configuration> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>${maven-dependency-plugin.version}</version> | ||
<executions> | ||
<execution> | ||
<id>copy-to-local-polarion</id> | ||
<phase>install</phase> | ||
<goals> | ||
<goal>copy</goal> | ||
</goals> | ||
<configuration> | ||
<artifactItems> | ||
<artifactItem> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>${project.artifactId}</artifactId> | ||
<version>${project.version}</version> | ||
<type>${project.packaging}</type> | ||
</artifactItem> | ||
</artifactItems> | ||
<outputDirectory>${env.POLARION_HOME}/polarion/extensions/${interceptor.artifactId}/eclipse/plugins/${hooks.folder.name}</outputDirectory> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>ch.sbb.polarion.extensions</groupId> | ||
<artifactId>ch.sbb.polarion.extension.interceptor</artifactId> | ||
<version>${ch.sbb.polarion.extension.interceptor.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Polarion artifacts --> | ||
<dependency> | ||
<groupId>com.polarion.alm.projects</groupId> | ||
<artifactId>projects</artifactId> | ||
<version>${polarion.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.polarion.alm.tracker</groupId> | ||
<artifactId>tracker</artifactId> | ||
<version>${polarion.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.polarion.platform</groupId> | ||
<artifactId>platform</artifactId> | ||
<version>${polarion.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.polarion.platform.persistence</groupId> | ||
<artifactId>platform-persistence</artifactId> | ||
<version>${polarion.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.polarion.core.util</groupId> | ||
<artifactId>util</artifactId> | ||
<version>${polarion.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
<!-- Others --> | ||
<dependency> | ||
<groupId>org.jetbrains</groupId> | ||
<artifactId>annotations</artifactId> | ||
<version>${jetbrains.api.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
<build> | ||
<pluginManagement> | ||
<plugins> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-dependency-plugin</artifactId> | ||
<version>${maven-dependency-plugin.version}</version> | ||
</plugin> | ||
|
||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>${maven-jar-plugin.version}</version> | ||
<configuration> | ||
<archive> | ||
<manifestFile>src/main/resources/META-INF/MANIFEST.MF</manifestFile> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
|
||
</plugins> | ||
</pluginManagement> | ||
</build> | ||
</project> |
74 changes: 74 additions & 0 deletions
74
...arion/extension/interceptor_hooks/only_assignee_can_delete/OnlyAssigneeCanDeleteHook.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package ch.sbb.polarion.extension.interceptor_hooks.only_assignee_can_delete; | ||
|
||
import ch.sbb.polarion.extension.interceptor.model.ActionHook; | ||
import ch.sbb.polarion.extension.interceptor.util.PropertiesUtils; | ||
import com.polarion.alm.projects.model.IUniqueObject; | ||
import com.polarion.alm.projects.model.IUser; | ||
import com.polarion.alm.tracker.ITrackerService; | ||
import com.polarion.alm.tracker.model.IWorkItem; | ||
import com.polarion.core.util.logging.Logger; | ||
import com.polarion.platform.core.PlatformContext; | ||
import com.polarion.platform.persistence.model.IPObject; | ||
import com.polarion.platform.persistence.model.IPObjectList; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Iterator; | ||
|
||
@SuppressWarnings({"unused", "unchecked", "rawtypes"}) | ||
public class OnlyAssigneeCanDeleteHook extends ActionHook { | ||
|
||
private static final String SETTINGS_PROJECTS = "projects"; | ||
private static final String SETTINGS_ERROR_MESSAGE = "errorMessage"; | ||
private static final String SETTINGS_DELETE_UNASSIGNED = "deleteUnassigned"; | ||
private static final boolean DEFAULT_DELETE_UNASSIGNED = true; | ||
private static final String DEFAULT_ERROR_MESSAGE = "Only assignee user can delete WI!"; | ||
private static final String VERSION = "1.0.0"; | ||
private static final ITrackerService trackerService = PlatformContext.getPlatform().lookupService(ITrackerService.class); | ||
private static final Logger logger = Logger.getLogger(OnlyAssigneeCanDeleteHook.class); | ||
|
||
public OnlyAssigneeCanDeleteHook() { | ||
super(ItemType.WORKITEM, ActionType.DELETE, VERSION, "Control that only assignee user can delete WI." + | ||
" If Wi is unassigned then it can be removed or not dependent on value property " + SETTINGS_DELETE_UNASSIGNED); | ||
} | ||
|
||
@Override | ||
public String processAction(@NotNull IUniqueObject object) { | ||
boolean deleteUnassigned = DEFAULT_DELETE_UNASSIGNED; | ||
String deleteUnassignedStringValue = getSettingsValue(SETTINGS_DELETE_UNASSIGNED); | ||
try { | ||
deleteUnassigned = Boolean.parseBoolean(deleteUnassignedStringValue); | ||
} catch (NumberFormatException e) { | ||
logger.error("Cannot parse boolean value '%s'".formatted(deleteUnassignedStringValue), e); | ||
} | ||
|
||
IWorkItem workItem = (IWorkItem) object; | ||
String returnMessage = null; | ||
if (workItem.getType() != null && workItem.getId() != null && isCommaSeparatedSettingsHasItem(workItem.getProjectId(), SETTINGS_PROJECTS)) { | ||
boolean allowToDelete = false; | ||
String currentUser = trackerService.getDataService().getSecurityService().getCurrentUser(); | ||
IPObjectList assignees = workItem.getAssignees(); | ||
if (assignees.isEmpty()) { | ||
allowToDelete = deleteUnassigned; | ||
} else { | ||
for (Iterator<IPObject> i = assignees.iterator(); i.hasNext() && !allowToDelete; ) { | ||
IPObject user = i.next(); | ||
allowToDelete = currentUser.equals(((IUser) user).getId()); | ||
} | ||
} | ||
if (!allowToDelete) { | ||
returnMessage = getSettingsValue(SETTINGS_ERROR_MESSAGE); | ||
} | ||
} | ||
|
||
return returnMessage; | ||
} | ||
|
||
@Override | ||
public String getDefaultSettings() { | ||
return PropertiesUtils.build( | ||
SETTINGS_PROJECTS, ALL_WILDCARD, | ||
SETTINGS_ERROR_MESSAGE, DEFAULT_ERROR_MESSAGE, | ||
SETTINGS_DELETE_UNASSIGNED, String.valueOf(DEFAULT_DELETE_UNASSIGNED) | ||
); | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
hooks/only-assignee-can-delete/src/main/resources/META-INF/MANIFEST.MF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Name: WorkItem deletion hook for Polarion ALM Interceptor plugin | ||
Main-Class: ch.sbb.polarion.extension.interceptor_hooks.only_assignee_can_delete.OnlyAssigneeCanDeleteHook |
Oops, something went wrong.