From 822dfe5d6f1b97b7849bc6fd735ee8c9d1103c19 Mon Sep 17 00:00:00 2001 From: James Moger <james.moger@gitblit.com> Date: Fri, 19 Oct 2012 22:47:34 -0400 Subject: [PATCH] Completed permissions UI, RPC, and Manager support (issue 36) --- src/com/gitblit/utils/RpcUtils.java | 66 ++++++++++++++++++++++++++------- 1 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/com/gitblit/utils/RpcUtils.java b/src/com/gitblit/utils/RpcUtils.java index 2b80e2a..ed23dab 100644 --- a/src/com/gitblit/utils/RpcUtils.java +++ b/src/com/gitblit/utils/RpcUtils.java @@ -25,6 +25,7 @@ import com.gitblit.Constants; import com.gitblit.Constants.RpcRequest; import com.gitblit.GitBlitException.UnknownRequestException; +import com.gitblit.models.RegistrantAccessPermission; import com.gitblit.models.FederationModel; import com.gitblit.models.FederationProposal; import com.gitblit.models.FederationSet; @@ -69,6 +70,9 @@ }.getType(); private static final Type BRANCHES_TYPE = new TypeToken<Map<String, Collection<String>>>() { + }.getType(); + + public static final Type REGISTRANT_PERMISSIONS_TYPE = new TypeToken<Collection<RegistrantAccessPermission>>() { }.getType(); /** @@ -357,25 +361,42 @@ Collection<String> list = JsonUtils.retrieveJson(url, NAMES_TYPE, account, password); return new ArrayList<String>(list); } - + /** - * Sets the repository user membership list. + * Retrieves the list of user access permissions for the specified repository. * * @param repository - * @param memberships + * @param serverUrl + * @param account + * @param password + * @return list of User-AccessPermission tuples + * @throws IOException + */ + public static List<RegistrantAccessPermission> getRepositoryMemberPermissions(RepositoryModel repository, + String serverUrl, String account, char [] password) throws IOException { + String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORY_MEMBER_PERMISSIONS, repository.name); + Collection<RegistrantAccessPermission> list = JsonUtils.retrieveJson(url, REGISTRANT_PERMISSIONS_TYPE, account, password); + return new ArrayList<RegistrantAccessPermission>(list); + } + + /** + * Sets the repository user access permissions + * + * @param repository + * @param permissions * @param serverUrl * @param account * @param password * @return true if the action succeeded * @throws IOException */ - public static boolean setRepositoryMembers(RepositoryModel repository, - List<String> memberships, String serverUrl, String account, char[] password) + public static boolean setRepositoryMemberPermissions(RepositoryModel repository, + List<RegistrantAccessPermission> permissions, String serverUrl, String account, char[] password) throws IOException { - return doAction(RpcRequest.SET_REPOSITORY_MEMBERS, repository.name, memberships, serverUrl, + return doAction(RpcRequest.SET_REPOSITORY_MEMBER_PERMISSIONS, repository.name, permissions, serverUrl, account, password); } - + /** * Retrieves the list of teams that can access the specified repository. * @@ -392,25 +413,42 @@ Collection<String> list = JsonUtils.retrieveJson(url, NAMES_TYPE, account, password); return new ArrayList<String>(list); } - + /** - * Sets the repository team membership list. + * Retrieves the list of team access permissions for the specified repository. * * @param repository - * @param teams + * @param serverUrl + * @param account + * @param password + * @return list of Team-AccessPermission tuples + * @throws IOException + */ + public static List<RegistrantAccessPermission> getRepositoryTeamPermissions(RepositoryModel repository, + String serverUrl, String account, char [] password) throws IOException { + String url = asLink(serverUrl, RpcRequest.LIST_REPOSITORY_TEAM_PERMISSIONS, repository.name); + Collection<RegistrantAccessPermission> list = JsonUtils.retrieveJson(url, REGISTRANT_PERMISSIONS_TYPE, account, password); + return new ArrayList<RegistrantAccessPermission>(list); + } + + /** + * Sets the repository team access permissions + * + * @param repository + * @param permissions * @param serverUrl * @param account * @param password * @return true if the action succeeded * @throws IOException */ - public static boolean setRepositoryTeams(RepositoryModel repository, - List<String> teams, String serverUrl, String account, char[] password) + public static boolean setRepositoryTeamPermissions(RepositoryModel repository, + List<RegistrantAccessPermission> permissions, String serverUrl, String account, char[] password) throws IOException { - return doAction(RpcRequest.SET_REPOSITORY_TEAMS, repository.name, teams, serverUrl, + return doAction(RpcRequest.SET_REPOSITORY_TEAM_PERMISSIONS, repository.name, permissions, serverUrl, account, password); } - + /** * Retrieves the list of federation registrations. These are the list of * registrations that this Gitblit instance is pulling from. -- Gitblit v1.9.1