public interface

RefRestrictionService

com.atlassian.bitbucket.repository.ref.restriction.RefRestrictionService

Class Overview

A service that manages restrictions to refs.

Repository admin permissions are required for all operations unless specified.

Summary

Public Methods
@Nullable RefRestriction getById(int id)
Get a RefRestriction by its ID.
boolean hasPermission(RefAccessRequest request)
Check if the current user has permission to perform an action on a ref or collection of MinimalRef refs.
@Nonnull Multimap<RefChangeRefRestriction> match(RestrictionMatchRequest request)
Match a proposed list of refChanges (optionally taking into consideration a specific user who is about to perform them) with any restriction(s) that would prevent the change.
boolean removeRefRestriction(int id)
Remove a RefRestriction by its ID.
@Nonnull Page<RefRestriction> search(RestrictionSearchRequest request, PageRequest pageRequest)
Search for restrictions based on the RestrictionSearchRequest.
@Nonnull RefRestriction setRestriction(SetRestrictionRequest request)
Sets a restriction based on the SetRestrictionRequest.
@Nonnull List<RefRestriction> setRestrictions(Collection<SetRestrictionRequest> requests)
Sets all the restrictions specified by the provided requests.

Public Methods

@Nullable public RefRestriction getById (int id)

Get a RefRestriction by its ID.

Parameters
id the ID associated with the RefRestriction
Returns

public boolean hasPermission (RefAccessRequest request)

Check if the current user has permission to perform an action on a ref or collection of MinimalRef refs. This method does not require any permissions and can be called by any user.

Parameters
request specifies which branches and which access rights to check for
Returns
  • true if the user can take the action specified in request, false otherwise

@Nonnull public Multimap<RefChangeRefRestriction> match (RestrictionMatchRequest request)

Match a proposed list of refChanges (optionally taking into consideration a specific user who is about to perform them) with any restriction(s) that would prevent the change. The results are returned as a Multimap that matches up each disallowed refChange to any restriction(s) that match it. This allows a caller to discover for any arbitrary set of refChanges not only whether they will be prevented by restrictions but also which specific restriction(s) apply to each individual refChange.

If the FAST_FORWARD_ONLY restriction type is included in the request, then the fromHash and toHash of any matching refChanges will be checked to determine if the ref change is a fast-forward-only change or would attempt to rewrite history (and therefore be prevented). This requires fromHash and toHash to be valid for the specified repository, or com.atlassian.bitbucket.scm.CommandFailedException will be thrown.

Parameters
request specifies the repository, types, refChanges, and (optionally) a user for the proposed change.
Returns
  • a Multimap containing RefRestriction(s) (if any) that apply to each refChange specified in the input. If the refChanges would not be prevented by any restriction, then an empty Multimap is returned.
Throws
if FAST_FORWARD_ONLY restrictions are checked and fromHash and toHash are invalid for the specified repository.

public boolean removeRefRestriction (int id)

Remove a RefRestriction by its ID.

Parameters
id the ID associated with the RefRestriction
Returns

@Nonnull public Page<RefRestriction> search (RestrictionSearchRequest request, PageRequest pageRequest)

Search for restrictions based on the RestrictionSearchRequest.

Parameters
request the RestrictionSearchRequest which specifies the restrictions to search for
pageRequest the PageRequest which specifies the page to return
Returns

@Nonnull public RefRestriction setRestriction (SetRestrictionRequest request)

Sets a restriction based on the SetRestrictionRequest. If the same RefRestriction already exists it will be overwritten.

Parameters
request the SetRestrictionRequest which specifies the restriction to be set
Returns

@Nonnull public List<RefRestriction> setRestrictions (Collection<SetRestrictionRequest> requests)

Sets all the restrictions specified by the provided requests.

Parameters
requests a list of requests which specify the restrictions to be set
Returns