Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

GitblitClient.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717
  1. /*
  2. * Copyright 2011 gitblit.com.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package com.gitblit.client;
  17. import java.io.IOException;
  18. import java.io.Serializable;
  19. import java.util.ArrayList;
  20. import java.util.Collections;
  21. import java.util.Date;
  22. import java.util.HashSet;
  23. import java.util.LinkedHashSet;
  24. import java.util.List;
  25. import java.util.Map;
  26. import java.util.Set;
  27. import java.util.TreeSet;
  28. import com.gitblit.Constants;
  29. import com.gitblit.Constants.AccessPermission;
  30. import com.gitblit.Constants.AccessRestrictionType;
  31. import com.gitblit.Constants.AuthorizationControl;
  32. import com.gitblit.Constants.PermissionType;
  33. import com.gitblit.Constants.RegistrantType;
  34. import com.gitblit.GitBlitException.ForbiddenException;
  35. import com.gitblit.GitBlitException.NotAllowedException;
  36. import com.gitblit.GitBlitException.UnauthorizedException;
  37. import com.gitblit.GitBlitException.UnknownRequestException;
  38. import com.gitblit.Keys;
  39. import com.gitblit.models.FederationModel;
  40. import com.gitblit.models.FeedEntryModel;
  41. import com.gitblit.models.FeedModel;
  42. import com.gitblit.models.RegistrantAccessPermission;
  43. import com.gitblit.models.RepositoryModel;
  44. import com.gitblit.models.ServerSettings;
  45. import com.gitblit.models.ServerStatus;
  46. import com.gitblit.models.TeamModel;
  47. import com.gitblit.models.UserModel;
  48. import com.gitblit.utils.ArrayUtils;
  49. import com.gitblit.utils.RpcUtils;
  50. import com.gitblit.utils.StringUtils;
  51. import com.gitblit.utils.SyndicationUtils;
  52. /**
  53. * GitblitClient is a object that retrieves data from a Gitblit server, caches
  54. * it for local operations, and allows updating or creating Gitblit objects.
  55. *
  56. * @author James Moger
  57. *
  58. */
  59. public class GitblitClient implements Serializable {
  60. private static final long serialVersionUID = 1L;
  61. private static final Date NEVER = new Date(0);
  62. protected final GitblitRegistration reg;
  63. public final String url;
  64. public final String account;
  65. private final char[] password;
  66. private volatile int protocolVersion;
  67. private volatile boolean allowManagement;
  68. private volatile boolean allowAdministration;
  69. private volatile ServerSettings settings;
  70. private final List<RepositoryModel> allRepositories;
  71. private final List<UserModel> allUsers;
  72. private final List<TeamModel> allTeams;
  73. private final List<FederationModel> federationRegistrations;
  74. private final List<FeedModel> availableFeeds;
  75. private final List<FeedEntryModel> syndicatedEntries;
  76. private final Set<String> subscribedRepositories;
  77. private ServerStatus status;
  78. public GitblitClient(GitblitRegistration reg) {
  79. this.reg = reg;
  80. this.url = reg.url;
  81. this.account = reg.account;
  82. this.password = reg.password;
  83. this.allUsers = new ArrayList<UserModel>();
  84. this.allTeams = new ArrayList<TeamModel>();
  85. this.allRepositories = new ArrayList<RepositoryModel>();
  86. this.federationRegistrations = new ArrayList<FederationModel>();
  87. this.availableFeeds = new ArrayList<FeedModel>();
  88. this.syndicatedEntries = new ArrayList<FeedEntryModel>();
  89. this.subscribedRepositories = new HashSet<String>();
  90. }
  91. public void login() throws IOException {
  92. protocolVersion = RpcUtils.getProtocolVersion(url, account, password);
  93. refreshSettings();
  94. refreshAvailableFeeds();
  95. refreshRepositories();
  96. refreshSubscribedFeeds(0);
  97. try {
  98. // credentials may not have administrator access
  99. // or server may have disabled rpc management
  100. refreshUsers();
  101. if (protocolVersion > 1) {
  102. refreshTeams();
  103. }
  104. allowManagement = true;
  105. } catch (UnauthorizedException e) {
  106. } catch (ForbiddenException e) {
  107. } catch (NotAllowedException e) {
  108. } catch (UnknownRequestException e) {
  109. } catch (IOException e) {
  110. e.printStackTrace();
  111. }
  112. try {
  113. // credentials may not have administrator access
  114. // or server may have disabled rpc administration
  115. refreshStatus();
  116. allowAdministration = true;
  117. } catch (UnauthorizedException e) {
  118. } catch (ForbiddenException e) {
  119. } catch (NotAllowedException e) {
  120. } catch (UnknownRequestException e) {
  121. } catch (IOException e) {
  122. e.printStackTrace();
  123. }
  124. }
  125. public int getProtocolVersion() {
  126. return protocolVersion;
  127. }
  128. public boolean allowManagement() {
  129. return allowManagement;
  130. }
  131. public boolean allowAdministration() {
  132. return allowAdministration;
  133. }
  134. public boolean isOwner(RepositoryModel model) {
  135. return model.isOwner(account);
  136. }
  137. public String getURL(String action, String repository, String objectId) {
  138. boolean mounted = settings.get(Keys.web.mountParameters).getBoolean(true);
  139. StringBuilder sb = new StringBuilder();
  140. sb.append(url);
  141. sb.append('/');
  142. sb.append(action);
  143. sb.append('/');
  144. if (mounted) {
  145. // mounted url/action/repository/objectId
  146. sb.append(StringUtils.encodeURL(repository));
  147. if (!StringUtils.isEmpty(objectId)) {
  148. sb.append('/');
  149. sb.append(objectId);
  150. }
  151. return sb.toString();
  152. } else {
  153. // parameterized url/action/&r=repository&h=objectId
  154. sb.append("?r=");
  155. sb.append(repository);
  156. if (!StringUtils.isEmpty(objectId)) {
  157. sb.append("&h=");
  158. sb.append(objectId);
  159. }
  160. return sb.toString();
  161. }
  162. }
  163. public AccessRestrictionType getDefaultAccessRestriction() {
  164. String restriction = "PUSH";
  165. if (settings.hasKey(Keys.git.defaultAccessRestriction)) {
  166. restriction = settings.get(Keys.git.defaultAccessRestriction).currentValue;
  167. }
  168. return AccessRestrictionType.fromName(restriction);
  169. }
  170. public AuthorizationControl getDefaultAuthorizationControl() {
  171. String authorization = null;
  172. if (settings.hasKey(Keys.git.defaultAuthorizationControl)) {
  173. authorization = settings.get(Keys.git.defaultAuthorizationControl).currentValue;
  174. }
  175. return AuthorizationControl.fromName(authorization);
  176. }
  177. /**
  178. * Returns the list of pre-receive scripts the repository inherited from the
  179. * global settings and team affiliations.
  180. *
  181. * @param repository
  182. * if null only the globally specified scripts are returned
  183. * @return a list of scripts
  184. */
  185. public List<String> getPreReceiveScriptsInherited(RepositoryModel repository) {
  186. Set<String> scripts = new LinkedHashSet<String>();
  187. // Globals
  188. for (String script : settings.get(Keys.groovy.preReceiveScripts).getStrings()) {
  189. if (script.endsWith(".groovy")) {
  190. scripts.add(script.substring(0, script.lastIndexOf('.')));
  191. } else {
  192. scripts.add(script);
  193. }
  194. }
  195. // Team Scripts
  196. if (repository != null) {
  197. for (String teamname : getPermittedTeamnames(repository)) {
  198. TeamModel team = getTeamModel(teamname);
  199. if (!ArrayUtils.isEmpty(team.preReceiveScripts)) {
  200. scripts.addAll(team.preReceiveScripts);
  201. }
  202. }
  203. }
  204. return new ArrayList<String>(scripts);
  205. }
  206. /**
  207. * Returns the list of all available Groovy pre-receive push hook scripts
  208. * that are not already inherited by the repository. Script files must have
  209. * .groovy extension
  210. *
  211. * @param repository
  212. * optional parameter
  213. * @return list of available hook scripts
  214. */
  215. public List<String> getPreReceiveScriptsUnused(RepositoryModel repository) {
  216. Set<String> inherited = new TreeSet<String>(getPreReceiveScriptsInherited(repository));
  217. // create list of available scripts by excluding inherited scripts
  218. List<String> scripts = new ArrayList<String>();
  219. for (String script : settings.pushScripts) {
  220. if (!inherited.contains(script)) {
  221. scripts.add(script);
  222. }
  223. }
  224. return scripts;
  225. }
  226. /**
  227. * Returns the list of post-receive scripts the repository inherited from
  228. * the global settings and team affiliations.
  229. *
  230. * @param repository
  231. * if null only the globally specified scripts are returned
  232. * @return a list of scripts
  233. */
  234. public List<String> getPostReceiveScriptsInherited(RepositoryModel repository) {
  235. Set<String> scripts = new LinkedHashSet<String>();
  236. // Global Scripts
  237. for (String script : settings.get(Keys.groovy.postReceiveScripts).getStrings()) {
  238. if (script.endsWith(".groovy")) {
  239. scripts.add(script.substring(0, script.lastIndexOf('.')));
  240. } else {
  241. scripts.add(script);
  242. }
  243. }
  244. // Team Scripts
  245. if (repository != null) {
  246. for (String teamname : getPermittedTeamnames(repository)) {
  247. TeamModel team = getTeamModel(teamname);
  248. if (!ArrayUtils.isEmpty(team.postReceiveScripts)) {
  249. scripts.addAll(team.postReceiveScripts);
  250. }
  251. }
  252. }
  253. return new ArrayList<String>(scripts);
  254. }
  255. /**
  256. * Returns the list of unused Groovy post-receive push hook scripts that are
  257. * not already inherited by the repository. Script files must have .groovy
  258. * extension
  259. *
  260. * @param repository
  261. * optional parameter
  262. * @return list of available hook scripts
  263. */
  264. public List<String> getPostReceiveScriptsUnused(RepositoryModel repository) {
  265. Set<String> inherited = new TreeSet<String>(getPostReceiveScriptsInherited(repository));
  266. // create list of available scripts by excluding inherited scripts
  267. List<String> scripts = new ArrayList<String>();
  268. if (!ArrayUtils.isEmpty(settings.pushScripts)) {
  269. for (String script : settings.pushScripts) {
  270. if (!inherited.contains(script)) {
  271. scripts.add(script);
  272. }
  273. }
  274. }
  275. return scripts;
  276. }
  277. public ServerSettings getSettings() {
  278. return settings;
  279. }
  280. public ServerStatus getStatus() {
  281. return status;
  282. }
  283. public String getSettingDescription(String key) {
  284. return settings.get(key).description;
  285. }
  286. public List<RepositoryModel> refreshRepositories() throws IOException {
  287. Map<String, RepositoryModel> repositories = RpcUtils
  288. .getRepositories(url, account, password);
  289. allRepositories.clear();
  290. allRepositories.addAll(repositories.values());
  291. Collections.sort(allRepositories);
  292. markSubscribedFeeds();
  293. return allRepositories;
  294. }
  295. public List<UserModel> refreshUsers() throws IOException {
  296. List<UserModel> users = RpcUtils.getUsers(url, account, password);
  297. allUsers.clear();
  298. allUsers.addAll(users);
  299. Collections.sort(users);
  300. return allUsers;
  301. }
  302. public List<TeamModel> refreshTeams() throws IOException {
  303. List<TeamModel> teams = RpcUtils.getTeams(url, account, password);
  304. allTeams.clear();
  305. allTeams.addAll(teams);
  306. Collections.sort(teams);
  307. return allTeams;
  308. }
  309. public ServerSettings refreshSettings() throws IOException {
  310. settings = RpcUtils.getSettings(url, account, password);
  311. return settings;
  312. }
  313. public ServerStatus refreshStatus() throws IOException {
  314. status = RpcUtils.getStatus(url, account, password);
  315. return status;
  316. }
  317. public List<String> getBranches(String repository) {
  318. List<FeedModel> feeds = getAvailableFeeds(repository);
  319. List<String> branches = new ArrayList<String>();
  320. for (FeedModel feed : feeds) {
  321. branches.add(feed.branch);
  322. }
  323. Collections.sort(branches);
  324. return branches;
  325. }
  326. public List<FeedModel> getAvailableFeeds() {
  327. return availableFeeds;
  328. }
  329. public List<FeedModel> getAvailableFeeds(RepositoryModel repository) {
  330. return getAvailableFeeds(repository.name);
  331. }
  332. public List<FeedModel> getAvailableFeeds(String repository) {
  333. List<FeedModel> repositoryFeeds = new ArrayList<FeedModel>();
  334. if (repository == null) {
  335. return repositoryFeeds;
  336. }
  337. for (FeedModel feed : availableFeeds) {
  338. if (feed.repository.equalsIgnoreCase(repository)) {
  339. repositoryFeeds.add(feed);
  340. }
  341. }
  342. return repositoryFeeds;
  343. }
  344. public List<FeedModel> refreshAvailableFeeds() throws IOException {
  345. List<FeedModel> feeds = RpcUtils.getBranchFeeds(url, account, password);
  346. availableFeeds.clear();
  347. availableFeeds.addAll(feeds);
  348. markSubscribedFeeds();
  349. return availableFeeds;
  350. }
  351. public List<FeedEntryModel> refreshSubscribedFeeds(int page) throws IOException {
  352. Set<FeedEntryModel> allEntries = new HashSet<FeedEntryModel>();
  353. if (reg.feeds.size() > 0) {
  354. for (FeedModel feed : reg.feeds) {
  355. feed.lastRefreshDate = feed.currentRefreshDate;
  356. feed.currentRefreshDate = new Date();
  357. List<FeedEntryModel> entries = SyndicationUtils.readFeed(url, feed.repository,
  358. feed.branch, -1, page, account, password);
  359. allEntries.addAll(entries);
  360. }
  361. }
  362. reg.cacheFeeds();
  363. syndicatedEntries.clear();
  364. syndicatedEntries.addAll(allEntries);
  365. Collections.sort(syndicatedEntries);
  366. return syndicatedEntries;
  367. }
  368. public void updateSubscribedFeeds(List<FeedModel> list) {
  369. reg.updateSubscribedFeeds(list);
  370. markSubscribedFeeds();
  371. }
  372. private void markSubscribedFeeds() {
  373. subscribedRepositories.clear();
  374. for (FeedModel feed : availableFeeds) {
  375. // mark feed in the available list as subscribed
  376. feed.subscribed = reg.feeds.contains(feed);
  377. if (feed.subscribed) {
  378. subscribedRepositories.add(feed.repository.toLowerCase());
  379. }
  380. }
  381. }
  382. public Date getLastFeedRefresh(String repository, String branch) {
  383. FeedModel feed = new FeedModel();
  384. feed.repository = repository;
  385. feed.branch = branch;
  386. if (reg.feeds.contains(feed)) {
  387. int idx = reg.feeds.indexOf(feed);
  388. feed = reg.feeds.get(idx);
  389. return feed.lastRefreshDate;
  390. }
  391. return NEVER;
  392. }
  393. public boolean isSubscribed(RepositoryModel repository) {
  394. return subscribedRepositories.contains(repository.name.toLowerCase());
  395. }
  396. public List<FeedEntryModel> getSyndicatedEntries() {
  397. return syndicatedEntries;
  398. }
  399. public List<FeedEntryModel> log(String repository, String branch, int numberOfEntries, int page)
  400. throws IOException {
  401. return SyndicationUtils.readFeed(url, repository, branch, numberOfEntries, page, account,
  402. password);
  403. }
  404. public List<FeedEntryModel> search(String repository, String branch, String fragment,
  405. Constants.SearchType type, int numberOfEntries, int page) throws IOException {
  406. return SyndicationUtils.readSearchFeed(url, repository, branch, fragment, type,
  407. numberOfEntries, page, account, password);
  408. }
  409. public List<FederationModel> refreshFederationRegistrations() throws IOException {
  410. List<FederationModel> list = RpcUtils.getFederationRegistrations(url, account, password);
  411. federationRegistrations.clear();
  412. federationRegistrations.addAll(list);
  413. return federationRegistrations;
  414. }
  415. public List<UserModel> getUsers() {
  416. return allUsers;
  417. }
  418. public UserModel getUser(String username) {
  419. for (UserModel user : getUsers()) {
  420. if (user.username.equalsIgnoreCase(username)) {
  421. return user;
  422. }
  423. }
  424. return null;
  425. }
  426. public List<String> getUsernames() {
  427. List<String> usernames = new ArrayList<String>();
  428. for (UserModel user : this.allUsers) {
  429. usernames.add(user.username);
  430. }
  431. Collections.sort(usernames);
  432. return usernames;
  433. }
  434. public List<String> getPermittedUsernames(RepositoryModel repository) {
  435. List<String> usernames = new ArrayList<String>();
  436. for (UserModel user : this.allUsers) {
  437. if (user.hasRepositoryPermission(repository.name)) {
  438. usernames.add(user.username);
  439. }
  440. }
  441. return usernames;
  442. }
  443. /**
  444. * Returns the effective list of permissions for this user, taking into account
  445. * team memberships, ownerships.
  446. *
  447. * @param user
  448. * @return the effective list of permissions for the user
  449. */
  450. public List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user) {
  451. Set<RegistrantAccessPermission> set = new LinkedHashSet<RegistrantAccessPermission>();
  452. set.addAll(user.getRepositoryPermissions());
  453. // Flag missing repositories
  454. for (RegistrantAccessPermission permission : set) {
  455. if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {
  456. RepositoryModel rm = getRepository(permission.registrant);
  457. if (rm == null) {
  458. permission.permissionType = PermissionType.MISSING;
  459. permission.mutable = false;
  460. continue;
  461. }
  462. }
  463. }
  464. // TODO reconsider ownership as a user property
  465. // manually specify personal repository ownerships
  466. for (RepositoryModel rm : allRepositories) {
  467. if (rm.isUsersPersonalRepository(user.username) || rm.isOwner(user.username)) {
  468. RegistrantAccessPermission rp = new RegistrantAccessPermission(rm.name, AccessPermission.REWIND,
  469. PermissionType.OWNER, RegistrantType.REPOSITORY, null, false);
  470. // user may be owner of a repository to which they've inherited
  471. // a team permission, replace any existing perm with owner perm
  472. set.remove(rp);
  473. set.add(rp);
  474. }
  475. }
  476. List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>(set);
  477. Collections.sort(list);
  478. return list;
  479. }
  480. public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) {
  481. List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
  482. if (AccessRestrictionType.NONE.equals(repository.accessRestriction)) {
  483. // no permissions needed, REWIND for everyone!
  484. return list;
  485. }
  486. if (AuthorizationControl.AUTHENTICATED.equals(repository.authorizationControl)) {
  487. // no permissions needed, REWIND for authenticated!
  488. return list;
  489. }
  490. // NAMED users and teams
  491. for (UserModel user : allUsers) {
  492. RegistrantAccessPermission ap = user.getRepositoryPermission(repository);
  493. if (ap.permission.exceeds(AccessPermission.NONE)) {
  494. list.add(ap);
  495. }
  496. }
  497. return list;
  498. }
  499. public boolean setUserAccessPermissions(RepositoryModel repository, List<RegistrantAccessPermission> permissions) throws IOException {
  500. return RpcUtils.setRepositoryMemberPermissions(repository, permissions, url, account, password);
  501. }
  502. public List<TeamModel> getTeams() {
  503. return allTeams;
  504. }
  505. public List<String> getTeamnames() {
  506. List<String> teamnames = new ArrayList<String>();
  507. for (TeamModel team : this.allTeams) {
  508. teamnames.add(team.name);
  509. }
  510. Collections.sort(teamnames);
  511. return teamnames;
  512. }
  513. public List<String> getPermittedTeamnames(RepositoryModel repository) {
  514. List<String> teamnames = new ArrayList<String>();
  515. for (TeamModel team : this.allTeams) {
  516. if (team.hasRepositoryPermission(repository.name)) {
  517. teamnames.add(team.name);
  518. }
  519. }
  520. return teamnames;
  521. }
  522. public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {
  523. List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
  524. for (TeamModel team : allTeams) {
  525. RegistrantAccessPermission ap = team.getRepositoryPermission(repository);
  526. if (ap.permission.exceeds(AccessPermission.NONE)) {
  527. list.add(ap);
  528. }
  529. }
  530. Collections.sort(list);
  531. return list;
  532. }
  533. public boolean setTeamAccessPermissions(RepositoryModel repository, List<RegistrantAccessPermission> permissions) throws IOException {
  534. return RpcUtils.setRepositoryTeamPermissions(repository, permissions, url, account, password);
  535. }
  536. public TeamModel getTeamModel(String name) {
  537. for (TeamModel team : allTeams) {
  538. if (team.name.equalsIgnoreCase(name)) {
  539. return team;
  540. }
  541. }
  542. return null;
  543. }
  544. public List<String> getFederationSets() {
  545. return settings.get(Keys.federation.sets).getStrings();
  546. }
  547. public List<RepositoryModel> getRepositories() {
  548. return allRepositories;
  549. }
  550. public RepositoryModel getRepository(String name) {
  551. for (RepositoryModel repository : allRepositories) {
  552. if (repository.name.equalsIgnoreCase(name)) {
  553. return repository;
  554. }
  555. }
  556. return null;
  557. }
  558. public boolean createRepository(RepositoryModel repository, List<RegistrantAccessPermission> userPermissions)
  559. throws IOException {
  560. return createRepository(repository, userPermissions, null);
  561. }
  562. public boolean createRepository(RepositoryModel repository, List<RegistrantAccessPermission> userPermissions,
  563. List<RegistrantAccessPermission> teamPermissions) throws IOException {
  564. boolean success = true;
  565. success &= RpcUtils.createRepository(repository, url, account, password);
  566. if (userPermissions != null && userPermissions.size() > 0) {
  567. // if new repository has named members, set them
  568. success &= RpcUtils.setRepositoryMemberPermissions(repository, userPermissions, url, account,
  569. password);
  570. }
  571. if (teamPermissions != null && teamPermissions.size() > 0) {
  572. // if new repository has named teams, set them
  573. success &= RpcUtils.setRepositoryTeamPermissions(repository, teamPermissions, url, account,
  574. password);
  575. }
  576. return success;
  577. }
  578. public boolean updateRepository(String name, RepositoryModel repository,
  579. List<RegistrantAccessPermission> userPermissions) throws IOException {
  580. return updateRepository(name, repository, userPermissions, null);
  581. }
  582. public boolean updateRepository(String name, RepositoryModel repository,
  583. List<RegistrantAccessPermission> userPermissions, List<RegistrantAccessPermission> teamPermissions) throws IOException {
  584. boolean success = true;
  585. success &= RpcUtils.updateRepository(name, repository, url, account, password);
  586. // set the repository members
  587. if (userPermissions != null) {
  588. success &= RpcUtils.setRepositoryMemberPermissions(repository, userPermissions, url, account,
  589. password);
  590. }
  591. if (teamPermissions != null) {
  592. success &= RpcUtils.setRepositoryTeamPermissions(repository, teamPermissions, url, account,
  593. password);
  594. }
  595. return success;
  596. }
  597. public boolean deleteRepository(RepositoryModel repository) throws IOException {
  598. return RpcUtils.deleteRepository(repository, url, account, password);
  599. }
  600. public boolean clearRepositoryCache() throws IOException {
  601. return RpcUtils.clearRepositoryCache(url, account, password);
  602. }
  603. public boolean createUser(UserModel user) throws IOException {
  604. return RpcUtils.createUser(user, url, account, password);
  605. }
  606. public boolean updateUser(String name, UserModel user) throws IOException {
  607. return RpcUtils.updateUser(name, user, url, account, password);
  608. }
  609. public boolean deleteUser(UserModel user) throws IOException {
  610. return RpcUtils.deleteUser(user, url, account, password);
  611. }
  612. public boolean createTeam(TeamModel team) throws IOException {
  613. return RpcUtils.createTeam(team, url, account, password);
  614. }
  615. public boolean updateTeam(String name, TeamModel team) throws IOException {
  616. return RpcUtils.updateTeam(name, team, url, account, password);
  617. }
  618. public boolean deleteTeam(TeamModel team) throws IOException {
  619. return RpcUtils.deleteTeam(team, url, account, password);
  620. }
  621. public boolean updateSettings(Map<String, String> newSettings) throws IOException {
  622. return RpcUtils.updateSettings(newSettings, url, account, password);
  623. }
  624. }