<tr><td>Gitblit v0.7.0</td><td>1 (inferred version)</td></tr>\r
<tr><td>Gitblit v0.8.0</td><td>2</td></tr>\r
<tr><td>Gitblit v0.9.0 - v1.0.0</td><td>3</td></tr>\r
-<tr><td>Gitblit v1.1.0+</td><td>4</td></tr>\r
+<tr><td>Gitblit v1.1.0</td><td>4</td></tr>\r
+<tr><td>Gitblit v1.2.0+</td><td>5</td></tr>\r
</tbody>\r
</table>\r
\r
+#### Protocol Version 5\r
+\r
+- *SET_REPOSITORY_MEMBERS* will reject all calls because this would elevate all discrete permissions to RW+ \r
+Use *SET_REPOSITORY_MEMBER_PERMISSIONS* instead.\r
+- *SET_REPOSITORY_TEAMS* will reject all calls because this would elevate all discrete permissions to RW+ \r
+Use *SET_REPOSITORY_TEAM_PERMISSIONS* instead.\r
+\r
### RPC Request and Response Types\r
<table class="table">\r
<tr><th colspan='2'>url parameters</th><th rowspan='2'>required<br/>user<br/>permission</th><th rowspan='2'>protocol<br/>version</th><th colspan='2'>json</th></tr>\r
<tr><td>EDIT_TEAM</td><td>team name</td><td><em>admin</em></td><td>2</td><td>TeamModel</td><td>-</td></tr>\r
<tr><td>DELETE_TEAM</td><td>team name</td><td><em>admin</em></td><td>2</td><td>-</td><td>-</td></tr>\r
<tr><td>LIST_REPOSITORY_MEMBERS</td><td>repository name</td><td><em>admin</em></td><td>1</td><td>-</td><td>List<String></td></tr>\r
-<tr><td>SET_REPOSITORY_MEMBERS</td><td>repository name</td><td><em>admin</em></td><td>1</td><td>List<String></td><td>-</td></tr>\r
+<tr><td><s>SET_REPOSITORY_MEMBERS</s></td><td><s>repository name</s></td><td><em><s>admin</s></em></td><td><s>1</s></td><td><s>List<String></s></td><td>-</td></tr>\r
+<tr><td>LIST_REPOSITORY_MEMBER_PERMISSIONS</td><td>repository name</td><td><em>admin</em></td><td>5</td><td>-</td><td>List<String></td></tr>\r
+<tr><td>SET_REPOSITORY_MEMBER_PERMISSIONS</td><td>repository name</td><td><em>admin</em></td><td>5</td><td>List<String></td><td>-</td></tr>\r
<tr><td>LIST_REPOSITORY_TEAMS</td><td>repository name</td><td><em>admin</em></td><td>2</td><td>-</td><td>List<String></td></tr>\r
-<tr><td>SET_REPOSITORY_TEAMS</td><td>repository name</td><td><em>admin</em></td><td>2</td><td>List<String></td><td>-</td></tr>\r
+<tr><td><s>SET_REPOSITORY_TEAMS</s></td><td><s>repository name</s></td><td><em><s>admin</s></em></td><td><s>2</s></td><td><s>List<String></s></td><td>-</td></tr>\r
+<tr><td>LIST_REPOSITORY_TEAM_PERMISSIONS</td><td>repository name</td><td><em>admin</em></td><td>5</td><td>-</td><td>List<String></td></tr>\r
+<tr><td>SET_REPOSITORY_TEAM_PERMISSIONS</td><td>repository name</td><td><em>admin</em></td><td>5</td><td>List<String></td><td>-</td></tr>\r
<tr><td>LIST_SETTINGS</td><td>-</td><td><em>admin</em></td><td>1</td><td>-</td><td>ServerSettings (management keys)</td></tr>\r
<tr><td>CLEAR_REPOSITORY_CACHE</td><td>-</td><td><em>-</em></td><td>4</td><td>-</td><td>-</td></tr>\r
<tr><td colspan='6'><em>web.enableRpcAdministration=true</em></td></tr>\r
## Release History\r
\r
-<div class="alert alert-error">\r
+<div class="alert alert-info">\r
<h4>Update Note</h4>\r
-If you are updating from an earlier release AND you have indexed branches with the Lucene indexing feature, you need to be aware that this release will completely re-index your repositories. Please be sure to provide ample heap resources as appropriate for your installation.\r
+The permissions model has changed in this release.\r
+<p>\r
+If you are updating your server, you must also update any Gitblit Manager and Federation Client installs to 1.2.0 as well. The data model used by the RPC mechanism has changed slightly for the new permissions infrastructure.\r
</div>\r
\r
### Current Release\r
\r
### Older Releases\r
\r
+<div class="alert alert-error">\r
+<h4>Update Note</h4>\r
+If you are updating from an earlier release AND you have indexed branches with the Lucene indexing feature, you need to be aware that this release will completely re-index your repositories. Please be sure to provide ample heap resources as appropriate for your installation.\r
+</div>\r
+\r
**1.1.0** *released 2012-08-25*\r
\r
#### fixes\r
}\r
config.setStringList(USER, model.username, ROLE, roles);\r
\r
- // repository memberships\r
- if (model.permissions == null) {\r
- // null check on "final" repositories because JSON-sourced UserModel\r
- // can have a null repositories object\r
- if (!ArrayUtils.isEmpty(model.repositories)) {\r
- config.setStringList(USER, model.username, REPOSITORY, new ArrayList<String>(\r
- model.repositories));\r
- }\r
- } else {\r
- // discrete repository permissions\r
+ // discrete repository permissions\r
+ if (model.permissions != null) {\r
List<String> permissions = new ArrayList<String>();\r
for (Map.Entry<String, AccessPermission> entry : model.permissions.entrySet()) {\r
if (entry.getValue().exceeds(AccessPermission.NONE)) {\r
LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, \r
LIST_TEAMS, CREATE_TEAM, EDIT_TEAM, DELETE_TEAM,\r
LIST_REPOSITORY_MEMBERS, SET_REPOSITORY_MEMBERS, LIST_REPOSITORY_TEAMS, SET_REPOSITORY_TEAMS, \r
+ LIST_REPOSITORY_MEMBER_PERMISSIONS, SET_REPOSITORY_MEMBER_PERMISSIONS, LIST_REPOSITORY_TEAM_PERMISSIONS, SET_REPOSITORY_TEAM_PERMISSIONS, \r
LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS, LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS,\r
EDIT_SETTINGS, LIST_STATUS;\r
\r
}\r
}\r
\r
+ public static enum RegistrantType {\r
+ REPOSITORY, USER, TEAM;\r
+ }\r
+ \r
@Documented\r
@Retention(RetentionPolicy.RUNTIME)\r
public @interface Unused {\r
// reparent all repository permissions if the local\r
// repositories are stored within subfolders\r
if (!StringUtils.isEmpty(registrationFolder)) {\r
- if (user.permissions != null && user.permissions.size() > 0) {\r
+ if (user.permissions != null) {\r
// pulling from >= 1.2 version\r
Map<String, AccessPermission> copy = new HashMap<String, AccessPermission>(user.permissions);\r
user.permissions.clear();\r
GitBlit.self().updateUserModel(user.username, user, true);\r
} else {\r
// update repository permissions of local user\r
- if (user.permissions != null && user.permissions.size() > 0) {\r
+ if (user.permissions != null) {\r
// pulling from >= 1.2 version\r
Map<String, AccessPermission> copy = new HashMap<String, AccessPermission>(user.permissions);\r
for (Map.Entry<String, AccessPermission> entry : copy.entrySet()) {\r
UserModel oldUser = getUserModel(username);\r
List<String> roles;\r
if (model.permissions == null) {\r
- // legacy, use repository list\r
- roles = new ArrayList<String>(model.repositories);\r
+ roles = new ArrayList<String>();\r
} else {\r
// discrete repository permissions\r
roles = new ArrayList<String>();\r
import com.gitblit.Constants.FederationRequest;\r
import com.gitblit.Constants.FederationStrategy;\r
import com.gitblit.Constants.FederationToken;\r
+import com.gitblit.Constants.RegistrantType;\r
import com.gitblit.models.FederationModel;\r
import com.gitblit.models.FederationProposal;\r
import com.gitblit.models.FederationSet;\r
import com.gitblit.models.ForkModel;\r
import com.gitblit.models.Metric;\r
import com.gitblit.models.ProjectModel;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.SearchResult;\r
import com.gitblit.models.ServerSettings;\r
import com.gitblit.models.ServerStatus;\r
import com.gitblit.models.SettingModel;\r
-import com.gitblit.models.TeamAccessPermission;\r
import com.gitblit.models.TeamModel;\r
-import com.gitblit.models.UserAccessPermission;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.ByteFormat;\r
* @param repository\r
* @return a list of User-AccessPermission tuples\r
*/\r
- public List<UserAccessPermission> getUserAccessPermissions(RepositoryModel repository) {\r
- List<UserAccessPermission> permissions = new ArrayList<UserAccessPermission>();\r
+ public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) {\r
+ List<RegistrantAccessPermission> permissions = new ArrayList<RegistrantAccessPermission>();\r
for (String user : userService.getUsernamesForRepositoryRole(repository.name)) {\r
AccessPermission ap = userService.getUserModel(user).getRepositoryPermission(repository);\r
- permissions.add(new UserAccessPermission(user, ap));\r
+ permissions.add(new RegistrantAccessPermission(user, ap, RegistrantType.USER));\r
}\r
return permissions;\r
}\r
* @param permissions\r
* @return true if the user models have been updated\r
*/\r
- public boolean setUserAccessPermissions(RepositoryModel repository, List<UserAccessPermission> permissions) {\r
+ public boolean setUserAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) {\r
List<UserModel> users = new ArrayList<UserModel>();\r
- for (UserAccessPermission up : permissions) {\r
- UserModel user = userService.getUserModel(up.user);\r
+ for (RegistrantAccessPermission up : permissions) {\r
+ UserModel user = userService.getUserModel(up.registrant);\r
user.setRepositoryPermission(repository.name, up.permission);\r
users.add(user);\r
}\r
*/\r
@Deprecated\r
public boolean setRepositoryUsers(RepositoryModel repository, List<String> repositoryUsers) {\r
- return userService.setUsernamesForRepositoryRole(repository.name, repositoryUsers);\r
+ // rejects all changes since 1.2.0 because this would elevate\r
+ // all discrete access permissions to RW+\r
+ return false;\r
}\r
\r
/**\r
* @param repository\r
* @return a list of Team-AccessPermission tuples\r
*/\r
- public List<TeamAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {\r
- List<TeamAccessPermission> permissions = new ArrayList<TeamAccessPermission>();\r
+ public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {\r
+ List<RegistrantAccessPermission> permissions = new ArrayList<RegistrantAccessPermission>();\r
for (String team : userService.getTeamnamesForRepositoryRole(repository.name)) {\r
AccessPermission ap = userService.getTeamModel(team).getRepositoryPermission(repository);\r
- permissions.add(new TeamAccessPermission(team, ap));\r
+ permissions.add(new RegistrantAccessPermission(team, ap, RegistrantType.TEAM));\r
}\r
return permissions;\r
}\r
* @param permissions\r
* @return true if the team models have been updated\r
*/\r
- public boolean setTeamAccessPermissions(RepositoryModel repository, List<TeamAccessPermission> permissions) {\r
+ public boolean setTeamAccessPermissions(RepositoryModel repository, Collection<RegistrantAccessPermission> permissions) {\r
List<TeamModel> teams = new ArrayList<TeamModel>();\r
- for (TeamAccessPermission tp : permissions) {\r
- TeamModel team = userService.getTeamModel(tp.team);\r
+ for (RegistrantAccessPermission tp : permissions) {\r
+ TeamModel team = userService.getTeamModel(tp.registrant);\r
team.setRepositoryPermission(repository.name, tp.permission);\r
teams.add(team);\r
}\r
}\r
\r
/**\r
- * Returns the list of all teams who are allowed to bypass the access\r
- * restriction placed on the specified repository.\r
+ * Returns the list of all teams who have an explicit access permission for\r
+ * the specified repository.\r
* \r
* @see IUserService.getTeamnamesForRepositoryRole(String)\r
* @param repository\r
- * @return list of all teamnames that can bypass the access restriction\r
+ * @return list of all teamnames with explicit access permissions to the repository\r
*/\r
- @Deprecated\r
public List<String> getRepositoryTeams(RepositoryModel repository) {\r
return userService.getTeamnamesForRepositoryRole(repository.name);\r
}\r
*/\r
@Deprecated\r
public boolean setRepositoryTeams(RepositoryModel repository, List<String> repositoryTeams) {\r
- return userService.setTeamnamesForRepositoryRole(repository.name, repositoryTeams);\r
+ // rejects all changes since 1.2.0 because this would elevate\r
+ // all discrete access permissions to RW+\r
+ return false;\r
}\r
\r
/**\r
import org.eclipse.jgit.lib.Repository;\r
\r
import com.gitblit.Constants.RpcRequest;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.RefModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.ServerSettings;\r
\r
private static final long serialVersionUID = 1L;\r
\r
- public static final int PROTOCOL_VERSION = 4;\r
+ public static final int PROTOCOL_VERSION = 5;\r
\r
public RpcServlet() {\r
super();\r
RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
result = GitBlit.self().getRepositoryUsers(model);\r
} else if (RpcRequest.SET_REPOSITORY_MEMBERS.equals(reqType)) {\r
- // update repository access list\r
+ // rejected since 1.2.0\r
+ response.setStatus(failureCode);\r
+ } else if (RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
+ // get repository member permissions\r
RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
- Collection<String> names = deserialize(request, response, RpcUtils.NAMES_TYPE);\r
- List<String> users = new ArrayList<String>(names);\r
- if (!GitBlit.self().setRepositoryUsers(model, users)) {\r
- response.setStatus(failureCode);\r
- }\r
+ result = GitBlit.self().getUserAccessPermissions(model);\r
+ } else if (RpcRequest.SET_REPOSITORY_MEMBER_PERMISSIONS.equals(reqType)) {\r
+ // set the repository permissions for the specified users\r
+ RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
+ Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
+ result = GitBlit.self().setUserAccessPermissions(model, permissions);\r
} else if (RpcRequest.LIST_REPOSITORY_TEAMS.equals(reqType)) {\r
// get repository teams\r
RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
result = GitBlit.self().getRepositoryTeams(model);\r
} else if (RpcRequest.SET_REPOSITORY_TEAMS.equals(reqType)) {\r
- // update repository team access list\r
+ // rejected since 1.2.0\r
+ response.setStatus(failureCode);\r
+ } else if (RpcRequest.LIST_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
+ // get repository team permissions\r
RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
- Collection<String> names = deserialize(request, response, RpcUtils.NAMES_TYPE);\r
- List<String> teams = new ArrayList<String>(names);\r
- if (!GitBlit.self().setRepositoryTeams(model, teams)) {\r
- response.setStatus(failureCode);\r
- }\r
+ result = GitBlit.self().getTeamAccessPermissions(model);\r
+ } else if (RpcRequest.SET_REPOSITORY_TEAM_PERMISSIONS.equals(reqType)) {\r
+ // set the repository permissions for the specified teams\r
+ RepositoryModel model = GitBlit.self().getRepositoryModel(objectName);\r
+ Collection<RegistrantAccessPermission> permissions = deserialize(request, response, RpcUtils.REGISTRANT_PERMISSIONS_TYPE);\r
+ result = GitBlit.self().setTeamAccessPermissions(model, permissions);\r
} else if (RpcRequest.LIST_FEDERATION_REGISTRATIONS.equals(reqType)) {\r
// return the list of federation registrations\r
if (allowAdmin) {\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.Constants.AuthorizationControl;\r
import com.gitblit.Constants.FederationStrategy;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.StringUtils;\r
\r
private JComboBox headRefField;\r
\r
- private JPalette<String> usersPalette;\r
+ private RegistrantPermissionsPanel usersPalette;\r
\r
private JPalette<String> setsPalette;\r
\r
- private JPalette<String> teamsPalette;\r
+ private RegistrantPermissionsPanel teamsPalette;\r
\r
private JPalette<String> indexedBranchesPalette;\r
\r
clonePushPanel\r
.add(newFieldPanel(Translation.get("gb.verifyCommitter"), verifyCommitter));\r
\r
- usersPalette = new JPalette<String>();\r
+ usersPalette = new RegistrantPermissionsPanel();\r
JPanel northAccessPanel = new JPanel(new BorderLayout(5, 5));\r
northAccessPanel.add(newFieldPanel(Translation.get("gb.accessRestriction"),\r
accessRestriction), BorderLayout.NORTH);\r
\r
JPanel accessPanel = new JPanel(new BorderLayout(5, 5));\r
accessPanel.add(northAccessPanel, BorderLayout.NORTH);\r
- accessPanel.add(newFieldPanel(Translation.get("gb.permittedUsers"),\r
+ accessPanel.add(newFieldPanel(Translation.get("gb.userPermissions"),\r
usersPalette), BorderLayout.CENTER);\r
\r
- teamsPalette = new JPalette<String>();\r
+ teamsPalette = new RegistrantPermissionsPanel();\r
JPanel teamsPanel = new JPanel(new BorderLayout(5, 5));\r
teamsPanel.add(\r
- newFieldPanel(Translation.get("gb.permittedTeams"),\r
+ newFieldPanel(Translation.get("gb.teamPermissions"),\r
teamsPalette), BorderLayout.CENTER);\r
\r
setsPalette = new JPalette<String>();\r
this.allowNamed.setSelected(!authenticated);\r
}\r
\r
- public void setUsers(String owner, List<String> all, List<String> selected) {\r
+ public void setUsers(String owner, List<String> all, List<RegistrantAccessPermission> permissions) {\r
ownerField.setModel(new DefaultComboBoxModel(all.toArray()));\r
if (!StringUtils.isEmpty(owner)) {\r
ownerField.setSelectedItem(owner);\r
}\r
- usersPalette.setObjects(all, selected);\r
+ usersPalette.setObjects(all, permissions);\r
}\r
\r
- public void setTeams(List<String> all, List<String> selected) {\r
- teamsPalette.setObjects(all, selected);\r
+ public void setTeams(List<String> all, List<RegistrantAccessPermission> permissions) {\r
+ teamsPalette.setObjects(all, permissions);\r
}\r
\r
public void setRepositories(List<RepositoryModel> repositories) {\r
return repository;\r
}\r
\r
- public List<String> getPermittedUsers() {\r
- return usersPalette.getSelections();\r
+ public List<RegistrantAccessPermission> getUserAccessPermissions() {\r
+ return usersPalette.getPermissions();\r
}\r
\r
- public List<String> getPermittedTeams() {\r
- return teamsPalette.getSelections();\r
+ public List<RegistrantAccessPermission> getTeamAccessPermissions() {\r
+ return teamsPalette.getPermissions();\r
}\r
\r
public void setCustomFields(RepositoryModel repository, Map<String, String> customFields) {\r
import javax.swing.KeyStroke;\r
\r
import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.ServerSettings;\r
import com.gitblit.models.TeamModel;\r
\r
private JTextField mailingListsField;\r
\r
- private JPalette<String> repositoryPalette;\r
+ private RegistrantPermissionsPanel repositoryPalette;\r
\r
private JPalette<String> userPalette;\r
\r
fieldsPanel.add(newFieldPanel(Translation.get("gb.mailingLists"), mailingListsField));\r
\r
final Insets _insets = new Insets(5, 5, 5, 5);\r
- repositoryPalette = new JPalette<String>();\r
+ repositoryPalette = new RegistrantPermissionsPanel();\r
userPalette = new JPalette<String>();\r
userPalette.setEnabled(settings.supportsTeamMembershipChanges);\r
\r
team.mailingLists.addAll(list);\r
}\r
\r
- team.repositories.clear();\r
- team.repositories.addAll(repositoryPalette.getSelections());\r
+ for (RegistrantAccessPermission rp : repositoryPalette.getPermissions()) {\r
+ team.setRepositoryPermission(rp.registrant, rp.permission);\r
+ }\r
\r
team.users.clear();\r
team.users.addAll(userPalette.getSelections());\r
}\r
}\r
\r
- public void setRepositories(List<RepositoryModel> repositories, List<String> selected) {\r
+ public void setRepositories(List<RepositoryModel> repositories, List<RegistrantAccessPermission> permissions) {\r
List<String> restricted = new ArrayList<String>();\r
for (RepositoryModel repo : repositories) {\r
if (repo.accessRestriction.exceeds(AccessRestrictionType.NONE)) {\r
restricted.add(repo.name);\r
}\r
}\r
- StringUtils.sortRepositorynames(restricted);\r
- if (selected != null) {\r
- StringUtils.sortRepositorynames(selected);\r
+ \r
+ // remove repositories for which team already has a permission\r
+ for (RegistrantAccessPermission rp : permissions) {\r
+ restricted.remove(rp.registrant);\r
}\r
- repositoryPalette.setObjects(restricted, selected);\r
+\r
+ StringUtils.sortRepositorynames(restricted);\r
+ repositoryPalette.setObjects(restricted, permissions);\r
}\r
\r
public void setUsers(List<String> users, List<String> selected) {\r
\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.models.ServerSettings;\r
import com.gitblit.models.TeamModel;\r
\r
private JCheckBox notFederatedCheckbox;\r
\r
- private JPalette<String> repositoryPalette;\r
+ private RegistrantPermissionsPanel repositoryPalette;\r
\r
private JPalette<TeamModel> teamsPalette;\r
\r
notFederatedCheckbox));\r
\r
final Insets _insets = new Insets(5, 5, 5, 5);\r
- repositoryPalette = new JPalette<String>();\r
+ repositoryPalette = new RegistrantPermissionsPanel();\r
teamsPalette = new JPalette<TeamModel>();\r
teamsPalette.setEnabled(settings.supportsTeamMembershipChanges);\r
\r
user.canCreate = canCreateCheckbox.isSelected();\r
user.excludeFromFederation = notFederatedCheckbox.isSelected();\r
\r
- user.repositories.clear();\r
- user.repositories.addAll(repositoryPalette.getSelections());\r
+ for (RegistrantAccessPermission rp : repositoryPalette.getPermissions()) {\r
+ user.setRepositoryPermission(rp.registrant, rp.permission);\r
+ }\r
\r
user.teams.clear();\r
user.teams.addAll(teamsPalette.getSelections());\r
}\r
}\r
\r
- public void setRepositories(List<RepositoryModel> repositories, List<String> selected) {\r
+ public void setRepositories(List<RepositoryModel> repositories, List<RegistrantAccessPermission> permissions) {\r
List<String> restricted = new ArrayList<String>();\r
for (RepositoryModel repo : repositories) {\r
if (repo.accessRestriction.exceeds(AccessRestrictionType.NONE)) {\r
restricted.add(repo.name);\r
}\r
}\r
- StringUtils.sortRepositorynames(restricted);\r
- if (selected != null) {\r
- StringUtils.sortRepositorynames(selected);\r
+ // remove repositories for which user already has a permission\r
+ for (RegistrantAccessPermission rp : permissions) {\r
+ restricted.remove(rp.registrant);\r
}\r
- repositoryPalette.setObjects(restricted, selected);\r
+ \r
+ StringUtils.sortRepositorynames(restricted);\r
+ repositoryPalette.setObjects(restricted, permissions);\r
}\r
\r
public void setTeams(List<TeamModel> teams, List<TeamModel> selected) {\r
import com.gitblit.GitBlitException.UnauthorizedException;\r
import com.gitblit.GitBlitException.UnknownRequestException;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.FederationModel;\r
import com.gitblit.models.FeedEntryModel;\r
import com.gitblit.models.FeedModel;\r
public List<String> getPermittedUsernames(RepositoryModel repository) {\r
List<String> usernames = new ArrayList<String>();\r
for (UserModel user : this.allUsers) {\r
- if (user.repositories.contains(repository.name)) {\r
+ if (user.hasRepositoryPermission(repository.name)) {\r
usernames.add(user.username);\r
}\r
}\r
return usernames;\r
}\r
+ \r
+ public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) throws IOException {\r
+ return RpcUtils.getRepositoryMemberPermissions(repository, url, account, password);\r
+ }\r
+\r
+ public boolean setUserAccessPermissions(RepositoryModel repository, List<RegistrantAccessPermission> permissions) throws IOException {\r
+ return RpcUtils.setRepositoryMemberPermissions(repository, permissions, url, account, password);\r
+ }\r
\r
public List<TeamModel> getTeams() {\r
return allTeams;\r
public List<String> getPermittedTeamnames(RepositoryModel repository) {\r
List<String> teamnames = new ArrayList<String>();\r
for (TeamModel team : this.allTeams) {\r
- if (team.repositories.contains(repository.name)) {\r
+ if (team.hasRepositoryPermission(repository.name)) {\r
teamnames.add(team.name);\r
}\r
}\r
return teamnames;\r
}\r
+ \r
+ public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) throws IOException {\r
+ return RpcUtils.getRepositoryTeamPermissions(repository, url, account, password);\r
+ }\r
+\r
+ public boolean setTeamAccessPermissions(RepositoryModel repository, List<RegistrantAccessPermission> permissions) throws IOException {\r
+ return RpcUtils.setRepositoryTeamPermissions(repository, permissions, url, account, password);\r
+ }\r
\r
public TeamModel getTeamModel(String name) {\r
for (TeamModel team : allTeams) {\r
return allRepositories;\r
}\r
\r
- public boolean createRepository(RepositoryModel repository, List<String> permittedUsers)\r
+ public boolean createRepository(RepositoryModel repository, List<RegistrantAccessPermission> userPermissions)\r
throws IOException {\r
- return createRepository(repository, permittedUsers, null);\r
+ return createRepository(repository, userPermissions, null);\r
}\r
\r
- public boolean createRepository(RepositoryModel repository, List<String> permittedUsers,\r
- List<String> permittedTeams) throws IOException {\r
+ public boolean createRepository(RepositoryModel repository, List<RegistrantAccessPermission> userPermissions,\r
+ List<RegistrantAccessPermission> teamPermissions) throws IOException {\r
boolean success = true;\r
success &= RpcUtils.createRepository(repository, url, account, password);\r
- if (permittedUsers != null && permittedUsers.size() > 0) {\r
+ if (userPermissions != null && userPermissions.size() > 0) {\r
// if new repository has named members, set them\r
- success &= RpcUtils.setRepositoryMembers(repository, permittedUsers, url, account,\r
+ success &= RpcUtils.setRepositoryMemberPermissions(repository, userPermissions, url, account,\r
password);\r
}\r
- if (permittedTeams != null && permittedTeams.size() > 0) {\r
+ if (teamPermissions != null && teamPermissions.size() > 0) {\r
// if new repository has named teams, set them\r
- success &= RpcUtils.setRepositoryTeams(repository, permittedTeams, url, account,\r
+ success &= RpcUtils.setRepositoryTeamPermissions(repository, teamPermissions, url, account,\r
password);\r
}\r
return success;\r
}\r
\r
public boolean updateRepository(String name, RepositoryModel repository,\r
- List<String> permittedUsers) throws IOException {\r
- return updateRepository(name, repository, permittedUsers, null);\r
+ List<RegistrantAccessPermission> userPermissions) throws IOException {\r
+ return updateRepository(name, repository, userPermissions, null);\r
}\r
\r
public boolean updateRepository(String name, RepositoryModel repository,\r
- List<String> permittedUsers, List<String> permittedTeams) throws IOException {\r
+ List<RegistrantAccessPermission> userPermissions, List<RegistrantAccessPermission> teamPermissions) throws IOException {\r
boolean success = true;\r
success &= RpcUtils.updateRepository(name, repository, url, account, password);\r
// set the repository members\r
- if (permittedUsers != null) {\r
- success &= RpcUtils.setRepositoryMembers(repository, permittedUsers, url, account,\r
+ if (userPermissions != null) {\r
+ success &= RpcUtils.setRepositoryMemberPermissions(repository, userPermissions, url, account,\r
password);\r
}\r
- if (permittedTeams != null) {\r
- success &= RpcUtils.setRepositoryTeams(repository, permittedTeams, url, account,\r
+ if (teamPermissions != null) {\r
+ success &= RpcUtils.setRepositoryTeamPermissions(repository, teamPermissions, url, account,\r
password);\r
}\r
return success;\r
--- /dev/null
+/*\r
+ * Copyright 2012 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.awt.BorderLayout;\r
+import java.awt.Dimension;\r
+import java.awt.event.ActionEvent;\r
+import java.awt.event.ActionListener;\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import javax.swing.DefaultCellEditor;\r
+import javax.swing.DefaultComboBoxModel;\r
+import javax.swing.JButton;\r
+import javax.swing.JComboBox;\r
+import javax.swing.JPanel;\r
+import javax.swing.JScrollPane;\r
+import javax.swing.JTable;\r
+\r
+import com.gitblit.Constants.AccessPermission;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
+\r
+public class RegistrantPermissionsPanel extends JPanel {\r
+\r
+ private static final long serialVersionUID = 1L;\r
+ \r
+ private JTable permissionsTable;\r
+\r
+ private RegistrantPermissionsTableModel tableModel;\r
+\r
+ private DefaultComboBoxModel registrantModel;\r
+\r
+ private JComboBox registrantSelector;\r
+\r
+ private JComboBox permissionSelector;\r
+\r
+ private JButton addButton;\r
+\r
+ private JPanel addPanel;\r
+\r
+ public RegistrantPermissionsPanel() {\r
+ super(new BorderLayout(5, 5));\r
+ tableModel = new RegistrantPermissionsTableModel();\r
+ permissionsTable = new JTable(tableModel);\r
+ permissionsTable.setPreferredScrollableViewportSize(new Dimension(400, 150));\r
+ JScrollPane jsp = new JScrollPane(permissionsTable);\r
+ add(jsp, BorderLayout.CENTER);\r
+ \r
+ permissionsTable.getColumnModel().getColumn(RegistrantPermissionsTableModel.Columns.Permission.ordinal())\r
+ .setCellEditor(new AccessPermissionEditor());\r
+ \r
+ registrantModel = new DefaultComboBoxModel();\r
+ registrantSelector = new JComboBox(registrantModel);\r
+ permissionSelector = new JComboBox(AccessPermission.NEWPERMISSIONS);\r
+ addButton = new JButton(Translation.get("gb.add"));\r
+ addButton.addActionListener(new ActionListener() {\r
+ public void actionPerformed(ActionEvent e) {\r
+ if (registrantSelector.getSelectedIndex() < 0) {\r
+ return;\r
+ }\r
+ if (permissionSelector.getSelectedIndex() < 0) {\r
+ return;\r
+ }\r
+ \r
+ RegistrantAccessPermission rp = new RegistrantAccessPermission();\r
+ rp.registrant = registrantSelector.getSelectedItem().toString();\r
+ rp.permission = (AccessPermission) permissionSelector.getSelectedItem();\r
+ tableModel.permissions.add(rp);\r
+ \r
+ registrantModel.removeElement(rp.registrant);\r
+ registrantSelector.setSelectedIndex(-1);\r
+ registrantSelector.invalidate();\r
+ addPanel.setVisible(registrantModel.getSize() > 0);\r
+ \r
+ tableModel.fireTableDataChanged();\r
+ }\r
+ });\r
+ \r
+ addPanel = new JPanel();\r
+ addPanel.add(registrantSelector);\r
+ addPanel.add(permissionSelector);\r
+ addPanel.add(addButton);\r
+ add(addPanel, BorderLayout.SOUTH);\r
+ }\r
+\r
+ @Override\r
+ public void setEnabled(boolean enabled) {\r
+ super.setEnabled(enabled);\r
+ permissionsTable.setEnabled(false);\r
+ }\r
+\r
+ public void setObjects(List<String> registrants, List<RegistrantAccessPermission> permissions) {\r
+ List<String> filtered;\r
+ if (registrants == null) {\r
+ filtered = new ArrayList<String>();\r
+ } else {\r
+ filtered = new ArrayList<String>(registrants);\r
+ }\r
+ if (permissions == null) {\r
+ permissions = new ArrayList<RegistrantAccessPermission>();\r
+ }\r
+ for (RegistrantAccessPermission rp : permissions) {\r
+ filtered.remove(rp.registrant);\r
+ }\r
+ for (String registrant : filtered) {\r
+ registrantModel.addElement(registrant);\r
+ }\r
+ tableModel.setPermissions(permissions);\r
+ \r
+ registrantSelector.setSelectedIndex(-1);\r
+ permissionSelector.setSelectedIndex(-1);\r
+ addPanel.setVisible(filtered.size() > 0);\r
+ }\r
+\r
+ public List<RegistrantAccessPermission> getPermissions() {\r
+ return tableModel.permissions;\r
+ }\r
+ \r
+ private class AccessPermissionEditor extends DefaultCellEditor {\r
+ \r
+ private static final long serialVersionUID = 1L;\r
+\r
+ public AccessPermissionEditor() {\r
+ super(new JComboBox(AccessPermission.values()));\r
+ }\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright 2012 gitblit.com.\r
+ *\r
+ * Licensed under the Apache License, Version 2.0 (the "License");\r
+ * you may not use this file except in compliance with the License.\r
+ * You may obtain a copy of the License at\r
+ *\r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS,\r
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ * See the License for the specific language governing permissions and\r
+ * limitations under the License.\r
+ */\r
+package com.gitblit.client;\r
+\r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
+import javax.swing.table.AbstractTableModel;\r
+\r
+import com.gitblit.Constants.AccessPermission;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
+\r
+/**\r
+ * Table model of a registrant permissions.\r
+ * \r
+ * @author James Moger\r
+ * \r
+ */\r
+public class RegistrantPermissionsTableModel extends AbstractTableModel {\r
+\r
+ private static final long serialVersionUID = 1L;\r
+\r
+ List<RegistrantAccessPermission> permissions;\r
+\r
+ enum Columns {\r
+ Registrant, Permission;\r
+\r
+ @Override\r
+ public String toString() {\r
+ return name().replace('_', ' ');\r
+ }\r
+ }\r
+\r
+ public RegistrantPermissionsTableModel() {\r
+ this(new ArrayList<RegistrantAccessPermission>());\r
+ }\r
+\r
+ public RegistrantPermissionsTableModel(List<RegistrantAccessPermission> list) {\r
+ setPermissions(list);\r
+ }\r
+\r
+ public void setPermissions(List<RegistrantAccessPermission> list) {\r
+ this.permissions = list;\r
+ }\r
+\r
+ @Override\r
+ public int getRowCount() {\r
+ return permissions.size();\r
+ }\r
+\r
+ @Override\r
+ public int getColumnCount() {\r
+ return Columns.values().length;\r
+ }\r
+\r
+ @Override\r
+ public String getColumnName(int column) {\r
+ Columns col = Columns.values()[column];\r
+ switch (col) {\r
+ case Registrant:\r
+ return Translation.get("gb.name");\r
+ case Permission:\r
+ return Translation.get("gb.permission");\r
+ }\r
+ return "";\r
+ }\r
+\r
+ /**\r
+ * Returns <code>Object.class</code> regardless of <code>columnIndex</code>.\r
+ * \r
+ * @param columnIndex\r
+ * the column being queried\r
+ * @return the Object.class\r
+ */\r
+ public Class<?> getColumnClass(int columnIndex) {\r
+ if (columnIndex == Columns.Permission.ordinal()) {\r
+ return AccessPermission.class;\r
+ }\r
+ return String.class;\r
+ }\r
+ \r
+ @Override\r
+ public boolean isCellEditable(int rowIndex, int columnIndex) {\r
+ return columnIndex == Columns.Permission.ordinal();\r
+ }\r
+\r
+ @Override\r
+ public Object getValueAt(int rowIndex, int columnIndex) {\r
+ RegistrantAccessPermission rp = permissions.get(rowIndex);\r
+ Columns col = Columns.values()[columnIndex];\r
+ switch (col) {\r
+ case Registrant:\r
+ return rp.registrant;\r
+ case Permission:\r
+ return rp.permission;\r
+ }\r
+ return null;\r
+ }\r
+ \r
+ @Override\r
+ public void setValueAt(Object o, int rowIndex, int columnIndex) {\r
+ RegistrantAccessPermission rp = permissions.get(rowIndex);\r
+ if (columnIndex == Columns.Permission.ordinal()) {\r
+ rp.permission = (AccessPermission) o;\r
+ }\r
+ }\r
+}\r
import com.gitblit.Constants;\r
import com.gitblit.Constants.RpcRequest;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.FeedModel;\r
import com.gitblit.models.RepositoryModel;\r
import com.gitblit.utils.StringUtils;\r
gitblit.getPostReceiveScriptsInherited(null), null);\r
dialog.setVisible(true);\r
final RepositoryModel newRepository = dialog.getRepository();\r
- final List<String> permittedUsers = dialog.getPermittedUsers();\r
- final List<String> permittedTeams = dialog.getPermittedTeams();\r
+ final List<RegistrantAccessPermission> permittedUsers = dialog.getUserAccessPermissions();\r
+ final List<RegistrantAccessPermission> permittedTeams = dialog.getTeamAccessPermissions();\r
if (newRepository == null) {\r
return;\r
}\r
repository);\r
dialog.setLocationRelativeTo(RepositoriesPanel.this);\r
List<String> usernames = gitblit.getUsernames();\r
- List<String> members = gitblit.getPermittedUsernames(repository);\r
- dialog.setUsers(repository.owner, usernames, members);\r
- dialog.setTeams(gitblit.getTeamnames(), gitblit.getPermittedTeamnames(repository));\r
- dialog.setRepositories(gitblit.getRepositories());\r
+ try {\r
+ List<RegistrantAccessPermission> members = gitblit.getUserAccessPermissions(repository);\r
+ dialog.setUsers(repository.owner, usernames, members);\r
+ dialog.setTeams(gitblit.getTeamnames(), gitblit.getTeamAccessPermissions(repository));\r
+ dialog.setRepositories(gitblit.getRepositories());\r
+ } catch (IOException e) {\r
+ // TODO\r
+ }\r
dialog.setFederationSets(gitblit.getFederationSets(), repository.federationSets);\r
List<String> allLocalBranches = new ArrayList<String>();\r
allLocalBranches.add(Constants.DEFAULT_BRANCH);\r
}\r
dialog.setVisible(true);\r
final RepositoryModel revisedRepository = dialog.getRepository();\r
- final List<String> permittedUsers = dialog.getPermittedUsers();\r
- final List<String> permittedTeams = dialog.getPermittedTeams();\r
+ final List<RegistrantAccessPermission> permittedUsers = dialog.getUserAccessPermissions();\r
+ final List<RegistrantAccessPermission> permittedTeams = dialog.getTeamAccessPermissions();\r
if (revisedRepository == null) {\r
return;\r
}\r
gitblit.getSettings());\r
dialog.setLocationRelativeTo(TeamsPanel.this);\r
dialog.setTeams(gitblit.getTeams());\r
- dialog.setRepositories(gitblit.getRepositories(), new ArrayList<String>(team.repositories));\r
+ dialog.setRepositories(gitblit.getRepositories(), team.getRepositoryPermissions());\r
dialog.setUsers(gitblit.getUsernames(), team.users == null ? null : new ArrayList<String>(\r
team.users));\r
dialog.setPreReceiveScripts(gitblit.getPreReceiveScriptsUnused(null),\r
gitblit.getSettings());\r
dialog.setLocationRelativeTo(UsersPanel.this);\r
dialog.setUsers(gitblit.getUsers());\r
- dialog.setRepositories(gitblit.getRepositories(), new ArrayList<String>(user.repositories));\r
+ dialog.setRepositories(gitblit.getRepositories(), user.getRepositoryPermissions());\r
dialog.setTeams(gitblit.getTeams(), user.teams == null ? null : new ArrayList<TeamModel>(\r
user.teams));\r
dialog.setVisible(true);\r
return (model.teams == null || model.teams.size() == 0) ? "" : String\r
.valueOf(model.teams.size());\r
case Repositories:\r
- return (model.repositories == null || model.repositories.size() == 0) ? "" : String\r
- .valueOf(model.repositories.size());\r
+ return (model.permissions == null || model.permissions.size() == 0) ? "" : String\r
+ .valueOf(model.permissions.size());\r
}\r
return null;\r
}\r
--- /dev/null
+/*
+ * Copyright 2012 gitblit.com.
+ *
+ * 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.gitblit.models;
+
+import java.io.Serializable;
+
+import com.gitblit.Constants.AccessPermission;
+import com.gitblit.Constants.RegistrantType;
+import com.gitblit.utils.StringUtils;
+
+/**
+ * Represents a Registrant-AccessPermission tuple.
+ *
+ * @author James Moger
+ */
+public class RegistrantAccessPermission implements Serializable, Comparable<RegistrantAccessPermission> {
+
+ private static final long serialVersionUID = 1L;
+
+ public String registrant;
+ public AccessPermission permission;
+ public RegistrantType type;
+
+ public RegistrantAccessPermission() {
+ }
+
+ public RegistrantAccessPermission(String registrant, AccessPermission permission, RegistrantType type) {
+ this.registrant = registrant;
+ this.permission = permission;
+ this.type = type;
+ }
+
+ @Override
+ public int compareTo(RegistrantAccessPermission p) {
+ switch (type) {
+ case REPOSITORY:
+ return StringUtils.compareRepositoryNames(registrant, p.registrant);
+ default:
+ return registrant.toLowerCase().compareTo(p.registrant.toLowerCase());
+ }
+ }
+
+ @Override
+ public String toString() {
+ return permission.asRole(registrant);
+ }
+}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2012 gitblit.com.
- *
- * 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.gitblit.models;
-
-import java.io.Serializable;
-
-import com.gitblit.Constants.AccessPermission;
-import com.gitblit.utils.StringUtils;
-
-/**
- * Represents a Repository-AccessPermission tuple.
- *
- * @author James Moger
- */
-public class RepositoryAccessPermission implements Serializable, Comparable<RepositoryAccessPermission> {
-
- private static final long serialVersionUID = 1L;
-
- public String repository;
- public AccessPermission permission;
-
- public RepositoryAccessPermission() {
- }
-
- public RepositoryAccessPermission(String repository, AccessPermission permission) {
- this.repository = repository;
- this.permission = permission;
- }
-
- @Override
- public int compareTo(RepositoryAccessPermission p) {
- return StringUtils.compareRepositoryNames(repository, p.repository);
- }
-
- @Override
- public String toString() {
- return permission.asRole(repository);
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2012 gitblit.com.
- *
- * 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.gitblit.models;
-
-import java.io.Serializable;
-
-import com.gitblit.Constants.AccessPermission;
-
-/**
- * Represents a Team-AccessPermission tuple.
- *
- * @author James Moger
- */
-public class TeamAccessPermission implements Serializable, Comparable<TeamAccessPermission> {
-
- private static final long serialVersionUID = 1L;
-
- public String team;
- public AccessPermission permission;
-
- public TeamAccessPermission() {
- }
-
- public TeamAccessPermission(String team, AccessPermission permission) {
- this.team = team;
- this.permission = permission;
- }
-
- @Override
- public int compareTo(TeamAccessPermission p) {
- return team.compareTo(p.team);
- }
-
- @Override
- public String toString() {
- return permission.asRole("@" + team);
- }
-}
\ No newline at end of file
\r
import com.gitblit.Constants.AccessPermission;\r
import com.gitblit.Constants.AccessRestrictionType;\r
+import com.gitblit.Constants.RegistrantType;\r
import com.gitblit.Constants.Unused;\r
\r
/**\r
* \r
* @return the team's list of permissions\r
*/\r
- public List<RepositoryAccessPermission> getRepositoryPermissions() {\r
- List<RepositoryAccessPermission> list = new ArrayList<RepositoryAccessPermission>();\r
+ public List<RegistrantAccessPermission> getRepositoryPermissions() {\r
+ List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();\r
for (Map.Entry<String, AccessPermission> entry : permissions.entrySet()) {\r
- list.add(new RepositoryAccessPermission(entry.getKey(), entry.getValue()));\r
+ list.add(new RegistrantAccessPermission(entry.getKey(), entry.getValue(), RegistrantType.REPOSITORY));\r
}\r
Collections.sort(list);\r
return list;\r
+++ /dev/null
-/*
- * Copyright 2012 gitblit.com.
- *
- * 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.gitblit.models;
-
-import java.io.Serializable;
-
-import com.gitblit.Constants.AccessPermission;
-
-/**
- * Represents a User-AccessPermission tuple.
- *
- * @author James Moger
- */
-public class UserAccessPermission implements Serializable, Comparable<UserAccessPermission> {
-
- private static final long serialVersionUID = 1L;
-
- public String user;
- public AccessPermission permission;
-
- public UserAccessPermission() {
- }
-
- public UserAccessPermission(String user, AccessPermission permission) {
- this.user = user;
- this.permission = permission;
- }
-
- @Override
- public int compareTo(UserAccessPermission p) {
- return user.compareTo(p.user);
- }
-
- @Override
- public String toString() {
- return permission.asRole(user);
- }
-}
\ No newline at end of file
import com.gitblit.Constants.AccessPermission;\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.Constants.AuthorizationControl;\r
+import com.gitblit.Constants.RegistrantType;\r
import com.gitblit.Constants.Unused;\r
import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.StringUtils;\r
* \r
* @return the user's list of permissions\r
*/\r
- public List<RepositoryAccessPermission> getRepositoryPermissions() {\r
- List<RepositoryAccessPermission> list = new ArrayList<RepositoryAccessPermission>();\r
+ public List<RegistrantAccessPermission> getRepositoryPermissions() {\r
+ List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();\r
for (Map.Entry<String, AccessPermission> entry : permissions.entrySet()) {\r
- list.add(new RepositoryAccessPermission(entry.getKey(), entry.getValue()));\r
+ list.add(new RegistrantAccessPermission(entry.getKey(), entry.getValue(), RegistrantType.REPOSITORY));\r
}\r
Collections.sort(list);\r
return list;\r
// and the permissions of teams of which the user belongs\r
AccessPermission permission = AccessPermission.NONE;\r
if (permissions.containsKey(repository.name.toLowerCase())) {\r
- // exact repository permission specified\r
+ // exact repository permission specified, use it\r
AccessPermission p = permissions.get(repository.name.toLowerCase());\r
if (p != null) {\r
- permission = p;\r
+ return p;\r
}\r
} else {\r
// search for regex permission match\r
import com.gitblit.Constants;\r
import com.gitblit.Constants.RpcRequest;\r
import com.gitblit.GitBlitException.UnknownRequestException;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.FederationModel;\r
import com.gitblit.models.FederationProposal;\r
import com.gitblit.models.FederationSet;\r
private static final Type BRANCHES_TYPE = new TypeToken<Map<String, Collection<String>>>() {\r
}.getType();\r
\r
+ public static final Type REGISTRANT_PERMISSIONS_TYPE = new TypeToken<Collection<RegistrantAccessPermission>>() {\r
+ }.getType();\r
+\r
/**\r
* \r
* @param remoteURL\r
Collection<String> list = JsonUtils.retrieveJson(url, NAMES_TYPE, account, password);\r
return new ArrayList<String>(list);\r
}\r
+ \r
+ /**\r
+ * Retrieves the list of user access permissions for the specified repository.\r
+ * \r
+ * @param repository\r
+ * @param serverUrl\r
+ * @param account\r
+ * @param password\r
+ * @return list of User-AccessPermission tuples\r
+ * @throws IOException\r
+ */\r
+ public static List<RegistrantAccessPermission> getRepositoryMemberPermissions(RepositoryModel repository, \r
+ String serverUrl, String account, char [] password) throws IOException {\r
+ String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS, repository.name);\r
+ Collection<RegistrantAccessPermission> list = JsonUtils.retrieveJson(url, REGISTRANT_PERMISSIONS_TYPE, account, password);\r
+ return new ArrayList<RegistrantAccessPermission>(list);\r
+ }\r
\r
/**\r
- * Sets the repository user membership list.\r
+ * Sets the repository user access permissions\r
* \r
* @param repository\r
- * @param memberships\r
+ * @param permissions\r
* @param serverUrl\r
* @param account\r
* @param password\r
* @return true if the action succeeded\r
* @throws IOException\r
*/\r
- public static boolean setRepositoryMembers(RepositoryModel repository,\r
- List<String> memberships, String serverUrl, String account, char[] password)\r
+ public static boolean setRepositoryMemberPermissions(RepositoryModel repository,\r
+ List<RegistrantAccessPermission> permissions, String serverUrl, String account, char[] password)\r
throws IOException {\r
- return doAction(RpcRequest.SET_REPOSITORY_MEMBERS, repository.name, memberships, serverUrl,\r
+ return doAction(RpcRequest.SET_REPOSITORY_MEMBER_PERMISSIONS, repository.name, permissions, serverUrl,\r
account, password);\r
}\r
-\r
+ \r
/**\r
* Retrieves the list of teams that can access the specified repository.\r
* \r
Collection<String> list = JsonUtils.retrieveJson(url, NAMES_TYPE, account, password);\r
return new ArrayList<String>(list);\r
}\r
+ \r
+ /**\r
+ * Retrieves the list of team access permissions for the specified repository.\r
+ * \r
+ * @param repository\r
+ * @param serverUrl\r
+ * @param account\r
+ * @param password\r
+ * @return list of Team-AccessPermission tuples\r
+ * @throws IOException\r
+ */\r
+ public static List<RegistrantAccessPermission> getRepositoryTeamPermissions(RepositoryModel repository, \r
+ String serverUrl, String account, char [] password) throws IOException {\r
+ String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORY_TEAM_PERMISSIONS, repository.name);\r
+ Collection<RegistrantAccessPermission> list = JsonUtils.retrieveJson(url, REGISTRANT_PERMISSIONS_TYPE, account, password);\r
+ return new ArrayList<RegistrantAccessPermission>(list);\r
+ }\r
\r
/**\r
- * Sets the repository team membership list.\r
+ * Sets the repository team access permissions\r
* \r
* @param repository\r
- * @param teams\r
+ * @param permissions\r
* @param serverUrl\r
* @param account\r
* @param password\r
* @return true if the action succeeded\r
* @throws IOException\r
*/\r
- public static boolean setRepositoryTeams(RepositoryModel repository,\r
- List<String> teams, String serverUrl, String account, char[] password)\r
+ public static boolean setRepositoryTeamPermissions(RepositoryModel repository,\r
+ List<RegistrantAccessPermission> permissions, String serverUrl, String account, char[] password)\r
throws IOException {\r
- return doAction(RpcRequest.SET_REPOSITORY_TEAMS, repository.name, teams, serverUrl,\r
+ return doAction(RpcRequest.SET_REPOSITORY_TEAM_PERMISSIONS, repository.name, permissions, serverUrl,\r
account, password);\r
}\r
-\r
+ \r
/**\r
* Retrieves the list of federation registrations. These are the list of\r
* registrations that this Gitblit instance is pulling from.\r
gb.pushPermission = {0} (push)\r
gb.createPermission = {0} (push, ref creation)\r
gb.deletePermission = {0} (push, ref creation+deletion)\r
-gb.rewindPermission = {0} (push, ref creation+deletion+rewind)
\ No newline at end of file
+gb.rewindPermission = {0} (push, ref creation+deletion+rewind)\r
+gb.permission = permission\r
import com.gitblit.GitBlit;\r
import com.gitblit.GitBlitException;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.TeamAccessPermission;\r
-import com.gitblit.models.UserAccessPermission;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.ArrayUtils;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.StringChoiceRenderer;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.panels.BulletListPanel;\r
-import com.gitblit.wicket.panels.TeamPermissionsPanel;\r
-import com.gitblit.wicket.panels.UserPermissionsPanel;\r
+import com.gitblit.wicket.panels.RegistrantPermissionsPanel;\r
\r
public class EditRepositoryPage extends RootSubPage {\r
\r
\r
List<String> indexedBranches = new ArrayList<String>();\r
List<String> federationSets = new ArrayList<String>();\r
- final List<UserAccessPermission> repositoryUsers = new ArrayList<UserAccessPermission>();\r
- final List<TeamAccessPermission> repositoryTeams = new ArrayList<TeamAccessPermission>();\r
+ final List<RegistrantAccessPermission> repositoryUsers = new ArrayList<RegistrantAccessPermission>();\r
+ final List<RegistrantAccessPermission> repositoryTeams = new ArrayList<RegistrantAccessPermission>();\r
List<String> preReceiveScripts = new ArrayList<String>();\r
List<String> postReceiveScripts = new ArrayList<String>();\r
\r
\r
final String oldName = repositoryModel.name;\r
\r
- UserPermissionsPanel usersPalette = new UserPermissionsPanel("users", repositoryUsers, getAccessPermissions());\r
- TeamPermissionsPanel teamsPalette = new TeamPermissionsPanel("teams", repositoryTeams, getAccessPermissions());\r
+ RegistrantPermissionsPanel usersPalette = new RegistrantPermissionsPanel("users", \r
+ GitBlit.self().getAllUsernames(), repositoryUsers, getAccessPermissions());\r
+ RegistrantPermissionsPanel teamsPalette = new RegistrantPermissionsPanel("teams", \r
+ GitBlit.self().getAllTeamnames(), repositoryTeams, getAccessPermissions());\r
\r
// indexed local branches palette\r
List<String> allLocalBranches = new ArrayList<String>();\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.GitBlit;\r
import com.gitblit.GitBlitException;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.RepositoryAccessPermission;\r
import com.gitblit.models.TeamModel;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.RequiresAdminRole;\r
import com.gitblit.wicket.StringChoiceRenderer;\r
import com.gitblit.wicket.WicketUtils;\r
import com.gitblit.wicket.panels.BulletListPanel;\r
-import com.gitblit.wicket.panels.RepositoryPermissionsPanel;\r
+import com.gitblit.wicket.panels.RegistrantPermissionsPanel;\r
\r
@RequiresAdminRole\r
public class EditTeamPage extends RootSubPage {\r
List<String> postReceiveScripts = new ArrayList<String>();\r
\r
final String oldName = teamModel.name;\r
- final List<RepositoryAccessPermission> permissions = teamModel.getRepositoryPermissions();\r
+ final List<RegistrantAccessPermission> permissions = teamModel.getRepositoryPermissions();\r
\r
// users palette\r
final Palette<String> users = new Palette<String>("users", new ListModel<String>(\r
}\r
}\r
// update team permissions\r
- for (RepositoryAccessPermission repositoryPermission : permissions) {\r
- teamModel.setRepositoryPermission(repositoryPermission.repository, repositoryPermission.permission);\r
+ for (RegistrantAccessPermission repositoryPermission : permissions) {\r
+ teamModel.setRepositoryPermission(repositoryPermission.registrant, repositoryPermission.permission);\r
}\r
\r
Iterator<String> selectedUsers = users.getSelectedChoices();\r
: StringUtils.flattenStrings(teamModel.mailingLists, " "));\r
form.add(new TextField<String>("mailingLists", mailingLists));\r
\r
- form.add(new RepositoryPermissionsPanel("repositories", permissions, getAccessPermissions()));\r
+ form.add(new RegistrantPermissionsPanel("repositories", repos, permissions, getAccessPermissions()));\r
form.add(preReceivePalette);\r
form.add(new BulletListPanel("inheritedPreReceive", "inherited", GitBlit.self()\r
.getPreReceiveScriptsInherited(null)));\r
import com.gitblit.GitBlit;\r
import com.gitblit.GitBlitException;\r
import com.gitblit.Keys;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.RepositoryModel;\r
-import com.gitblit.models.RepositoryAccessPermission;\r
import com.gitblit.models.TeamModel;\r
import com.gitblit.models.UserModel;\r
import com.gitblit.utils.StringUtils;\r
import com.gitblit.wicket.RequiresAdminRole;\r
import com.gitblit.wicket.StringChoiceRenderer;\r
import com.gitblit.wicket.WicketUtils;\r
-import com.gitblit.wicket.panels.RepositoryPermissionsPanel;\r
+import com.gitblit.wicket.panels.RegistrantPermissionsPanel;\r
\r
@RequiresAdminRole\r
public class EditUserPage extends RootSubPage {\r
repos.add(repo);\r
}\r
}\r
+ StringUtils.sortRepositorynames(repos);\r
+ \r
List<String> userTeams = new ArrayList<String>();\r
for (TeamModel team : userModel.teams) {\r
userTeams.add(team.name);\r
Collections.sort(userTeams);\r
\r
final String oldName = userModel.username;\r
- final List<RepositoryAccessPermission> permissions = userModel.getRepositoryPermissions();\r
+ final List<RegistrantAccessPermission> permissions = userModel.getRepositoryPermissions();\r
\r
final Palette<String> teams = new Palette<String>("teams", new ListModel<String>(\r
new ArrayList<String>(userTeams)), new CollectionModel<String>(GitBlit.self()\r
}\r
\r
// update user permissions\r
- for (RepositoryAccessPermission repositoryPermission : permissions) {\r
- userModel.setRepositoryPermission(repositoryPermission.repository, repositoryPermission.permission);\r
+ for (RegistrantAccessPermission repositoryPermission : permissions) {\r
+ userModel.setRepositoryPermission(repositoryPermission.registrant, repositoryPermission.permission);\r
}\r
\r
Iterator<String> selectedTeams = teams.getSelectedChoices();\r
form.add(new CheckBox("canFork"));\r
form.add(new CheckBox("canCreate"));\r
form.add(new CheckBox("excludeFromFederation"));\r
- form.add(new RepositoryPermissionsPanel("repositories", permissions, getAccessPermissions()));\r
+ form.add(new RegistrantPermissionsPanel("repositories", repos, permissions, getAccessPermissions()));\r
form.add(teams.setEnabled(editTeams));\r
\r
form.add(new Button("save"));\r
--- /dev/null
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
+<html xmlns="http://www.w3.org/1999/xhtml" \r
+ xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd" \r
+ xml:lang="en" \r
+ lang="en"> \r
+\r
+<body>\r
+<wicket:panel>\r
+\r
+ <div wicket:id="permissionRow">\r
+ <div style="padding-top:10px" class="row-fluid">\r
+ <span class="span8" wicket:id="registrant"></span> <select class="input-medium" wicket:id="permission"></select>\r
+ </div>\r
+ </div>\r
+\r
+ <div style="padding-top:15px;" class="row-fluid">\r
+ <form class="well form-inline" wicket:id="addPermissionForm">\r
+ <select class="input-large" wicket:id="registrant"></select> <select class="input-medium" wicket:id="permission"></select> <input class="btn btn-success" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addPermissionButton"/>\r
+ </form>\r
+ </div> \r
+ \r
+</wicket:panel>\r
+</body>\r
+</html>
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright 2012 gitblit.com.
+ *
+ * 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.gitblit.wicket.panels;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.wicket.ajax.AjaxRequestTarget;
+import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
+import org.apache.wicket.ajax.markup.html.form.AjaxButton;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.IChoiceRenderer;
+import org.apache.wicket.markup.repeater.Item;
+import org.apache.wicket.markup.repeater.OddEvenItem;
+import org.apache.wicket.markup.repeater.RefreshingView;
+import org.apache.wicket.markup.repeater.util.ModelIteratorAdapter;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.model.IModel;
+
+import com.gitblit.Constants.AccessPermission;
+import com.gitblit.models.RegistrantAccessPermission;
+import com.gitblit.utils.DeepCopier;
+
+/**
+ * Allows user to manipulate registrant access permissions.
+ *
+ * @author James Moger
+ *
+ */
+public class RegistrantPermissionsPanel extends BasePanel {
+
+ private static final long serialVersionUID = 1L;
+
+ public RegistrantPermissionsPanel(String wicketId, List<String> allRegistrants, final List<RegistrantAccessPermission> permissions, final Map<AccessPermission, String> translations) {
+ super(wicketId);
+
+ // update existing permissions repeater
+ RefreshingView<RegistrantAccessPermission> dataView = new RefreshingView<RegistrantAccessPermission>("permissionRow") {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected Iterator<IModel<RegistrantAccessPermission>> getItemModels() {
+ // the iterator returns RepositoryPermission objects, but we need it to
+ // return models
+ return new ModelIteratorAdapter<RegistrantAccessPermission>(permissions.iterator()) {
+ @Override
+ protected IModel<RegistrantAccessPermission> model(RegistrantAccessPermission permission) {
+ return new CompoundPropertyModel<RegistrantAccessPermission>(permission);
+ }
+ };
+ }
+
+ @Override
+ protected Item<RegistrantAccessPermission> newItem(String id, int index, IModel<RegistrantAccessPermission> model) {
+ // this item sets markup class attribute to either 'odd' or
+ // 'even' for decoration
+ return new OddEvenItem<RegistrantAccessPermission>(id, index, model);
+ }
+
+ public void populateItem(final Item<RegistrantAccessPermission> item) {
+ final RegistrantAccessPermission entry = item.getModelObject();
+ item.add(new Label("registrant", entry.registrant));
+
+ // use ajax to get immediate update of permission level change
+ // otherwise we can lose it if they change levels and then add
+ // a new repository permission
+ final DropDownChoice<AccessPermission> permissionChoice = new DropDownChoice<AccessPermission>(
+ "permission", Arrays.asList(AccessPermission.values()), new AccessPermissionRenderer(translations));
+ permissionChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
+
+ private static final long serialVersionUID = 1L;
+
+ protected void onUpdate(AjaxRequestTarget target) {
+ target.addComponent(permissionChoice);
+ }
+ });
+
+ item.add(permissionChoice);
+ }
+ };
+ add(dataView);
+ setOutputMarkupId(true);
+
+ // filter out registrants we already have permissions for
+ final List<String> registrants = new ArrayList<String>(allRegistrants);
+ for (RegistrantAccessPermission rp : permissions) {
+ registrants.remove(rp.registrant);
+ }
+
+ // add new permission form
+ IModel<RegistrantAccessPermission> addPermissionModel = new CompoundPropertyModel<RegistrantAccessPermission>(new RegistrantAccessPermission());
+ Form<RegistrantAccessPermission> addPermissionForm = new Form<RegistrantAccessPermission>("addPermissionForm", addPermissionModel);
+ addPermissionForm.add(new DropDownChoice<String>("registrant", registrants));
+ addPermissionForm.add(new DropDownChoice<AccessPermission>("permission", Arrays
+ .asList(AccessPermission.NEWPERMISSIONS), new AccessPermissionRenderer(translations)));
+ AjaxButton button = new AjaxButton("addPermissionButton", addPermissionForm) {
+
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
+ // add permission to our list
+ RegistrantAccessPermission rp = (RegistrantAccessPermission) form.getModel().getObject();
+ permissions.add(DeepCopier.copy(rp));
+
+ // remove registrant from available choices
+ registrants.remove(rp.registrant);
+
+ // force the panel to refresh
+ target.addComponent(RegistrantPermissionsPanel.this);
+ }
+ };
+ addPermissionForm.add(button);
+
+ // only show add permission form if we have a registrant choice
+ add(addPermissionForm.setVisible(registrants.size() > 0));
+ }
+
+ private class AccessPermissionRenderer implements IChoiceRenderer<AccessPermission> {
+
+ private static final long serialVersionUID = 1L;
+
+ private final Map<AccessPermission, String> map;
+
+ public AccessPermissionRenderer(Map<AccessPermission, String> map) {
+ this.map = map;
+ }
+
+ @Override
+ public String getDisplayValue(AccessPermission type) {
+ return map.get(type);
+ }
+
+ @Override
+ public String getIdValue(AccessPermission type, int index) {
+ return Integer.toString(index);
+ }
+ }
+}
+++ /dev/null
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
-<html xmlns="http://www.w3.org/1999/xhtml" \r
- xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd" \r
- xml:lang="en" \r
- lang="en"> \r
-\r
-<body>\r
-<wicket:panel>\r
-\r
- <div wicket:id="permissionRow">\r
- <div style="padding-top:10px" class="row-fluid">\r
- <span class="span8" wicket:id="repository"></span> <select class="input-medium" wicket:id="permission"></select>\r
- </div>\r
- </div>\r
-\r
- <div style="padding-top:15px;" class="row-fluid">\r
- <form class="well form-inline" wicket:id="addPermissionForm">\r
- <select class="input-large" wicket:id="repository"></select> <select class="input-medium" wicket:id="permission"></select> <input class="btn btn-success" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addPermissionButton"/>\r
- </form>\r
- </div> \r
- \r
-</wicket:panel>\r
-</body>\r
-</html>
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2012 gitblit.com.
- *
- * 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.gitblit.wicket.panels;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
-import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.DropDownChoice;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.IChoiceRenderer;
-import org.apache.wicket.markup.repeater.Item;
-import org.apache.wicket.markup.repeater.OddEvenItem;
-import org.apache.wicket.markup.repeater.RefreshingView;
-import org.apache.wicket.markup.repeater.util.ModelIteratorAdapter;
-import org.apache.wicket.model.CompoundPropertyModel;
-import org.apache.wicket.model.IModel;
-
-import com.gitblit.Constants.AccessPermission;
-import com.gitblit.GitBlit;
-import com.gitblit.models.RepositoryAccessPermission;
-import com.gitblit.utils.DeepCopier;
-
-/**
- * Allows user to manipulate repository access permissions.
- *
- * @author James Moger
- *
- */
-public class RepositoryPermissionsPanel extends BasePanel {
-
- private static final long serialVersionUID = 1L;
-
- public RepositoryPermissionsPanel(String wicketId, final List<RepositoryAccessPermission> permissions, final Map<AccessPermission, String> translations) {
- super(wicketId);
-
- // update existing permissions repeater
- RefreshingView<RepositoryAccessPermission> dataView = new RefreshingView<RepositoryAccessPermission>("permissionRow") {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected Iterator<IModel<RepositoryAccessPermission>> getItemModels() {
- // the iterator returns RepositoryPermission objects, but we need it to
- // return models
- return new ModelIteratorAdapter<RepositoryAccessPermission>(permissions.iterator()) {
- @Override
- protected IModel<RepositoryAccessPermission> model(RepositoryAccessPermission permission) {
- return new CompoundPropertyModel<RepositoryAccessPermission>(permission);
- }
- };
- }
-
- @Override
- protected Item<RepositoryAccessPermission> newItem(String id, int index, IModel<RepositoryAccessPermission> model) {
- // this item sets markup class attribute to either 'odd' or
- // 'even' for decoration
- return new OddEvenItem<RepositoryAccessPermission>(id, index, model);
- }
-
- public void populateItem(final Item<RepositoryAccessPermission> item) {
- final RepositoryAccessPermission entry = item.getModelObject();
- item.add(new Label("repository", entry.repository));
-
- // use ajax to get immediate update of permission level change
- // otherwise we can lose it if they change levels and then add
- // a new repository permission
- final DropDownChoice<AccessPermission> permissionChoice = new DropDownChoice<AccessPermission>(
- "permission", Arrays.asList(AccessPermission.values()), new AccessPermissionRenderer(translations));
- permissionChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
-
- private static final long serialVersionUID = 1L;
-
- protected void onUpdate(AjaxRequestTarget target) {
- target.addComponent(permissionChoice);
- }
- });
-
- item.add(permissionChoice);
- }
- };
- add(dataView);
- setOutputMarkupId(true);
-
- // filter out repositories we already have permissions for
- final List<String> repositories = GitBlit.self().getRepositoryList();
- for (RepositoryAccessPermission rp : permissions) {
- repositories.remove(rp.repository);
- }
-
- // add new permission form
- IModel<RepositoryAccessPermission> addPermissionModel = new CompoundPropertyModel<RepositoryAccessPermission>(new RepositoryAccessPermission());
- Form<RepositoryAccessPermission> addPermissionForm = new Form<RepositoryAccessPermission>("addPermissionForm", addPermissionModel);
- addPermissionForm.add(new DropDownChoice<String>("repository", repositories));
- addPermissionForm.add(new DropDownChoice<AccessPermission>("permission", Arrays
- .asList(AccessPermission.NEWPERMISSIONS), new AccessPermissionRenderer(translations)));
- AjaxButton button = new AjaxButton("addPermissionButton", addPermissionForm) {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
- // add permission to our list
- RepositoryAccessPermission rp = (RepositoryAccessPermission) form.getModel().getObject();
- permissions.add(DeepCopier.copy(rp));
-
- // remove repository from available choices
- repositories.remove(rp.repository);
-
- // force the panel to refresh
- target.addComponent(RepositoryPermissionsPanel.this);
- }
- };
- addPermissionForm.add(button);
-
- // only show add permission form if we have a repository choice
- add(addPermissionForm.setVisible(repositories.size() > 0));
- }
-
- private class AccessPermissionRenderer implements IChoiceRenderer<AccessPermission> {
-
- private static final long serialVersionUID = 1L;
-
- private final Map<AccessPermission, String> map;
-
- public AccessPermissionRenderer(Map<AccessPermission, String> map) {
- this.map = map;
- }
-
- @Override
- public String getDisplayValue(AccessPermission type) {
- return map.get(type);
- }
-
- @Override
- public String getIdValue(AccessPermission type, int index) {
- return Integer.toString(index);
- }
- }
-}
+++ /dev/null
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
-<html xmlns="http://www.w3.org/1999/xhtml" \r
- xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd" \r
- xml:lang="en" \r
- lang="en"> \r
-\r
-<body>\r
-<wicket:panel>\r
-\r
- <div wicket:id="permissionRow">\r
- <div style="padding-top:10px" class="row-fluid">\r
- <span class="span8" wicket:id="team"></span> <select class="input-medium" wicket:id="permission"></select>\r
- </div>\r
- </div>\r
-\r
- <div style="padding-top:15px;" class="row-fluid">\r
- <form class="well form-inline" wicket:id="addPermissionForm">\r
- <select class="input-large" wicket:id="team"></select> <select class="input-medium" wicket:id="permission"></select> <input class="btn btn-success" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addPermissionButton"/>\r
- </form>\r
- </div> \r
- \r
-</wicket:panel>\r
-</body>\r
-</html>
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2012 gitblit.com.
- *
- * 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.gitblit.wicket.panels;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
-import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.DropDownChoice;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.IChoiceRenderer;
-import org.apache.wicket.markup.repeater.Item;
-import org.apache.wicket.markup.repeater.OddEvenItem;
-import org.apache.wicket.markup.repeater.RefreshingView;
-import org.apache.wicket.markup.repeater.util.ModelIteratorAdapter;
-import org.apache.wicket.model.CompoundPropertyModel;
-import org.apache.wicket.model.IModel;
-
-import com.gitblit.Constants.AccessPermission;
-import com.gitblit.GitBlit;
-import com.gitblit.models.TeamAccessPermission;
-import com.gitblit.utils.DeepCopier;
-
-/**
- * Allows user to manipulate user access permissions.
- *
- * @author James Moger
- *
- */
-public class TeamPermissionsPanel extends BasePanel {
-
- private static final long serialVersionUID = 1L;
-
- public TeamPermissionsPanel(String wicketId, final List<TeamAccessPermission> permissions, final Map<AccessPermission, String> translations) {
- super(wicketId);
-
- // update existing permissions repeater
- RefreshingView<TeamAccessPermission> dataView = new RefreshingView<TeamAccessPermission>("permissionRow") {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected Iterator<IModel<TeamAccessPermission>> getItemModels() {
- // the iterator returns RepositoryPermission objects, but we need it to
- // return models
- return new ModelIteratorAdapter<TeamAccessPermission>(permissions.iterator()) {
- @Override
- protected IModel<TeamAccessPermission> model(TeamAccessPermission permission) {
- return new CompoundPropertyModel<TeamAccessPermission>(permission);
- }
- };
- }
-
- @Override
- protected Item<TeamAccessPermission> newItem(String id, int index, IModel<TeamAccessPermission> model) {
- // this item sets markup class attribute to either 'odd' or
- // 'even' for decoration
- return new OddEvenItem<TeamAccessPermission>(id, index, model);
- }
-
- public void populateItem(final Item<TeamAccessPermission> item) {
- final TeamAccessPermission entry = item.getModelObject();
- item.add(new Label("team", entry.team));
-
- // use ajax to get immediate update of permission level change
- // otherwise we can lose it if they change levels and then add
- // a new repository permission
- final DropDownChoice<AccessPermission> permissionChoice = new DropDownChoice<AccessPermission>(
- "permission", Arrays.asList(AccessPermission.values()), new AccessPermissionRenderer(translations));
- permissionChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
-
- private static final long serialVersionUID = 1L;
-
- protected void onUpdate(AjaxRequestTarget target) {
- target.addComponent(permissionChoice);
- }
- });
-
- item.add(permissionChoice);
- }
- };
- add(dataView);
- setOutputMarkupId(true);
-
- // filter out teams we already have permissions for
- final List<String> teams = GitBlit.self().getAllTeamnames();
- for (TeamAccessPermission tp : permissions) {
- teams.remove(tp.team);
- }
-
- // add new permission form
- IModel<TeamAccessPermission> addPermissionModel = new CompoundPropertyModel<TeamAccessPermission>(new TeamAccessPermission());
- Form<TeamAccessPermission> addPermissionForm = new Form<TeamAccessPermission>("addPermissionForm", addPermissionModel);
- addPermissionForm.add(new DropDownChoice<String>("team", teams));
- addPermissionForm.add(new DropDownChoice<AccessPermission>("permission", Arrays
- .asList(AccessPermission.NEWPERMISSIONS), new AccessPermissionRenderer(translations)));
- AjaxButton button = new AjaxButton("addPermissionButton", addPermissionForm) {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
- // add permission to our list
- TeamAccessPermission tp = (TeamAccessPermission) form.getModel().getObject();
- permissions.add(DeepCopier.copy(tp));
-
- // remove team from available choices
- teams.remove(tp.team);
-
- // force the panel to refresh
- target.addComponent(TeamPermissionsPanel.this);
- }
- };
- addPermissionForm.add(button);
-
- // only show add permission form if we have a team choice
- add(addPermissionForm.setVisible(teams.size() > 0));
- }
-
- private class AccessPermissionRenderer implements IChoiceRenderer<AccessPermission> {
-
- private static final long serialVersionUID = 1L;
-
- private final Map<AccessPermission, String> map;
-
- public AccessPermissionRenderer(Map<AccessPermission, String> map) {
- this.map = map;
- }
-
- @Override
- public String getDisplayValue(AccessPermission type) {
- return map.get(type);
- }
-
- @Override
- public String getIdValue(AccessPermission type, int index) {
- return Integer.toString(index);
- }
- }
-}
+++ /dev/null
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\r
-<html xmlns="http://www.w3.org/1999/xhtml" \r
- xmlns:wicket="http://wicket.apache.org/dtds.data/wicket-xhtml1.3-strict.dtd" \r
- xml:lang="en" \r
- lang="en"> \r
-\r
-<body>\r
-<wicket:panel>\r
-\r
- <div wicket:id="permissionRow">\r
- <div style="padding-top:10px" class="row-fluid">\r
- <span class="span8" wicket:id="user"></span> <select class="input-medium" wicket:id="permission"></select>\r
- </div>\r
- </div>\r
-\r
- <div style="padding-top:15px;" class="row-fluid">\r
- <form class="well form-inline" wicket:id="addPermissionForm">\r
- <select class="input-large" wicket:id="user"></select> <select class="input-medium" wicket:id="permission"></select> <input class="btn btn-success" type="submit" value="Add" wicket:message="value:gb.add" wicket:id="addPermissionButton"/>\r
- </form>\r
- </div> \r
- \r
-</wicket:panel>\r
-</body>\r
-</html>
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright 2012 gitblit.com.
- *
- * 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.gitblit.wicket.panels;
-
-import java.util.Arrays;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.wicket.ajax.AjaxRequestTarget;
-import org.apache.wicket.ajax.form.AjaxFormComponentUpdatingBehavior;
-import org.apache.wicket.ajax.markup.html.form.AjaxButton;
-import org.apache.wicket.markup.html.basic.Label;
-import org.apache.wicket.markup.html.form.DropDownChoice;
-import org.apache.wicket.markup.html.form.Form;
-import org.apache.wicket.markup.html.form.IChoiceRenderer;
-import org.apache.wicket.markup.repeater.Item;
-import org.apache.wicket.markup.repeater.OddEvenItem;
-import org.apache.wicket.markup.repeater.RefreshingView;
-import org.apache.wicket.markup.repeater.util.ModelIteratorAdapter;
-import org.apache.wicket.model.CompoundPropertyModel;
-import org.apache.wicket.model.IModel;
-
-import com.gitblit.Constants.AccessPermission;
-import com.gitblit.GitBlit;
-import com.gitblit.models.UserAccessPermission;
-import com.gitblit.utils.DeepCopier;
-
-/**
- * Allows user to manipulate user access permissions.
- *
- * @author James Moger
- *
- */
-public class UserPermissionsPanel extends BasePanel {
-
- private static final long serialVersionUID = 1L;
-
- public UserPermissionsPanel(String wicketId, final List<UserAccessPermission> permissions, final Map<AccessPermission, String> translations) {
- super(wicketId);
-
- // update existing permissions repeater
- RefreshingView<UserAccessPermission> dataView = new RefreshingView<UserAccessPermission>("permissionRow") {
- private static final long serialVersionUID = 1L;
-
- @Override
- protected Iterator<IModel<UserAccessPermission>> getItemModels() {
- // the iterator returns RepositoryPermission objects, but we need it to
- // return models
- return new ModelIteratorAdapter<UserAccessPermission>(permissions.iterator()) {
- @Override
- protected IModel<UserAccessPermission> model(UserAccessPermission permission) {
- return new CompoundPropertyModel<UserAccessPermission>(permission);
- }
- };
- }
-
- @Override
- protected Item<UserAccessPermission> newItem(String id, int index, IModel<UserAccessPermission> model) {
- // this item sets markup class attribute to either 'odd' or
- // 'even' for decoration
- return new OddEvenItem<UserAccessPermission>(id, index, model);
- }
-
- public void populateItem(final Item<UserAccessPermission> item) {
- final UserAccessPermission entry = item.getModelObject();
- item.add(new Label("user", entry.user));
-
- // use ajax to get immediate update of permission level change
- // otherwise we can lose it if they change levels and then add
- // a new repository permission
- final DropDownChoice<AccessPermission> permissionChoice = new DropDownChoice<AccessPermission>(
- "permission", Arrays.asList(AccessPermission.values()), new AccessPermissionRenderer(translations));
- permissionChoice.add(new AjaxFormComponentUpdatingBehavior("onchange") {
-
- private static final long serialVersionUID = 1L;
-
- protected void onUpdate(AjaxRequestTarget target) {
- target.addComponent(permissionChoice);
- }
- });
-
- item.add(permissionChoice);
- }
- };
- add(dataView);
- setOutputMarkupId(true);
-
- // filter out users we already have permissions for
- final List<String> users = GitBlit.self().getAllUsernames();
- for (UserAccessPermission up : permissions) {
- users.remove(up.user);
- }
-
- // add new permission form
- IModel<UserAccessPermission> addPermissionModel = new CompoundPropertyModel<UserAccessPermission>(new UserAccessPermission());
- Form<UserAccessPermission> addPermissionForm = new Form<UserAccessPermission>("addPermissionForm", addPermissionModel);
- addPermissionForm.add(new DropDownChoice<String>("user", users));
- addPermissionForm.add(new DropDownChoice<AccessPermission>("permission", Arrays
- .asList(AccessPermission.NEWPERMISSIONS), new AccessPermissionRenderer(translations)));
- AjaxButton button = new AjaxButton("addPermissionButton", addPermissionForm) {
-
- private static final long serialVersionUID = 1L;
-
- @Override
- protected void onSubmit(AjaxRequestTarget target, Form<?> form) {
- // add permission to our list
- UserAccessPermission up = (UserAccessPermission) form.getModel().getObject();
- permissions.add(DeepCopier.copy(up));
-
- // remove user from available choices
- users.remove(up.user);
-
- // force the panel to refresh
- target.addComponent(UserPermissionsPanel.this);
- }
- };
- addPermissionForm.add(button);
-
- // only show add permission form if we have a user choice
- add(addPermissionForm.setVisible(users.size() > 0));
- }
-
- private class AccessPermissionRenderer implements IChoiceRenderer<AccessPermission> {
-
- private static final long serialVersionUID = 1L;
-
- private final Map<AccessPermission, String> map;
-
- public AccessPermissionRenderer(Map<AccessPermission, String> map) {
- this.map = map;
- }
-
- @Override
- public String getDisplayValue(AccessPermission type) {
- return map.get(type);
- }
-
- @Override
- public String getIdValue(AccessPermission type, int index) {
- return Integer.toString(index);
- }
- }
-}
item.add(new Label("accesslevel", entry.canAdmin() ? "administrator" : ""));\r
item.add(new Label("teams", entry.teams.size() > 0 ? ("" + entry.teams.size()) : ""));\r
item.add(new Label("repositories",\r
- entry.repositories.size() > 0 ? ("" + entry.repositories.size()) : ""));\r
+ entry.permissions.size() > 0 ? ("" + entry.permissions.size()) : ""));\r
Fragment userLinks = new Fragment("userLinks", "userAdminLinks", this);\r
userLinks.add(new BookmarkablePageLink<Void>("editUser", EditUserPage.class,\r
WicketUtils.newUsernameParameter(entry.username)));\r
import org.junit.BeforeClass;\r
import org.junit.Test;\r
\r
+import com.gitblit.Constants.AccessPermission;\r
import com.gitblit.Constants.AccessRestrictionType;\r
import com.gitblit.Constants.AuthorizationControl;\r
+import com.gitblit.Constants.RegistrantType;\r
import com.gitblit.GitBlitException.UnauthorizedException;\r
import com.gitblit.Keys;\r
import com.gitblit.RpcServlet;\r
+import com.gitblit.models.RegistrantAccessPermission;\r
import com.gitblit.models.FederationModel;\r
import com.gitblit.models.FederationProposal;\r
import com.gitblit.models.FederationSet;\r
String originalName = model.name;\r
model.name = "garbagerepo2.git";\r
model.accessRestriction = AccessRestrictionType.PUSH;\r
+ model.authorizationControl = AuthorizationControl.NAMED;\r
assertTrue("Failed to update repository!", RpcUtils.updateRepository(originalName, model,\r
url, account, password.toCharArray()));\r
\r
UserModel testMember = new UserModel("justadded");\r
assertTrue(RpcUtils.createUser(testMember, url, account, password.toCharArray()));\r
\r
- List<String> members = RpcUtils.getRepositoryMembers(retrievedRepository, url, account,\r
+ List<RegistrantAccessPermission> permissions = RpcUtils.getRepositoryMemberPermissions(retrievedRepository, url, account,\r
password.toCharArray());\r
- assertEquals("Membership roster is not empty!", 0, members.size());\r
- members.add(testMember.username);\r
+ assertEquals("Membership permissions is not empty!", 0, permissions.size());\r
+ permissions.add(new RegistrantAccessPermission(testMember.username, AccessPermission.PUSH, RegistrantType.USER));\r
assertTrue(\r
- "Failed to set memberships!",\r
- RpcUtils.setRepositoryMembers(retrievedRepository, members, url, account,\r
+ "Failed to set member permissions!",\r
+ RpcUtils.setRepositoryMemberPermissions(retrievedRepository, permissions, url, account,\r
password.toCharArray()));\r
- members = RpcUtils.getRepositoryMembers(retrievedRepository, url, account,\r
+ permissions = RpcUtils.getRepositoryMemberPermissions(retrievedRepository, url, account,\r
password.toCharArray());\r
boolean foundMember = false;\r
- for (String member : members) {\r
- if (member.equalsIgnoreCase(testMember.username)) {\r
+ for (RegistrantAccessPermission permission : permissions) {\r
+ if (permission.registrant.equalsIgnoreCase(testMember.username)) {\r
foundMember = true;\r
+ assertEquals(AccessPermission.PUSH, permission.permission);\r
break;\r
}\r
}\r
assertTrue(helloworldTeams.contains(aTeam.name));\r
\r
// set no teams\r
- assertTrue(RpcUtils.setRepositoryTeams(helloworld, new ArrayList<String>(), url, account,\r
+ List<RegistrantAccessPermission> permissions = new ArrayList<RegistrantAccessPermission>();\r
+ for (String team : helloworldTeams) {\r
+ permissions.add(new RegistrantAccessPermission(team, AccessPermission.NONE, RegistrantType.TEAM));\r
+ }\r
+ assertTrue(RpcUtils.setRepositoryTeamPermissions(helloworld, permissions, url, account,\r
password.toCharArray()));\r
helloworldTeams = RpcUtils.getRepositoryTeams(helloworld, url, account,\r
password.toCharArray());\r