Skip to content

Commit c7f1202

Browse files
authored
allow users with Overall/Manage to configure global options (#423)
1 parent c5fd7ef commit c7f1202

File tree

8 files changed

+25
-16
lines changed

8 files changed

+25
-16
lines changed

pom.xml

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.jenkins-ci.plugins</groupId>
66
<artifactId>plugin</artifactId>
7-
<version>4.78</version>
7+
<version>4.81</version>
88
<relativePath />
99
</parent>
1010
<groupId>io.jenkins.plugins</groupId>
@@ -35,6 +35,8 @@
3535
<gitHubRepo>jenkinsci/${project.artifactId}-plugin</gitHubRepo>
3636
<spotless.check.skip>false</spotless.check.skip>
3737
<hpi.compatibleSinceVersion>685</hpi.compatibleSinceVersion>
38+
<!-- Jenkins.MANAGE is still considered beta -->
39+
<useBeta>true</useBeta>
3840
</properties>
3941

4042
<dependencyManagement>

src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMNavigator.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ public SCMNavigator newInstance(String name) {
512512
public ListBoxModel doFillServerNameItems(
513513
@AncestorInPath SCMSourceOwner context, @QueryParameter String serverName) {
514514
if (context == null) {
515-
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
515+
if (!Jenkins.get().hasPermission(Jenkins.MANAGE)) {
516516
// must have admin if you want the list without a context
517517
ListBoxModel result = new ListBoxModel();
518518
result.add(serverName);
@@ -535,7 +535,7 @@ public ListBoxModel doFillCredentialsIdItems(
535535
@QueryParameter String credentialsId) {
536536
StandardListBoxModel result = new StandardListBoxModel();
537537
if (context == null) {
538-
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
538+
if (!Jenkins.get().hasPermission(Jenkins.MANAGE)) {
539539
// must have admin if you want the list without a context
540540
result.includeCurrentValue(credentialsId);
541541
return result;

src/main/java/io/jenkins/plugins/gitlabbranchsource/GitLabSCMSource.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,7 @@ public String getSelectedServer(@QueryParameter String serverName) {
819819
public ListBoxModel doFillServerNameItems(
820820
@AncestorInPath SCMSourceOwner context, @QueryParameter String serverName) {
821821
if (context == null) {
822-
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
822+
if (!Jenkins.get().hasPermission(Jenkins.MANAGE)) {
823823
// must have admin if you want the list without a context
824824
ListBoxModel result = new ListBoxModel();
825825
result.add(serverName);
@@ -843,7 +843,7 @@ public ListBoxModel doFillCredentialsIdItems(
843843
StandardListBoxModel result = new StandardListBoxModel();
844844
if (context == null) {
845845
// must have admin if you want the list without a context
846-
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
846+
if (!Jenkins.get().hasPermission(Jenkins.MANAGE)) {
847847
result.includeCurrentValue(credentialsId);
848848
return result;
849849
}

src/main/java/io/jenkins/plugins/gitlabbranchsource/SSHCheckoutTrait.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public ListBoxModel doFillCredentialsIdItems(
8888
@QueryParameter String credentialsId) {
8989
StandardListBoxModel result = new StandardListBoxModel();
9090
if (context == null) {
91-
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
91+
if (!Jenkins.get().hasPermission(Jenkins.MANAGE)) {
9292
// must have admin if you want the list without a context
9393
result.includeCurrentValue(credentialsId);
9494
return result;

src/main/java/io/jenkins/plugins/gitlabserverconfig/action/GitlabAction.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class GitlabAction implements RootAction {
3434

3535
@RequirePOST
3636
public HttpResponse doServerList() {
37-
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
37+
if (!Jenkins.get().hasPermission(Jenkins.MANAGE)) {
3838
return HttpResponses.errorJSON("no permission to get Gitlab server list");
3939
}
4040

@@ -52,7 +52,7 @@ public HttpResponse doServerList() {
5252
@RequirePOST
5353
public HttpResponse doProjectList(
5454
@AncestorInPath SCMSourceOwner context, @QueryParameter String server, @QueryParameter String owner) {
55-
if (!Jenkins.get().hasPermission(Jenkins.ADMINISTER)) {
55+
if (!Jenkins.get().hasPermission(Jenkins.MANAGE)) {
5656
return HttpResponses.errorJSON("no permission to get Gitlab server list");
5757
}
5858

src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServer.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ public static class DescriptorImpl extends Descriptor<GitLabServer> {
507507
*/
508508
@POST
509509
public static FormValidation doCheckServerUrl(@QueryParameter String serverUrl) {
510-
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
510+
Jenkins.get().checkPermission(Jenkins.MANAGE);
511511
try {
512512
new URL(serverUrl);
513513
} catch (MalformedURLException e) {
@@ -626,7 +626,7 @@ public FormValidation doTestConnection(@QueryParameter String serverUrl, @QueryP
626626
public ListBoxModel doFillCredentialsIdItems(
627627
@QueryParameter String serverUrl, @QueryParameter String credentialsId) {
628628
Jenkins jenkins = Jenkins.get();
629-
if (!jenkins.hasPermission(Jenkins.ADMINISTER)) {
629+
if (!jenkins.hasPermission(Jenkins.MANAGE)) {
630630
return new StandardListBoxModel().includeCurrentValue(credentialsId);
631631
}
632632
return new StandardListBoxModel()
@@ -650,7 +650,7 @@ public ListBoxModel doFillCredentialsIdItems(
650650
public ListBoxModel doFillWebhookSecretCredentialsIdItems(
651651
@QueryParameter String serverUrl, @QueryParameter String webhookSecretCredentialsId) {
652652
Jenkins jenkins = Jenkins.get();
653-
if (!jenkins.hasPermission(Jenkins.ADMINISTER)) {
653+
if (!jenkins.hasPermission(Jenkins.MANAGE)) {
654654
return new StandardListBoxModel().includeCurrentValue(webhookSecretCredentialsId);
655655
}
656656
return new StandardListBoxModel()
@@ -665,7 +665,7 @@ public ListBoxModel doFillWebhookSecretCredentialsIdItems(
665665

666666
private StandardCredentials getCredentials(String serverUrl, String credentialsId) {
667667
Jenkins jenkins = Jenkins.get();
668-
jenkins.checkPermission(Jenkins.ADMINISTER);
668+
jenkins.checkPermission(Jenkins.MANAGE);
669669
return StringUtils.isBlank(credentialsId)
670670
? null
671671
: CredentialsMatchers.firstOrNull(

src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/GitLabServers.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import hudson.ExtensionList;
99
import hudson.model.Descriptor;
1010
import hudson.model.PersistentDescriptor;
11+
import hudson.security.Permission;
1112
import hudson.util.ListBoxModel;
1213
import io.jenkins.plugins.gitlabserverconfig.servers.helpers.GitLabPersonalAccessTokenCreator;
1314
import java.util.ArrayList;
@@ -38,6 +39,12 @@ public class GitLabServers extends GlobalConfiguration implements PersistentDesc
3839
*/
3940
private List<GitLabServer> servers;
4041

42+
@NonNull
43+
@Override
44+
public Permission getRequiredGlobalConfigPagePermission() {
45+
return Jenkins.MANAGE;
46+
}
47+
4148
/**
4249
* Gets the {@link GitLabServers} singleton.
4350
*
@@ -96,7 +103,7 @@ public List<GitLabServer> getServers() {
96103
* @param servers the list of endpoints.
97104
*/
98105
public void setServers(@CheckForNull List<? extends GitLabServer> servers) {
99-
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
106+
Jenkins.get().checkPermission(Jenkins.MANAGE);
100107
this.servers = fixNull(servers).stream()
101108
.filter(distinctByKey(GitLabServer::getName))
102109
.collect(Collectors.toList());

src/main/java/io/jenkins/plugins/gitlabserverconfig/servers/helpers/GitLabPersonalAccessTokenCreator.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public String getDisplayName() {
8181
public ListBoxModel doFillCredentialsIdItems(
8282
@QueryParameter String serverUrl, @QueryParameter String credentialsId) {
8383
Jenkins jenkins = Jenkins.get();
84-
if (!jenkins.hasPermission(Jenkins.ADMINISTER)) {
84+
if (!jenkins.hasPermission(Jenkins.MANAGE)) {
8585
return new StandardListBoxModel().includeCurrentValue(credentialsId);
8686
}
8787
return new StandardUsernameListBoxModel()
@@ -108,7 +108,7 @@ public FormValidation doCreateTokenByCredentials(
108108
@QueryParameter String serverUrl, @QueryParameter String credentialsId) {
109109

110110
Jenkins jenkins = Jenkins.get();
111-
jenkins.checkPermission(Jenkins.ADMINISTER);
111+
jenkins.checkPermission(Jenkins.MANAGE);
112112
if (isEmpty(credentialsId)) {
113113
return FormValidation.error("Please specify credentials to create token");
114114
}
@@ -156,7 +156,7 @@ public FormValidation doCreateTokenByCredentials(
156156
@RequirePOST
157157
public FormValidation doCreateTokenByPassword(
158158
@QueryParameter String serverUrl, @QueryParameter String login, @QueryParameter String password) {
159-
Jenkins.get().checkPermission(Jenkins.ADMINISTER);
159+
Jenkins.get().checkPermission(Jenkins.MANAGE);
160160
try {
161161
String tokenName = UUID.randomUUID().toString();
162162
String token = AccessTokenUtils.createPersonalAccessToken(

0 commit comments

Comments
 (0)