Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix error message when creation of item by type is prohibited #9662

Merged

Conversation

daniel-beck
Copy link
Member

Noticed this while looking at neighboring code for matrix-auth development and experimentally confirmed: The output here is weird.

Patch to matrix-auth since there seem to be no implementers
diff --git a/src/main/java/hudson/security/GlobalMatrixAuthorizationStrategy.java b/src/main/java/hudson/security/GlobalMatrixAuthorizationStrategy.java
index 14eae51..38eb9fc 100644
--- a/src/main/java/hudson/security/GlobalMatrixAuthorizationStrategy.java
+++ b/src/main/java/hudson/security/GlobalMatrixAuthorizationStrategy.java
@@ -29,6 +29,9 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import hudson.Extension;
 import hudson.PluginManager;
 import hudson.model.Descriptor;
+import hudson.model.FreeStyleProject;
+import hudson.model.ItemGroup;
+import hudson.model.TopLevelItemDescriptor;
 import hudson.model.User;
 import hudson.util.FormValidation;
 import java.io.IOException;
@@ -57,6 +60,7 @@ import org.kohsuke.accmod.restrictions.DoNotUse;
 import org.kohsuke.accmod.restrictions.NoExternalUse;
 import org.kohsuke.stapler.QueryParameter;
 import org.kohsuke.stapler.StaplerRequest;
+import org.springframework.security.core.Authentication;
 
 /**
  * Role-based authorization via a matrix.
@@ -121,6 +125,11 @@ public class GlobalMatrixAuthorizationStrategy extends AuthorizationStrategy imp
                     toString(p), permission, p instanceof PrincipalSid)) return true;
             return null;
         }
+
+        @Override
+        public boolean hasCreatePermission2(@NonNull Authentication a, @NonNull ItemGroup c, @NonNull TopLevelItemDescriptor d) {
+            return d.clazz != FreeStyleProject.class;
+        }
     }

Testing done

Manual - before

Screenshot 2024-08-26 at 17 58 24

Manual - after

Screenshot 2024-08-26 at 18 06 36

(I skipped a manual test of the View variant.)

Still not ideal, but that's more related to the localization message skipping quotation marks or other formatting than this message.

Proposed changelog entries

  • too minor

Proposed upgrade guidelines

N/A

Submitter checklist

Desired reviewers

@mention

Before the changes are marked as ready-for-merge:

Maintainer checklist

@daniel-beck daniel-beck added the skip-changelog Should not be shown in the changelog label Aug 26, 2024
Copy link
Member

@timja timja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/label ready-for-merge


This PR is now ready for merge, after ~24 hours, we will merge it if there's no negative feedback.

Thanks!

@comment-ops-bot comment-ops-bot bot added the ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback label Aug 26, 2024
@MarkEWaite MarkEWaite added bug For changelog: Minor bug. Will be listed after features and removed bug For changelog: Minor bug. Will be listed after features labels Aug 26, 2024
@MarkEWaite
Copy link
Contributor

Merging before the weekly build so that it is included.

@MarkEWaite MarkEWaite merged commit ffdd5be into jenkinsci:master Aug 26, 2024
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge The PR is ready to go, and it will be merged soon if there is no negative feedback skip-changelog Should not be shown in the changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants