]> source.dussan.org Git - gitblit.git/commitdiff
Gracefully deal with missing repository in permissions ui (issue 155)
authorJames Moger <james.moger@gitblit.com>
Thu, 1 Nov 2012 13:12:55 +0000 (09:12 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 1 Nov 2012 13:12:55 +0000 (09:12 -0400)
src/com/gitblit/Constants.java
src/com/gitblit/GitBlit.java
src/com/gitblit/client/EditUserDialog.java
src/com/gitblit/client/RegistrantPermissionsPanel.java
src/com/gitblit/client/UsersPanel.java
src/com/gitblit/models/RegistrantAccessPermission.java
src/com/gitblit/models/UserModel.java
src/com/gitblit/wicket/GitBlitWebApp.properties
src/com/gitblit/wicket/pages/EditUserPage.java
src/com/gitblit/wicket/panels/RegistrantPermissionsPanel.java

index 426d2df00056cbf337460224901e57d139d35c54..8a3ec9891860bfb0637cfcf9e40f8094fadc88ad 100644 (file)
@@ -321,7 +321,7 @@ public class Constants {
         * The access permissions available for a repository. \r
         */\r
        public static enum AccessPermission {\r
-               NONE("N"), EXCLUDE("X"), VIEW("V"), CLONE("R"), PUSH("RW"), CREATE("RWC"), DELETE("RWD"), REWIND("RW+");\r
+               NONE("N"), EXCLUDE("X"), VIEW("V"), CLONE("R"), PUSH("RW"), CREATE("RWC"), DELETE("RWD"), REWIND("RW+"), OWNER("RW+");\r
                \r
                public static final AccessPermission [] NEWPERMISSIONS = { EXCLUDE, VIEW, CLONE, PUSH, CREATE, DELETE, REWIND };\r
                \r
@@ -387,7 +387,7 @@ public class Constants {
        }\r
        \r
        public static enum PermissionType {\r
-               EXPLICIT, OWNER, ADMINISTRATOR, TEAM, REGEX;\r
+               MISSING, EXPLICIT, TEAM, REGEX, OWNER, ADMINISTRATOR;\r
        }\r
        \r
        public static enum GCStatus {\r
index eccd7c1115659460405070948a815aba822d8dba..2c5545badef47bf777d8157bb3bdb8790a646db7 100644 (file)
@@ -79,7 +79,6 @@ import com.gitblit.Constants.AuthorizationControl;
 import com.gitblit.Constants.FederationRequest;\r
 import com.gitblit.Constants.FederationStrategy;\r
 import com.gitblit.Constants.FederationToken;\r
-import com.gitblit.Constants.PermissionType;\r
 import com.gitblit.models.FederationModel;\r
 import com.gitblit.models.FederationProposal;\r
 import com.gitblit.models.FederationSet;\r
@@ -2204,6 +2203,8 @@ public class GitBlit implements ServletContextListener {
                case PULL_SETTINGS:\r
                case PULL_SCRIPTS:\r
                        return token.equals(all);\r
+               default:\r
+                       break;\r
                }\r
                return false;\r
        }\r
@@ -2347,6 +2348,8 @@ public class GitBlit implements ServletContextListener {
                                        url = model.origin;\r
                                }\r
                                break;\r
+                       default:\r
+                               break;\r
                        }\r
 \r
                        if (federationSets.containsKey(token)) {\r
index 070926ddf53a7d357d3a66661bcbebd2494369bb..e954fed675423046dc5452a5105e18ac487f3580 100644 (file)
@@ -27,8 +27,10 @@ import java.awt.event.KeyEvent;
 import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.Collections;\r
+import java.util.HashMap;\r
 import java.util.HashSet;\r
 import java.util.List;\r
+import java.util.Map;\r
 import java.util.Set;\r
 \r
 import javax.swing.ImageIcon;\r
@@ -47,6 +49,7 @@ import javax.swing.KeyStroke;
 \r
 import com.gitblit.Constants.AccessRestrictionType;\r
 import com.gitblit.Constants.AuthorizationControl;\r
+import com.gitblit.Constants.PermissionType;\r
 import com.gitblit.Constants.RegistrantType;\r
 import com.gitblit.Keys;\r
 import com.gitblit.models.RegistrantAccessPermission;\r
@@ -343,6 +346,7 @@ public class EditUserDialog extends JDialog {
        }\r
 \r
        public void setRepositories(List<RepositoryModel> repositories, List<RegistrantAccessPermission> permissions) {\r
+               Map<String, RepositoryModel> repoMap = new HashMap<String, RepositoryModel>();\r
                List<String> restricted = new ArrayList<String>();\r
                for (RepositoryModel repo : repositories) {\r
                        // exclude Owner or personal repositories\r
@@ -352,6 +356,7 @@ public class EditUserDialog extends JDialog {
                                        restricted.add(repo.name);\r
                                }                               \r
                        }\r
+                       repoMap.put(repo.name.toLowerCase(), repo);\r
                }\r
                StringUtils.sortRepositorynames(restricted);\r
                \r
@@ -381,6 +386,27 @@ public class EditUserDialog extends JDialog {
                                list.remove(rp.registrant.toLowerCase());\r
                        }\r
                }\r
+               \r
+               // update owner and missing permissions for editing\r
+               for (RegistrantAccessPermission permission : permissions) {\r
+                       if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {\r
+                               // Ensure this is NOT an owner permission - which is non-editable\r
+                               // We don't know this from within the usermodel, ownership is a\r
+                               // property of a repository.\r
+                               RepositoryModel rm = repoMap.get(permission.registrant.toLowerCase());\r
+                               if (rm == null) {\r
+                                       permission.permissionType = PermissionType.MISSING;\r
+                                       permission.mutable = false;\r
+                                       continue;\r
+                               }\r
+                               boolean isOwner = rm.isOwner(username);\r
+                               if (isOwner) {\r
+                                       permission.permissionType = PermissionType.OWNER;\r
+                                       permission.mutable = false;\r
+                               }\r
+                       }\r
+               }\r
+\r
                repositoryPalette.setObjects(list, permissions);\r
        }\r
 \r
index c28724c772b33a65ee2398496ba9c1170d2c9fa1..ef04a8762e8a37a2950e273c0708c7796974a168 100644 (file)
@@ -198,8 +198,13 @@ public class RegistrantPermissionsPanel extends JPanel {
                                setToolTipText(MessageFormat.format(Translation.get("gb.regexPermission"), ap.source));\r
                                break;\r
                        default:\r
-                               setText("");\r
-                               setToolTipText(null);\r
+                               if (ap.isMissing()) {\r
+                                       setText(Translation.get("gb.missing"));\r
+                                       setToolTipText(Translation.get("gb.missingPermission"));\r
+                               } else {\r
+                                       setText("");\r
+                                       setToolTipText(null);\r
+                               }\r
                                break;\r
                        }\r
                }\r
index 2c236958a3157ef963542a4e99417f74b69c2cb1..469d95366c6587cd163f24dfc83f544c17d516e9 100644 (file)
@@ -25,7 +25,6 @@ import java.awt.event.KeyEvent;
 import java.awt.event.MouseAdapter;\r
 import java.awt.event.MouseEvent;\r
 import java.io.IOException;\r
-import java.text.MessageFormat;\r
 import java.util.ArrayList;\r
 import java.util.List;\r
 \r
@@ -41,6 +40,7 @@ import javax.swing.event.ListSelectionEvent;
 import javax.swing.event.ListSelectionListener;\r
 import javax.swing.table.TableRowSorter;\r
 \r
+import com.gitblit.Constants.AccessPermission;\r
 import com.gitblit.Constants.PermissionType;\r
 import com.gitblit.Constants.RpcRequest;\r
 import com.gitblit.models.RegistrantAccessPermission;\r
@@ -313,27 +313,6 @@ public abstract class UsersPanel extends JPanel {
                                gitblit.getSettings());\r
                dialog.setLocationRelativeTo(UsersPanel.this);\r
                dialog.setUsers(gitblit.getUsers());\r
-               \r
-               List<RegistrantAccessPermission> permissions = user.getRepositoryPermissions();\r
-               for (RegistrantAccessPermission permission : permissions) {\r
-                       if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {\r
-                               // Ensure this is NOT an owner permission - which is non-editable\r
-                               // We don't know this from within the usermodel, ownership is a\r
-                               // property of a repository.\r
-                               RepositoryModel rm = gitblit.getRepository(permission.registrant);\r
-                               if (rm == null) {\r
-                                       System.out.println(MessageFormat.format("{0}: failed to find registrant repository {1}",\r
-                                                       getClass().getSimpleName(), permission.registrant));\r
-                                       continue;\r
-                               }\r
-                               boolean isOwner = rm.isOwner(user.username);\r
-                               if (isOwner) {\r
-                                       permission.permissionType = PermissionType.OWNER;\r
-                                       permission.mutable = false;\r
-                               }\r
-                       }\r
-               }\r
-               \r
                dialog.setRepositories(gitblit.getRepositories(), user.getRepositoryPermissions());\r
                dialog.setTeams(gitblit.getTeams(), user.teams == null ? null : new ArrayList<TeamModel>(\r
                                user.teams));\r
index 0b28d1974ae9ee63e094e0fe41a3dd2dbcc60836..4bdc2da464bcc894e3307ca752e28e08f9962291 100644 (file)
@@ -64,6 +64,10 @@ public class RegistrantAccessPermission implements Serializable, Comparable<Regi
                return PermissionType.OWNER.equals(permissionType);
        }
 
+       public boolean isMissing() {
+               return PermissionType.MISSING.equals(permissionType);
+       }
+       
        @Override
        public int compareTo(RegistrantAccessPermission p) {
                switch (registrantType) {
index 7742d5d98e162d890a18aeedbc8f255ace989d97..0c9b9cc1b11074ef8d58391d6545ab69d47f4a77 100644 (file)
@@ -154,10 +154,6 @@ public class UserModel implements Principal, Serializable, Comparable<UserModel>
                                pType = PermissionType.REGEX;\r
                                source = registrant;\r
                        }\r
-                       if (AccessPermission.MISSING.equals(entry.getValue())) {\r
-                               // repository can not be found, permission is not editable\r
-                               editable = false;\r
-                       }\r
                        list.add(new RegistrantAccessPermission(registrant, entry.getValue(), pType, RegistrantType.REPOSITORY, source, editable));\r
                }\r
                Collections.sort(list);\r
index 1f338267348ade71582cbe2410ad21a897d3aa6f..4303b13498e80874731a4daae68e2c0724915267 100644 (file)
@@ -368,4 +368,6 @@ gb.ownerPermission = repository owner
 gb.administrator = admin\r
 gb.administratorPermission = Gitblit administrator\r
 gb.team = team\r
-gb.teamPermission = permission set by \"{0}\" team membership
\ No newline at end of file
+gb.teamPermission = permission set by \"{0}\" team membership\r
+gb.missing = missing!\r
+gb.missingPermission = the repository for this permission is missing!
\ No newline at end of file
index 45de1beff67bf7c649edcb6741de5e6735f84291..ea92293e8b692b1e4af3b0d1c80bddcc5bdf0f85 100644 (file)
@@ -33,7 +33,6 @@ import org.apache.wicket.model.CompoundPropertyModel;
 import org.apache.wicket.model.Model;\r
 import org.apache.wicket.model.util.CollectionModel;\r
 import org.apache.wicket.model.util.ListModel;\r
-import org.slf4j.LoggerFactory;\r
 \r
 import com.gitblit.Constants.PermissionType;\r
 import com.gitblit.Constants.RegistrantType;\r
@@ -113,7 +112,8 @@ public class EditUserPage extends RootSubPage {
                                // property of a repository.\r
                                RepositoryModel rm = GitBlit.self().getRepositoryModel(permission.registrant);\r
                                if (rm == null) {\r
-                                       LoggerFactory.getLogger(getClass()).error("Missing repository " + permission.registrant);\r
+                                       permission.permissionType = PermissionType.MISSING;\r
+                                       permission.mutable = false;\r
                                        continue;\r
                                }\r
                                boolean isOwner = rm.isOwner(oldName);\r
index a34ac71fa8e380c4103ccae4ba232501012316b6..9431df8f2bb05be9d0fb1cf4276a5cf45b88bd42 100644 (file)
@@ -89,14 +89,14 @@ public class RegistrantPermissionsPanel extends BasePanel {
                                final RegistrantAccessPermission entry = item.getModelObject();
                                if (RegistrantType.REPOSITORY.equals(entry.registrantType)) {
                                        String repoName = StringUtils.stripDotGit(entry.registrant);
-                                       if (StringUtils.findInvalidCharacter(repoName) == null) {
+                                       if (!entry.isMissing() && StringUtils.findInvalidCharacter(repoName) == null) {
                                                // repository, strip .git and show swatch
                                                Label registrant = new Label("registrant", repoName);
                                                WicketUtils.setCssClass(registrant, "repositorySwatch");
                                                WicketUtils.setCssBackground(registrant, repoName);
                                                item.add(registrant);
                                        } else {
-                                               // likely a regex
+                                               // regex or missing
                                                Label label = new Label("registrant", entry.registrant);
                                                WicketUtils.setCssStyle(label, "font-weight: bold;");
                                                item.add(label);
@@ -147,7 +147,16 @@ public class RegistrantPermissionsPanel extends BasePanel {
                                        item.add(regex);
                                        break;
                                default:
-                                       item.add(new Label("pType", "").setVisible(false));
+                                       if (entry.isMissing()) {
+                                               // repository is missing, this permission will be removed on save
+                                               Label missing = new Label("pType", getString("gb.missing"));
+                                               WicketUtils.setCssClass(missing, "label label-important");
+                                               WicketUtils.setHtmlTooltip(missing, getString("gb.missingPermission"));
+                                               item.add(missing);
+                                       } else {
+                                               // standard permission
+                                               item.add(new Label("pType", "").setVisible(false));
+                                       }
                                        break;
                                }