-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- #17 define configuration page for admins; - add resources to atlassian-plugin.xml; - add WebAction; - Add store functions (plugin settings); - add form to define projects Co-authored-by: Marcel Frank <[email protected]>
- Loading branch information
1 parent
e1d5aac
commit 8accd3e
Showing
11 changed files
with
540 additions
and
2 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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/aprey/jira/plugin/openpoker/api/config/AllowedProjectsCondition.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,31 @@ | ||
package com.aprey.jira.plugin.openpoker.api.config; | ||
|
||
import java.util.List; | ||
|
||
import com.atlassian.jira.plugin.webfragment.conditions.AbstractWebCondition; | ||
import com.atlassian.jira.plugin.webfragment.model.JiraHelper; | ||
import com.atlassian.jira.user.ApplicationUser; | ||
|
||
/** | ||
* Class that defines a condition for the web fragment visibility | ||
*/ | ||
public class AllowedProjectsCondition extends AbstractWebCondition { | ||
|
||
/** | ||
* Method to determine whether the web fragment should be displayed or not | ||
* @param applicationUser The user currently viewing the page | ||
* @param jiraHelper The JiraHelper that provides access to various Jira-related objects | ||
* @return boolean value indicating whether the web fragment should be displayed or not | ||
*/ | ||
@Override | ||
public boolean shouldDisplay(ApplicationUser applicationUser, JiraHelper jiraHelper) { | ||
List<String> allowedProjects = ConfigurationManager.getStoredAllowedProjects(); | ||
if ( allowedProjects.isEmpty() ) { | ||
return true; | ||
} | ||
if ( jiraHelper.getProject() != null ) { | ||
return allowedProjects.contains(jiraHelper.getProject().getKey()); | ||
} | ||
return true; | ||
} | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/aprey/jira/plugin/openpoker/api/config/ConfigurationManager.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,49 @@ | ||
package com.aprey.jira.plugin.openpoker.api.config; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.stream.Collectors; | ||
|
||
import com.atlassian.jira.component.ComponentAccessor; | ||
import com.atlassian.sal.api.pluginsettings.PluginSettings; | ||
import com.atlassian.sal.api.pluginsettings.PluginSettingsFactory; | ||
|
||
public abstract class ConfigurationManager { | ||
//Key for plugin settings | ||
private static String OPEN_POKER_KEY = "com.aprey.jira.plugin.openpoker"; | ||
|
||
/** | ||
* Method to get the plugin settings | ||
* | ||
* @return pluginSettings instance | ||
*/ | ||
public static PluginSettings getPluginSettings() { | ||
PluginSettingsFactory pluginSettingsFactory = ComponentAccessor.getOSGiComponentInstanceOfType(PluginSettingsFactory.class); | ||
PluginSettings pluginSettings = pluginSettingsFactory.createSettingsForKey(OPEN_POKER_KEY); | ||
return pluginSettings; | ||
} | ||
|
||
/** | ||
* Method to get the stored allowed projects from plugin settings | ||
* | ||
* @return ArrayList of allowed projects | ||
*/ | ||
public static ArrayList<String> getStoredAllowedProjects() { | ||
PluginSettings pluginSettings = getPluginSettings(); | ||
String storedProjects = ((String) pluginSettings.get("allowedProjects")); | ||
if ( storedProjects != null && !storedProjects.isEmpty() ) { | ||
return Arrays.stream(storedProjects.split(",")).collect(Collectors.toCollection(ArrayList::new)); | ||
} | ||
return new ArrayList<>(); | ||
} | ||
|
||
/** | ||
* Method to store the updated allowed projects in plugin settings | ||
* | ||
* @param updatedAllowedProjects String of allowed projects | ||
*/ | ||
public static void storeAllowedProjects(String updatedAllowedProjects) { | ||
PluginSettings pluginSettings = getPluginSettings(); | ||
pluginSettings.put("allowedProjects", updatedAllowedProjects); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
src/main/java/com/aprey/jira/plugin/openpoker/config/PokerConfigPage.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,80 @@ | ||
package com.aprey.jira.plugin.openpoker.config; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.atlassian.jira.component.ComponentAccessor; | ||
import com.atlassian.jira.project.Project; | ||
import com.atlassian.jira.security.request.RequestMethod; | ||
import com.atlassian.jira.security.request.SupportedMethods; | ||
import com.atlassian.jira.web.action.JiraWebActionSupport; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import webwork.action.Action; | ||
import webwork.action.ServletActionContext; | ||
|
||
import static com.aprey.jira.plugin.openpoker.api.config.ConfigurationManager.getStoredAllowedProjects; | ||
import static com.aprey.jira.plugin.openpoker.api.config.ConfigurationManager.storeAllowedProjects; | ||
|
||
@SupportedMethods({ RequestMethod.GET }) | ||
public class PokerConfigPage extends JiraWebActionSupport { | ||
|
||
//List of allowed projects | ||
private List<String> allowedProjects = new ArrayList<>(); | ||
|
||
/** | ||
* Method is called when the page is first loaded | ||
*/ | ||
@Override | ||
public String doDefault() throws Exception { | ||
allowedProjects.addAll(getStoredAllowedProjects()); | ||
return Action.INPUT; | ||
} | ||
|
||
/** | ||
* Method is called when the form is submitted | ||
*/ | ||
@Override | ||
@SupportedMethods({ RequestMethod.POST }) | ||
protected String doExecute() throws Exception { | ||
String updatedAllowedProjects = getUpdatedAllowedProjects(); | ||
storeAllowedProjects(updatedAllowedProjects); | ||
|
||
if ( !getHasErrorMessages() ) { | ||
return returnComplete("openPokerConfig!default.jspa"); | ||
} | ||
return Action.INPUT; | ||
} | ||
|
||
/** | ||
* Method to get the updated allowed projects from the form | ||
* | ||
* @return String of allowed projects | ||
*/ | ||
private static String getUpdatedAllowedProjects() { | ||
HttpServletRequest request = ServletActionContext.getRequest(); | ||
String updatedAllowedProjects = request.getParameter("allowedProjects"); | ||
return updatedAllowedProjects; | ||
} | ||
|
||
public List<String> getAllowedProjects() { | ||
return allowedProjects; | ||
} | ||
|
||
public String getAllowedProjectsValue() { | ||
return String.join(",", allowedProjects); | ||
} | ||
|
||
public void setAllowedProjects(List<String> allowedProjects) { | ||
this.allowedProjects = allowedProjects; | ||
} | ||
|
||
public List<Project> getProjects() { | ||
return ComponentAccessor.getProjectManager().getProjects(); | ||
} | ||
|
||
public String getURL() { | ||
return "openPokerConfig.jspa"; | ||
} | ||
} |
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,10 @@ | ||
.allowedProjectsSelectLabel | ||
{ | ||
display: flex; | ||
width: 100%; | ||
} | ||
|
||
#s2id_allowedProjectsSelect | ||
{ | ||
max-width: 800px; | ||
} |
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,16 @@ | ||
AJS.$(document).ready(() => { | ||
const initialize = () => { | ||
let $allowedProjectsSelect = AJS.$("#allowedProjectsSelect"); | ||
$allowedProjectsSelect.auiSelect2( | ||
{ | ||
placeholder: "Open poker will be available for each project", | ||
allowClear: true | ||
}); | ||
|
||
$allowedProjectsSelect.on("change", () => { | ||
AJS.$("#allowedProjects").val(AJS.$("#allowedProjectsSelect").val()); | ||
}); | ||
}; | ||
|
||
initialize(); | ||
}); |
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,36 @@ | ||
$webResourceManager.requireResource("com.aprey.jira.plugin.openpoker.open-poker:open-poker-config-resources") | ||
<html> | ||
<head> | ||
<title>Open poker configuration</title> | ||
</head> | ||
<body> | ||
|
||
<header class="aui-page-header"> | ||
<div class="aui-page-header-inner"> | ||
<div class="aui-page-header-main"> | ||
<h1>Open poker configuration</h1> | ||
</div> | ||
</div> | ||
</header> | ||
<h2>Permissions</h2> | ||
<form action="$action.getURL()" class="aui" method="POST"> | ||
<input type="hidden" name="atl_token" value="$atl_token" /> | ||
<input type="hidden" id="allowedProjects" name="allowedProjects" value="$action.getAllowedProjectsValue()"/> | ||
<fieldset> | ||
<label for="allowedProjects" class="allowedProjectsSelectLabel">Projects:</label> | ||
<select id="allowedProjectsSelect" name="allowedProjectsSelect" style="padding: 5px 0 0 0" multiple> | ||
#foreach ($project in $projects) | ||
<option #if(${allowedProjects.contains(${project.getKey()})}) selected #end value="${project.getKey()}">${project.getName()} (${project.getKey()})</option> | ||
#end | ||
</select> | ||
<div class="description">Define the projects, where open poker should be rendered on the issue view. If no project is selected, it will be enabled for all projects.</div> | ||
</fieldset> | ||
|
||
<div class="buttons-container" style="padding: 10px 0 4px 0;"> | ||
<div class="buttons"> | ||
<button id="save_button" class="aui-button aui-button-primary" type="submit">Save</button> | ||
</div> | ||
</div> | ||
</form> | ||
</body> | ||
</html> |
Oops, something went wrong.