You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GitblitClient.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  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. if (!ArrayUtils.isEmpty(settings.pushScripts)) {
  220. for (String script : settings.pushScripts) {
  221. if (!inherited.contains(script)) {
  222. scripts.add(script);
  223. }
  224. }
  225. }
  226. return scripts;
  227. }
  228. /**
  229. * Returns the list of post-receive scripts the repository inherited from
  230. * the global settings and team affiliations.
  231. *
  232. * @param repository
  233. * if null only the globally specified scripts are returned
  234. * @return a list of scripts
  235. */
  236. public List<String> getPostReceiveScriptsInherited(RepositoryModel repository) {
  237. Set<String> scripts = new LinkedHashSet<String>();
  238. // Global Scripts
  239. for (String script : settings.get(Keys.groovy.postReceiveScripts).getStrings()) {
  240. if (script.endsWith(".groovy")) {
  241. scripts.add(script.substring(0, script.lastIndexOf('.')));
  242. } else {
  243. scripts.add(script);
  244. }
  245. }
  246. // Team Scripts
  247. if (repository != null) {
  248. for (String teamname : getPermittedTeamnames(repository)) {
  249. TeamModel team = getTeamModel(teamname);
  250. if (!ArrayUtils.isEmpty(team.postReceiveScripts)) {
  251. scripts.addAll(team.postReceiveScripts);
  252. }
  253. }
  254. }
  255. return new ArrayList<String>(scripts);
  256. }
  257. /**
  258. * Returns the list of unused Groovy post-receive push hook scripts that are
  259. * not already inherited by the repository. Script files must have .groovy
  260. * extension
  261. *
  262. * @param repository
  263. * optional parameter
  264. * @return list of available hook scripts
  265. */
  266. public List<String> getPostReceiveScriptsUnused(RepositoryModel repository) {
  267. Set<String> inherited = new TreeSet<String>(getPostReceiveScriptsInherited(repository));
  268. // create list of available scripts by excluding inherited scripts
  269. List<String> scripts = new ArrayList<String>();
  270. if (!ArrayUtils.isEmpty(settings.pushScripts)) {
  271. for (String script : settings.pushScripts) {
  272. if (!inherited.contains(script)) {
  273. scripts.add(script);
  274. }
  275. }
  276. }
  277. return scripts;
  278. }
  279. public ServerSettings getSettings() {
  280. return settings;
  281. }
  282. public ServerStatus getStatus() {
  283. return status;
  284. }
  285. public String getSettingDescription(String key) {
  286. return settings.get(key).description;
  287. }
  288. public List<RepositoryModel> refreshRepositories() throws IOException {
  289. Map<String, RepositoryModel> repositories = RpcUtils
  290. .getRepositories(url, account, password);
  291. allRepositories.clear();
  292. allRepositories.addAll(repositories.values());
  293. Collections.sort(allRepositories);
  294. markSubscribedFeeds();
  295. return allRepositories;
  296. }
  297. public List<UserModel> refreshUsers() throws IOException {
  298. List<UserModel> users = RpcUtils.getUsers(url, account, password);
  299. allUsers.clear();
  300. allUsers.addAll(users);
  301. Collections.sort(users);
  302. return allUsers;
  303. }
  304. public List<TeamModel> refreshTeams() throws IOException {
  305. List<TeamModel> teams = RpcUtils.getTeams(url, account, password);
  306. allTeams.clear();
  307. allTeams.addAll(teams);
  308. Collections.sort(teams);
  309. return allTeams;
  310. }
  311. public ServerSettings refreshSettings() throws IOException {
  312. settings = RpcUtils.getSettings(url, account, password);
  313. return settings;
  314. }
  315. public ServerStatus refreshStatus() throws IOException {
  316. status = RpcUtils.getStatus(url, account, password);
  317. return status;
  318. }
  319. public List<String> getBranches(String repository) {
  320. List<FeedModel> feeds = getAvailableFeeds(repository);
  321. List<String> branches = new ArrayList<String>();
  322. for (FeedModel feed : feeds) {
  323. branches.add(feed.branch);
  324. }
  325. Collections.sort(branches);
  326. return branches;
  327. }
  328. public List<FeedModel> getAvailableFeeds() {
  329. return availableFeeds;
  330. }
  331. public List<FeedModel> getAvailableFeeds(RepositoryModel repository) {
  332. return getAvailableFeeds(repository.name);
  333. }
  334. public List<FeedModel> getAvailableFeeds(String repository) {
  335. List<FeedModel> repositoryFeeds = new ArrayList<FeedModel>();
  336. if (repository == null) {
  337. return repositoryFeeds;
  338. }
  339. for (FeedModel feed : availableFeeds) {
  340. if (feed.repository.equalsIgnoreCase(repository)) {
  341. repositoryFeeds.add(feed);
  342. }
  343. }
  344. return repositoryFeeds;
  345. }
  346. public List<FeedModel> refreshAvailableFeeds() throws IOException {
  347. List<FeedModel> feeds = RpcUtils.getBranchFeeds(url, account, password);
  348. availableFeeds.clear();
  349. availableFeeds.addAll(feeds);
  350. markSubscribedFeeds();
  351. return availableFeeds;
  352. }
  353. public List<FeedEntryModel> refreshSubscribedFeeds(int page) throws IOException {
  354. Set<FeedEntryModel> allEntries = new HashSet<FeedEntryModel>();
  355. if (reg.feeds.size() > 0) {
  356. for (FeedModel feed : reg.feeds) {
  357. feed.lastRefreshDate = feed.currentRefreshDate;
  358. feed.currentRefreshDate = new Date();
  359. List<FeedEntryModel> entries = SyndicationUtils.readFeed(url, feed.repository,
  360. feed.branch, -1, page, account, password);
  361. allEntries.addAll(entries);
  362. }
  363. }
  364. reg.cacheFeeds();
  365. syndicatedEntries.clear();
  366. syndicatedEntries.addAll(allEntries);
  367. Collections.sort(syndicatedEntries);
  368. return syndicatedEntries;
  369. }
  370. public void updateSubscribedFeeds(List<FeedModel> list) {
  371. reg.updateSubscribedFeeds(list);
  372. markSubscribedFeeds();
  373. }
  374. private void markSubscribedFeeds() {
  375. subscribedRepositories.clear();
  376. for (FeedModel feed : availableFeeds) {
  377. // mark feed in the available list as subscribed
  378. feed.subscribed = reg.feeds.contains(feed);
  379. if (feed.subscribed) {
  380. subscribedRepositories.add(feed.repository.toLowerCase());
  381. }
  382. }
  383. }
  384. public Date getLastFeedRefresh(String repository, String branch) {
  385. FeedModel feed = new FeedModel();
  386. feed.repository = repository;
  387. feed.branch = branch;
  388. if (reg.feeds.contains(feed)) {
  389. int idx = reg.feeds.indexOf(feed);
  390. feed = reg.feeds.get(idx);
  391. return feed.lastRefreshDate;
  392. }
  393. return NEVER;
  394. }
  395. public boolean isSubscribed(RepositoryModel repository) {
  396. return subscribedRepositories.contains(repository.name.toLowerCase());
  397. }
  398. public List<FeedEntryModel> getSyndicatedEntries() {
  399. return syndicatedEntries;
  400. }
  401. public List<FeedEntryModel> log(String repository, String branch, int numberOfEntries, int page)
  402. throws IOException {
  403. return SyndicationUtils.readFeed(url, repository, branch, numberOfEntries, page, account,
  404. password);
  405. }
  406. public List<FeedEntryModel> search(String repository, String branch, String fragment,
  407. Constants.SearchType type, int numberOfEntries, int page) throws IOException {
  408. return SyndicationUtils.readSearchFeed(url, repository, branch, fragment, type,
  409. numberOfEntries, page, account, password);
  410. }
  411. public List<FederationModel> refreshFederationRegistrations() throws IOException {
  412. List<FederationModel> list = RpcUtils.getFederationRegistrations(url, account, password);
  413. federationRegistrations.clear();
  414. federationRegistrations.addAll(list);
  415. return federationRegistrations;
  416. }
  417. public List<UserModel> getUsers() {
  418. return allUsers;
  419. }
  420. public UserModel getUser(String username) {
  421. for (UserModel user : getUsers()) {
  422. if (user.username.equalsIgnoreCase(username)) {
  423. return user;
  424. }
  425. }
  426. return null;
  427. }
  428. public List<String> getUsernames() {
  429. List<String> usernames = new ArrayList<String>();
  430. for (UserModel user : this.allUsers) {
  431. usernames.add(user.username);
  432. }
  433. Collections.sort(usernames);
  434. return usernames;
  435. }
  436. public List<String> getPermittedUsernames(RepositoryModel repository) {
  437. List<String> usernames = new ArrayList<String>();
  438. for (UserModel user : this.allUsers) {
  439. if (user.hasRepositoryPermission(repository.name)) {
  440. usernames.add(user.username);
  441. }
  442. }
  443. return usernames;
  444. }
  445. /**
  446. * Returns the effective list of permissions for this user, taking into account
  447. * team memberships, ownerships.
  448. *
  449. * @param user
  450. * @return the effective list of permissions for the user
  451. */
  452. public List<RegistrantAccessPermission> getUserAccessPermissions(UserModel user) {
  453. Set<RegistrantAccessPermission> set = new LinkedHashSet<RegistrantAccessPermission>();
  454. set.addAll(user.getRepositoryPermissions());
  455. // Flag missing repositories
  456. for (RegistrantAccessPermission permission : set) {
  457. if (permission.mutable && PermissionType.EXPLICIT.equals(permission.permissionType)) {
  458. RepositoryModel rm = getRepository(permission.registrant);
  459. if (rm == null) {
  460. permission.permissionType = PermissionType.MISSING;
  461. permission.mutable = false;
  462. continue;
  463. }
  464. }
  465. }
  466. // TODO reconsider ownership as a user property
  467. // manually specify personal repository ownerships
  468. for (RepositoryModel rm : allRepositories) {
  469. if (rm.isUsersPersonalRepository(user.username) || rm.isOwner(user.username)) {
  470. RegistrantAccessPermission rp = new RegistrantAccessPermission(rm.name, AccessPermission.REWIND,
  471. PermissionType.OWNER, RegistrantType.REPOSITORY, null, false);
  472. // user may be owner of a repository to which they've inherited
  473. // a team permission, replace any existing perm with owner perm
  474. set.remove(rp);
  475. set.add(rp);
  476. }
  477. }
  478. List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>(set);
  479. Collections.sort(list);
  480. return list;
  481. }
  482. public List<RegistrantAccessPermission> getUserAccessPermissions(RepositoryModel repository) {
  483. List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
  484. if (AccessRestrictionType.NONE.equals(repository.accessRestriction)) {
  485. // no permissions needed, REWIND for everyone!
  486. return list;
  487. }
  488. if (AuthorizationControl.AUTHENTICATED.equals(repository.authorizationControl)) {
  489. // no permissions needed, REWIND for authenticated!
  490. return list;
  491. }
  492. // NAMED users and teams
  493. for (UserModel user : allUsers) {
  494. RegistrantAccessPermission ap = user.getRepositoryPermission(repository);
  495. if (ap.permission.exceeds(AccessPermission.NONE)) {
  496. list.add(ap);
  497. }
  498. }
  499. return list;
  500. }
  501. public boolean setUserAccessPermissions(RepositoryModel repository, List<RegistrantAccessPermission> permissions) throws IOException {
  502. return RpcUtils.setRepositoryMemberPermissions(repository, permissions, url, account, password);
  503. }
  504. public List<TeamModel> getTeams() {
  505. return allTeams;
  506. }
  507. public List<String> getTeamnames() {
  508. List<String> teamnames = new ArrayList<String>();
  509. for (TeamModel team : this.allTeams) {
  510. teamnames.add(team.name);
  511. }
  512. Collections.sort(teamnames);
  513. return teamnames;
  514. }
  515. public List<String> getPermittedTeamnames(RepositoryModel repository) {
  516. List<String> teamnames = new ArrayList<String>();
  517. for (TeamModel team : this.allTeams) {
  518. if (team.hasRepositoryPermission(repository.name)) {
  519. teamnames.add(team.name);
  520. }
  521. }
  522. return teamnames;
  523. }
  524. public List<RegistrantAccessPermission> getTeamAccessPermissions(RepositoryModel repository) {
  525. List<RegistrantAccessPermission> list = new ArrayList<RegistrantAccessPermission>();
  526. for (TeamModel team : allTeams) {
  527. RegistrantAccessPermission ap = team.getRepositoryPermission(repository);
  528. if (ap.permission.exceeds(AccessPermission.NONE)) {
  529. list.add(ap);
  530. }
  531. }
  532. Collections.sort(list);
  533. return list;
  534. }
  535. public boolean setTeamAccessPermissions(RepositoryModel repository, List<RegistrantAccessPermission> permissions) throws IOException {
  536. return RpcUtils.setRepositoryTeamPermissions(repository, permissions, url, account, password);
  537. }
  538. public TeamModel getTeamModel(String name) {
  539. for (TeamModel team : allTeams) {
  540. if (team.name.equalsIgnoreCase(name)) {
  541. return team;
  542. }
  543. }
  544. return null;
  545. }
  546. public List<String> getFederationSets() {
  547. return settings.get(Keys.federation.sets).getStrings();
  548. }
  549. public List<RepositoryModel> getRepositories() {
  550. return allRepositories;
  551. }
  552. public RepositoryModel getRepository(String name) {
  553. for (RepositoryModel repository : allRepositories) {
  554. if (repository.name.equalsIgnoreCase(name)) {
  555. return repository;
  556. }
  557. }
  558. return null;
  559. }
  560. public boolean createRepository(RepositoryModel repository, List<RegistrantAccessPermission> userPermissions)
  561. throws IOException {
  562. return createRepository(repository, userPermissions, null);
  563. }
  564. public boolean createRepository(RepositoryModel repository, List<RegistrantAccessPermission> userPermissions,
  565. List<RegistrantAccessPermission> teamPermissions) throws IOException {
  566. boolean success = true;
  567. success &= RpcUtils.createRepository(repository, url, account, password);
  568. if (userPermissions != null && userPermissions.size() > 0) {
  569. // if new repository has named members, set them
  570. success &= RpcUtils.setRepositoryMemberPermissions(repository, userPermissions, url, account,
  571. password);
  572. }
  573. if (teamPermissions != null && teamPermissions.size() > 0) {
  574. // if new repository has named teams, set them
  575. success &= RpcUtils.setRepositoryTeamPermissions(repository, teamPermissions, url, account,
  576. password);
  577. }
  578. return success;
  579. }
  580. public boolean updateRepository(String name, RepositoryModel repository,
  581. List<RegistrantAccessPermission> userPermissions) throws IOException {
  582. return updateRepository(name, repository, userPermissions, null);
  583. }
  584. public boolean updateRepository(String name, RepositoryModel repository,
  585. List<RegistrantAccessPermission> userPermissions, List<RegistrantAccessPermission> teamPermissions) throws IOException {
  586. boolean success = true;
  587. success &= RpcUtils.updateRepository(name, repository, url, account, password);
  588. // set the repository members
  589. if (userPermissions != null) {
  590. success &= RpcUtils.setRepositoryMemberPermissions(repository, userPermissions, url, account,
  591. password);
  592. }
  593. if (teamPermissions != null) {
  594. success &= RpcUtils.setRepositoryTeamPermissions(repository, teamPermissions, url, account,
  595. password);
  596. }
  597. return success;
  598. }
  599. public boolean deleteRepository(RepositoryModel repository) throws IOException {
  600. return RpcUtils.deleteRepository(repository, url, account, password);
  601. }
  602. public boolean clearRepositoryCache() throws IOException {
  603. return RpcUtils.clearRepositoryCache(url, account, password);
  604. }
  605. public boolean createUser(UserModel user) throws IOException {
  606. return RpcUtils.createUser(user, url, account, password);
  607. }
  608. public boolean updateUser(String name, UserModel user) throws IOException {
  609. return RpcUtils.updateUser(name, user, url, account, password);
  610. }
  611. public boolean deleteUser(UserModel user) throws IOException {
  612. return RpcUtils.deleteUser(user, url, account, password);
  613. }
  614. public boolean createTeam(TeamModel team) throws IOException {
  615. return RpcUtils.createTeam(team, url, account, password);
  616. }
  617. public boolean updateTeam(String name, TeamModel team) throws IOException {
  618. return RpcUtils.updateTeam(name, team, url, account, password);
  619. }
  620. public boolean deleteTeam(TeamModel team) throws IOException {
  621. return RpcUtils.deleteTeam(team, url, account, password);
  622. }
  623. public boolean updateSettings(Map<String, String> newSettings) throws IOException {
  624. return RpcUtils.updateSettings(newSettings, url, account, password);
  625. }
  626. }