diff --git a/core/src/main/java/jenkins/appearance/AppearanceCategory.java b/core/src/main/java/jenkins/appearance/AppearanceCategory.java new file mode 100644 index 000000000000..ac27ac279ae4 --- /dev/null +++ b/core/src/main/java/jenkins/appearance/AppearanceCategory.java @@ -0,0 +1,45 @@ +/* + * The MIT License + * + * Copyright (c) 2023, Tim Jacomb + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package jenkins.appearance; + +import hudson.Extension; +import jenkins.model.GlobalConfigurationCategory; + +/** + * Global configuration of appearance configuration + * + */ +@Extension +public class AppearanceCategory extends GlobalConfigurationCategory { + @Override + public String getShortDescription() { + return Messages.AppearanceCategory_DisplayName(); + } + + @Override + public String getDisplayName() { + return Messages.AppearanceCategory_Description(); + } +} diff --git a/core/src/main/java/jenkins/appearance/AppearanceGlobalConfiguration.java b/core/src/main/java/jenkins/appearance/AppearanceGlobalConfiguration.java new file mode 100644 index 000000000000..35075425b90f --- /dev/null +++ b/core/src/main/java/jenkins/appearance/AppearanceGlobalConfiguration.java @@ -0,0 +1,110 @@ +/* + * The MIT License + * + * Copyright (c) 2023, Tim Jacomb + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +package jenkins.appearance; + +import edu.umd.cs.findbugs.annotations.NonNull; +import hudson.Extension; +import hudson.Functions; +import hudson.model.Descriptor; +import hudson.model.ManagementLink; +import hudson.util.FormApply; +import java.io.IOException; +import java.util.function.Predicate; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.servlet.ServletException; +import jenkins.model.Jenkins; +import net.sf.json.JSONObject; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; +import org.kohsuke.stapler.StaplerRequest; +import org.kohsuke.stapler.StaplerResponse; +import org.kohsuke.stapler.verb.POST; + +@Extension +public class AppearanceGlobalConfiguration extends ManagementLink { + + private static final Logger LOGGER = Logger.getLogger(AppearanceGlobalConfiguration.class.getName()); + + @Restricted(NoExternalUse.class) + public static final Predicate FILTER = input -> input.getCategory() instanceof AppearanceCategory; + + @Override + public String getIconFileName() { + if (Functions.getSortedDescriptorsForGlobalConfigByDescriptor(FILTER).isEmpty()) { + return null; + } + + return "symbol-brush-outline"; + } + + @Override + public String getDisplayName() { + return Messages.AppearanceGlobalConfiguration_DisplayName(); + } + + @Override + public String getDescription() { + return Messages.AppearanceGlobalConfiguration_Description(); + } + + @Override + public String getUrlName() { + return "appearance"; + } + + @NonNull + @Override + public Category getCategory() { + return Category.CONFIGURATION; + } + + @POST + public synchronized void doConfigure(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException, Descriptor.FormException { + boolean result = configure(req, req.getSubmittedForm()); + LOGGER.log(Level.FINE, "appearance saved: " + result); + FormApply.success(req.getContextPath() + "/manage").generateResponse(req, rsp, null); + } + + private boolean configure(StaplerRequest req, JSONObject json) throws Descriptor.FormException, IOException { + Jenkins j = Jenkins.get(); + j.checkPermission(Jenkins.MANAGE); + + boolean result = true; + for (Descriptor d : Functions.getSortedDescriptorsForGlobalConfigByDescriptor(FILTER)) { + result &= configureDescriptor(req, json, d); + } + j.save(); + + return result; + } + + private boolean configureDescriptor(StaplerRequest req, JSONObject json, Descriptor d) throws Descriptor.FormException { + String name = d.getJsonSafeClassName(); + JSONObject js = json.has(name) ? json.getJSONObject(name) : new JSONObject(); // if it doesn't have the property, the method returns invalid null object. + json.putAll(js); + return d.configure(req, js); + } +} diff --git a/core/src/main/resources/jenkins/appearance/AppearanceGlobalConfiguration/index.jelly b/core/src/main/resources/jenkins/appearance/AppearanceGlobalConfiguration/index.jelly new file mode 100644 index 000000000000..c7fdd51e5641 --- /dev/null +++ b/core/src/main/resources/jenkins/appearance/AppearanceGlobalConfiguration/index.jelly @@ -0,0 +1,61 @@ + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/core/src/main/resources/jenkins/appearance/Messages.properties b/core/src/main/resources/jenkins/appearance/Messages.properties new file mode 100644 index 000000000000..248beefd3000 --- /dev/null +++ b/core/src/main/resources/jenkins/appearance/Messages.properties @@ -0,0 +1,5 @@ +AppearanceGlobalConfiguration.DisplayName=Appearance +AppearanceGlobalConfiguration.Description=Configure the look and feel of Jenkins + +AppearanceCategory.DisplayName=Appearance +AppearanceCategory.Description=Configure the look and feel of Jenkins diff --git a/war/src/main/resources/images/symbols/brush-outline.svg b/war/src/main/resources/images/symbols/brush-outline.svg new file mode 100644 index 000000000000..14f3dce438fb --- /dev/null +++ b/war/src/main/resources/images/symbols/brush-outline.svg @@ -0,0 +1 @@ +Brush