Skip to content

Commit

Permalink
use new dialog to prompt for user/group (#159)
Browse files Browse the repository at this point in the history
replaces the browser built-in prompt and alert calls with the dialogs
for better theming.
  • Loading branch information
mawinter69 authored Jul 27, 2024
1 parent 6e5dbb5 commit 259392b
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 50 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@
<changelist>-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
<hpi.compatibleSinceVersion>3.2</hpi.compatibleSinceVersion>
<jenkins.version>2.387.3</jenkins.version>
<jenkins.version>2.426.3</jenkins.version>
<spotless.check.skip>false</spotless.check.skip>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.jenkins.tools.bom</groupId>
<artifactId>bom-2.387.x</artifactId>
<version>2329.v078520e55c19</version>
<artifactId>bom-2.426.x</artifactId>
<version>3056.v53343b_a_b_a_850</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,14 @@ THE SOFTWARE.
data-type="USER"
data-type-label="${%user}"
data-message-prompt="${%userPrompt}"
data-message-empty="${%userEmpty}"
data-message-title="${%Add user}"
data-message-error="${%userError}">${%Add user…}</button>
<button type="button" class="jenkins-button matrix-auth-add-button" value="" id="${id}GroupButton"
data-table-id="${id}"
data-type="GROUP"
data-type-label="${%group}"
data-message-prompt="${%groupPrompt}"
data-message-empty="${%groupEmpty}"
data-message-title="${%Add group}"
data-message-error="${%groupError}">${%Add group…}</button>
<f:helpLink featureName="${%Permissions matrix}" url="${descriptor.find('hudson.security.GlobalMatrixAuthorizationStrategy$DescriptorImpl').getHelpFile('user-group')}"/>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@ tooltip_enabled={0}/{1} for {2} {3}
tooltip_disabled={0}/{1} for {2} {3} is granted through another permission

groupPrompt=Group name:
groupEmpty=Please enter a group name
groupError=An entry for this group already exists

userPrompt=User ID:
userEmpty=Please enter a user ID
userError=An entry for this user already exists

ambiguous=This table contains rows with ambiguous entries. This means that they apply both to users with the specified ID, and groups with the specified name. \
Expand Down
82 changes: 39 additions & 43 deletions src/main/resources/hudson/security/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,51 @@ Behaviour.specify(".matrix-auth-add-button", 'GlobalMatrixAuthorizationStrategy'
var type = dataReference.getAttribute('data-type');
var typeLabel = dataReference.getAttribute('data-type-label');

var name = prompt(dataReference.getAttribute('data-message-prompt'));
if (name == null) {
return;
}
if(name=="") {
alert(dataReference.getAttribute('data-message-empty'));
return;
}
if(findElementsBySelector(table,"TR").find(function(n){return n.getAttribute("name")=='['+type+':'+name+']';})!=null) {
alert(dataReference.getAttribute('data-message-error'));
return;
}
var name = dialog.prompt(dataReference.getAttribute('data-message-title'), {
message: dataReference.getAttribute('data-message-prompt')
}).then ((name) => {
if(findElementsBySelector(table,"TR").find(function(n){return n.getAttribute("name")=='['+type+':'+name+']';})!=null) {
dialog.alert(dataReference.getAttribute('data-message-error'));
return;
}

if(document.importNode!=null)
copy = document.importNode(master,true);
else
copy = master.cloneNode(true); // for IE
copy.removeAttribute("id");
copy.removeAttribute("style");
copy.firstChild.innerHTML = YAHOO.lang.escapeHTML(name); // TODO consider setting innerText
copy.setAttribute("name",'['+type+':'+name+']');
if(document.importNode!=null)
copy = document.importNode(master,true);
else
copy = master.cloneNode(true); // for IE
copy.removeAttribute("id");
copy.removeAttribute("style");
copy.firstChild.innerHTML = YAHOO.lang.escapeHTML(name); // TODO consider setting innerText
copy.setAttribute("name",'['+type+':'+name+']');

for(var child = copy.firstChild; child !== null; child = child.nextSibling) {
if (child.hasAttribute('data-permission-id')) {
child.setAttribute("data-tooltip-enabled", child.getAttribute("data-tooltip-enabled").replace("__SID__", name).replace("__TYPE__", typeLabel));
child.setAttribute("data-tooltip-disabled", child.getAttribute("data-tooltip-disabled").replace("__SID__", name).replace("__TYPE__", typeLabel));
for(var child = copy.firstChild; child !== null; child = child.nextSibling) {
if (child.hasAttribute('data-permission-id')) {
child.setAttribute("data-tooltip-enabled", child.getAttribute("data-tooltip-enabled").replace("__SID__", name).replace("__TYPE__", typeLabel));
child.setAttribute("data-tooltip-disabled", child.getAttribute("data-tooltip-disabled").replace("__SID__", name).replace("__TYPE__", typeLabel));
}
}
}

var tooltipAttributeName = getTooltipAttributeName();
var tooltipAttributeName = getTooltipAttributeName();

findElementsBySelector(copy, ".stop a").forEach(function(item) {
let oldTitle = item.getAttribute("title");
if (oldTitle !== null) {
item.setAttribute("title", oldTitle.replace("__SID__", name).replace("__TYPE__", typeLabel));
}
item.setAttribute(tooltipAttributeName, item.getAttribute(tooltipAttributeName).replace("__SID__", name).replace("__TYPE__", typeLabel));
});
findElementsBySelector(copy, ".stop a").forEach(function(item) {
let oldTitle = item.getAttribute("title");
if (oldTitle !== null) {
item.setAttribute("title", oldTitle.replace("__SID__", name).replace("__TYPE__", typeLabel));
}
item.setAttribute(tooltipAttributeName, item.getAttribute(tooltipAttributeName).replace("__SID__", name).replace("__TYPE__", typeLabel));
});

findElementsBySelector(copy, "input[type=checkbox]").forEach(function(item) {
const tooltip = item.getAttribute(tooltipAttributeName);
if (tooltip) {
item.setAttribute(tooltipAttributeName, tooltip.replace("__SID__", name).replace("__TYPE__", typeLabel));
} else {
item.setAttribute("title", item.getAttribute("title").replace("__SID__", name).replace("__TYPE__", typeLabel));
}
});
table.appendChild(copy);
Behaviour.applySubtree(findAncestor(table,"TABLE"),true);
findElementsBySelector(copy, "input[type=checkbox]").forEach(function(item) {
const tooltip = item.getAttribute(tooltipAttributeName);
if (tooltip) {
item.setAttribute(tooltipAttributeName, tooltip.replace("__SID__", name).replace("__TYPE__", typeLabel));
} else {
item.setAttribute("title", item.getAttribute("title").replace("__SID__", name).replace("__TYPE__", typeLabel));
}
});
table.appendChild(copy);
Behaviour.applySubtree(findAncestor(table,"TABLE"),true);
}, () => {});
}
});

Expand Down

0 comments on commit 259392b

Please sign in to comment.