From 42488810727a403e5ee533b1660bf7dc30a28143 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Fri, 20 May 2011 03:11:43 +0200 Subject: [PATCH 1/5] Add config setting to only suggest users which are in a visible group Add a new setting for the suggest section in the Gerrit configuration that limits the suggested users to those which are in at least one group that is visible to the current user. Change-Id: I89654bfdf63e2b780c5e0c93ee54b14afc1640a0 Signed-off-by: Edwin Kempin --- Documentation/config-gerrit.txt | 3 +++ .../gerrit/httpd/rpc/SuggestAccountsEnum.java | 1 + .../gerrit/httpd/rpc/SuggestServiceImpl.java | 16 ++++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index 09b3f50686..2e8d5a4ca1 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt @@ -1779,6 +1779,9 @@ or a user to a group. If `SAME_GROUP`, only users who are also members of a group the current user is a member of will be offered. + +If `VISIBLE_GROUP`, only users who are members of at least one group +that is visible to the current user will be offered. ++ If `OFF`, no account suggestions are given. + Default is `ALL`. diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestAccountsEnum.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestAccountsEnum.java index 0cd21ef2f3..2ef2d44e55 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestAccountsEnum.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestAccountsEnum.java @@ -17,5 +17,6 @@ package com.google.gerrit.httpd.rpc; public enum SuggestAccountsEnum { ALL, SAME_GROUP, + VISIBLE_GROUP, OFF; } diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java index 48176b4a74..379fee6921 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/rpc/SuggestServiceImpl.java @@ -165,6 +165,22 @@ class SuggestServiceImpl extends BaseServiceImplementation implements } break; } + case VISIBLE_GROUP: { + Set usersGroups = groupsOf(account); + usersGroups.removeAll(authConfig.getRegisteredGroups()); + usersGroups.remove(authConfig.getBatchUsersGroup()); + for (AccountGroup.Id usersGroup : usersGroups) { + try { + if (groupControlFactory.controlFor(usersGroup).isVisible()) { + map.put(account.getId(), info); + break; + } + } catch (NoSuchGroupException e) { + continue; + } + } + break; + } case OFF: break; default: From c771cd5c7a16aacc090aaa9bc7c1150a5ca6f590 Mon Sep 17 00:00:00 2001 From: Edwin Kempin Date: Fri, 20 May 2011 08:00:09 +0200 Subject: [PATCH 2/5] Fix NPE on Gerrit startup if mail.from doesn't include a name If for mail.from in the gerrit.config only an e-mail address but no name was set, Gerrit failed on startup with a NullPointerException. Bug: issue 961 Change-Id: Ie99a6c7ae42d77e408bc624408b2d13c8b5f9797 Signed-off-by: Edwin Kempin --- .../gerrit/server/mail/FromAddressGeneratorProvider.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/mail/FromAddressGeneratorProvider.java b/gerrit-server/src/main/java/com/google/gerrit/server/mail/FromAddressGeneratorProvider.java index 2d739ea1aa..afcfccd340 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/mail/FromAddressGeneratorProvider.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/mail/FromAddressGeneratorProvider.java @@ -52,8 +52,8 @@ public class FromAddressGeneratorProvider implements } else { final Address a = Address.parse(from); - final ParamertizedString name = new ParamertizedString(a.name); - if (name.getParameterNames().isEmpty()) { + final ParamertizedString name = a.name != null ? new ParamertizedString(a.name) : null; + if (name == null || name.getParameterNames().isEmpty()) { generator = new ServerGen(a); } else { generator = new PatternGen(srvAddr, accountCache, name, a.email); From 70d336d49b02b5db7b24bb91beddcf4d4a02dbd9 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 20 May 2011 07:03:43 -0700 Subject: [PATCH 3/5] Enable git:// download URLs if canonicalGitUrl set If the administrator has set gerrit.canonicalGitUrl but has left the download.scheme variable unset to its default, assume they want to use git:// as a type of download and enable it. Bug: issue 966 Change-Id: I8f6d5c5a3d16821d07c61f16bce9680a7e0721e5 Signed-off-by: Shawn O. Pearce --- .../gerrit/client/changes/PatchSetComplexDisclosurePanel.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java index efa971b124..364d710c5f 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/changes/PatchSetComplexDisclosurePanel.java @@ -191,7 +191,8 @@ class PatchSetComplexDisclosurePanel extends ComplexDisclosurePanel implements O if (changeDetail.isAllowsAnonymous() && Gerrit.getConfig().getGitDaemonUrl() != null - && allowedSchemes.contains(DownloadScheme.ANON_GIT)) { + && (allowedSchemes.contains(DownloadScheme.ANON_GIT) || + allowedSchemes.contains(DownloadScheme.DEFAULT_DOWNLOADS))) { StringBuilder r = new StringBuilder(); r.append(Gerrit.getConfig().getGitDaemonUrl()); r.append(projectName); From 79a9896f599eede025e0ad78d11c8cf24dade896 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 20 May 2011 07:17:03 -0700 Subject: [PATCH 4/5] Send new patchset event after its available gerrit stream-events sent notification of a new patch set before it created the reference in the Git repository. This confused some CI systems that were able to read the stream-events message and look for the reference before the server was able to create it. Bug: issue 755 Change-Id: I14eb9d19984701eb9afbb13e006a24057e8c3473 Signed-off-by: Shawn O. Pearce --- .../main/java/com/google/gerrit/server/git/ReceiveCommits.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java b/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java index 445974fe7b..4380ff015f 100644 --- a/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java +++ b/gerrit-server/src/main/java/com/google/gerrit/server/git/ReceiveCommits.java @@ -1373,8 +1373,6 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook { insertDummyApproval(result, reviewer, catId, db); } } - - hooks.doPatchsetCreatedHook(result.change, ps); } final RefUpdate ru = repo.updateRef(ps.getRefName()); @@ -1385,6 +1383,7 @@ public class ReceiveCommits implements PreReceiveHook, PostReceiveHook { + repo.getDirectory() + ": " + ru.getResult()); } replication.scheduleUpdate(project.getNameKey(), ru.getName()); + hooks.doPatchsetCreatedHook(result.change, ps); request.cmd.setResult(ReceiveCommand.Result.OK); try { From a83bb1c344787f1e5ff6c20c48c5ad37d8d31253 Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 20 May 2011 08:46:48 -0700 Subject: [PATCH 5/5] Support different color pallete when not signed in If the user is not signed in a different theme of colors can be applied to the UI, making it more obvious that login is necessary. Bug: issue 913 Change-Id: Id8c780042740b3b93dcee7ed84b3f9f6be06d9de Signed-off-by: Shawn O. Pearce --- Documentation/config-gerrit.txt | 16 ++++- .../gerrit/common/data/GerritConfig.java | 46 ------------- .../gerrit/common/data/HostPageData.java | 9 +++ .../java/com/google/gerrit/client/Gerrit.java | 7 ++ .../java/com/google/gerrit/client/gerrit.css | 10 +-- .../com/google/gerrit/client/gwt_override.css | 8 +-- .../gerrit/httpd/GerritConfigProvider.java | 19 ------ .../gerrit/httpd/raw/HostPageServlet.java | 23 +++++-- .../google/gerrit/httpd/raw/ThemeFactory.java | 66 +++++++++++++++++++ 9 files changed, 125 insertions(+), 79 deletions(-) create mode 100644 gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ThemeFactory.java diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index 2e8d5a4ca1..b288c89e2b 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt @@ -1795,7 +1795,8 @@ Background color for the page, and major data tables like the all open changes table or the account dashboard. The value must be a valid HTML hex color code, or standard color name. + -By default white, `FFFFFF`. +By default white, `FFFFFF` for signed-out theme and `FCFEEF` (creme) +for signed-in theme. [[theme.topMenuColor]]theme.topMenuColor:: + @@ -1830,6 +1831,19 @@ code, or standard color name. + By default a shade of yellow, `FFFFCC`. +A different theme may be used for signed-in vs. signed-out user status +by using the "signed-in" and "signed-out" theme sections. Variables +not specified in a section are inherited from the default theme. + +---- +[theme] + backgroundColor = FFFFFF +[theme "signed-in"] + backgroundColor = C0C0C0 +[theme "signed-out"] + backgroundColor = 00FFFF +---- + [[trackingid]] Section trackingid ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java index 2e6be7e995..9bb87abee8 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/GerritConfig.java @@ -42,12 +42,6 @@ public class GerritConfig implements Cloneable { protected List commentLinks; protected boolean documentationAvailable; - protected String backgroundColor; - protected String topMenuColor; - protected String textColor; - protected String trimColor; - protected String selectionColor; - public String getRegisterUrl() { return registerUrl; } @@ -166,44 +160,4 @@ public class GerritConfig implements Cloneable { public void setDocumentationAvailable(final boolean available) { documentationAvailable = available; } - - public String getBackgroundColor() { - return backgroundColor; - } - - public void setBackgroundColor(String color) { - backgroundColor = color; - } - - public String getTopMenuColor() { - return topMenuColor; - } - - public void setTopMenuColor(String color) { - topMenuColor = color; - } - - public String getTextColor() { - return textColor; - } - - public void setTextColor(String color) { - textColor = color; - } - - public String getTrimColor() { - return trimColor; - } - - public void setTrimColor(String color) { - trimColor = color; - } - - public String getSelectionColor() { - return selectionColor; - } - - public void setSelectionColor(String color) { - selectionColor = color; - } } diff --git a/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java b/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java index 717a49287f..66b0c3bc10 100644 --- a/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java +++ b/gerrit-common/src/main/java/com/google/gerrit/common/data/HostPageData.java @@ -22,4 +22,13 @@ public class HostPageData { public Account account; public AccountDiffPreference accountDiffPref; public GerritConfig config; + public Theme theme; + + public static class Theme { + public String backgroundColor; + public String topMenuColor; + public String textColor; + public String trimColor; + public String selectionColor; + } } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java index c2afb84c85..d0e51928d6 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/Gerrit.java @@ -72,6 +72,7 @@ public class Gerrit implements EntryPoint { private static String myHost; private static GerritConfig myConfig; + private static HostPageData.Theme myTheme; private static Account myAccount; private static AccountDiffPreference myAccountDiffPref; @@ -183,6 +184,11 @@ public class Gerrit implements EntryPoint { return myConfig; } + /** Site theme information (site specific colors)/ */ + public static HostPageData.Theme getTheme() { + return myTheme; + } + /** @return the currently signed in user's account data; null if no account */ public static Account getUserAccount() { return myAccount; @@ -264,6 +270,7 @@ public class Gerrit implements EntryPoint { hpd.load(new GerritCallback() { public void onSuccess(final HostPageData result) { myConfig = result.config; + myTheme = result.theme; if (result.account != null) { myAccount = result.account; } diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/gerrit.css b/gerrit-gwtui/src/main/java/com/google/gerrit/client/gerrit.css index c81920dbf0..a281393b59 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/gerrit.css +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/gerrit.css @@ -38,11 +38,11 @@ @def norm-font Arial Unicode MS, Arial, sans-serif; @def mono-font 'Lucida Console', 'Lucida Sans Typewriter', Monaco, monospace; -@eval backgroundColor com.google.gerrit.client.Gerrit.getConfig().getBackgroundColor(); -@eval topMenuColor com.google.gerrit.client.Gerrit.getConfig().getTopMenuColor(); -@eval textColor com.google.gerrit.client.Gerrit.getConfig().getTextColor();; -@eval trimColor com.google.gerrit.client.Gerrit.getConfig().getTrimColor(); -@eval selectionColor com.google.gerrit.client.Gerrit.getConfig().getSelectionColor(); +@eval backgroundColor com.google.gerrit.client.Gerrit.getTheme().backgroundColor; +@eval topMenuColor com.google.gerrit.client.Gerrit.getTheme().topMenuColor; +@eval textColor com.google.gerrit.client.Gerrit.getTheme().textColor; +@eval trimColor com.google.gerrit.client.Gerrit.getTheme().trimColor; +@eval selectionColor com.google.gerrit.client.Gerrit.getTheme().selectionColor; @sprite .greenCheckClass { diff --git a/gerrit-gwtui/src/main/java/com/google/gerrit/client/gwt_override.css b/gerrit-gwtui/src/main/java/com/google/gerrit/client/gwt_override.css index b238292d4e..ed0b32c229 100644 --- a/gerrit-gwtui/src/main/java/com/google/gerrit/client/gwt_override.css +++ b/gerrit-gwtui/src/main/java/com/google/gerrit/client/gwt_override.css @@ -23,10 +23,10 @@ @external .gwt-TabPanel; @external .gwt-TabPanelBottom; -@eval backgroundColor com.google.gerrit.client.Gerrit.getConfig().getBackgroundColor(); -@eval textColor com.google.gerrit.client.Gerrit.getConfig().getTextColor();; -@eval trimColor com.google.gerrit.client.Gerrit.getConfig().getTrimColor(); -@eval selectionColor com.google.gerrit.client.Gerrit.getConfig().getSelectionColor(); +@eval backgroundColor com.google.gerrit.client.Gerrit.getTheme().backgroundColor; +@eval textColor com.google.gerrit.client.Gerrit.getTheme().textColor; +@eval trimColor com.google.gerrit.client.Gerrit.getTheme().trimColor; +@eval selectionColor com.google.gerrit.client.Gerrit.getTheme().selectionColor; body { background: backgroundColor; diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java index e51731d8d3..dd2ef69571 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/GerritConfigProvider.java @@ -149,28 +149,9 @@ class GerritConfigProvider implements Provider { } config.setCommentLinks(links); - config.setBackgroundColor(getThemeColor("backgroundColor", "#FFFFFF")); - config.setTextColor(getThemeColor("textColor", "#000000")); - config.setTrimColor(getThemeColor("trimColor", "#D4E9A9")); - config.setSelectionColor(getThemeColor("selectionColor", "#FFFFCC")); - - config - .setTopMenuColor(getThemeColor("topMenuColor", config.getTrimColor())); - return config; } - private String getThemeColor(String name, String defaultValue) { - String v = cfg.getString("theme", null, name); - if (v == null || v.isEmpty()) { - v = defaultValue; - } - if (!v.startsWith("#") && v.matches("^[0-9a-fA-F]{2,6}$")) { - v = "#" + v; - } - return v; - } - @Override public GerritConfig get() { try { diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java index 45213487da..1c2e5b8ab4 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/HostPageServlet.java @@ -62,6 +62,8 @@ public class HostPageServlet extends HttpServlet { private final Provider currentUser; private final GerritConfig config; + private final HostPageData.Theme signedOutTheme; + private final HostPageData.Theme signedInTheme; private final SitePaths site; private final Document template; private final String noCacheName; @@ -70,10 +72,12 @@ public class HostPageServlet extends HttpServlet { @Inject HostPageServlet(final Provider cu, final SitePaths sp, - final GerritConfig gc, final ServletContext servletContext) - throws IOException, ServletException { + final ThemeFactory themeFactory, final GerritConfig gc, + final ServletContext servletContext) throws IOException, ServletException { currentUser = cu; config = gc; + signedOutTheme = themeFactory.getSignedOutTheme(); + signedInTheme = themeFactory.getSignedInTheme(); site = sp; final String pageName = "HostPage.html"; @@ -158,12 +162,16 @@ public class HostPageServlet extends HttpServlet { w.write(HPD_ID + ".account="); json(((IdentifiedUser) user).getAccount(), w); w.write(";"); + w.write(HPD_ID + ".accountDiffPref="); json(((IdentifiedUser) user).getAccountDiffPreference(), w); w.write(";"); - final byte[] userData = w.toString().getBytes("UTF-8"); + w.write(HPD_ID + ".theme="); + json(signedInTheme, w); + w.write(";"); + final byte[] userData = w.toString().getBytes("UTF-8"); raw = concat(page.part1, userData, page.part2); } else { raw = page.full; @@ -303,7 +311,14 @@ public class HostPageServlet extends HttpServlet { } part1 = raw.substring(0, p).getBytes("UTF-8"); part2 = raw.substring(raw.indexOf('>', p) + 1).getBytes("UTF-8"); - full = concat(part1, part2, new byte[0]); + + final StringWriter w = new StringWriter(); + w.write(HPD_ID + ".theme="); + json(signedOutTheme, w); + w.write(";"); + + final byte[] themeData = w.toString().getBytes("UTF-8"); + full = concat(part1, themeData, part2); full_gz = HtmlDomUtil.compress(full); } } diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ThemeFactory.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ThemeFactory.java new file mode 100644 index 0000000000..a1e09f9861 --- /dev/null +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/ThemeFactory.java @@ -0,0 +1,66 @@ +// Copyright (C) 2011 The Android Open Source Project +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.gerrit.httpd.raw; + +import com.google.gerrit.common.data.HostPageData; +import com.google.gerrit.server.config.GerritServerConfig; +import com.google.inject.Inject; + +import org.eclipse.jgit.lib.Config; + +class ThemeFactory { + private final Config cfg; + + @Inject + ThemeFactory(@GerritServerConfig Config cfg) { + this.cfg = cfg; + } + + HostPageData.Theme getSignedOutTheme() { + return getTheme("signed-out"); + } + + HostPageData.Theme getSignedInTheme() { + return getTheme("signed-in"); + } + + private HostPageData.Theme getTheme(String name) { + HostPageData.Theme theme = new HostPageData.Theme(); + theme.backgroundColor = color(name, "backgroundColor", "#FFFFFF"); + theme.textColor = color(name, "textColor", "#000000"); + theme.trimColor = color(name, "trimColor", "#D4E9A9"); + theme.selectionColor = color(name, "selectionColor", "#FFFFCC"); + theme.topMenuColor = color(name, "topMenuColor", theme.trimColor); + return theme; + } + + private String color(String section, String name, String defaultValue) { + String v = cfg.getString("theme", section, name); + if (v == null || v.isEmpty()) { + v = cfg.getString("theme", null, name); + if (v == null || v.isEmpty()) { + if ("signed-in".equals(section) && "backgroundColor".equals(name)) { + v = "#FCFEEF"; + } else { + v = defaultValue; + } + } + } + if (!v.startsWith("#") && v.matches("^[0-9a-fA-F]{2,6}$")) { + v = "#" + v; + } + return v; + } +}