Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Privileges #79

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions lib/bitbucket_rest_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,30 +58,31 @@ def lookup_constant(const_name)
extend AutoloadHelper

autoload_all 'bitbucket_rest_api',
:API => 'api',
:ApiFactory => 'api_factory',
:Authorization => 'authorization',
:Authorizations => 'authorizations',
:Validations => 'validations',
:ParameterFilter => 'parameter_filter',
:Normalizer => 'normalizer',
:Client => 'client',
:CoreExt => 'core_ext',
:Request => 'request',
:Response => 'response',
:Result => 'result',

:Repos => 'repos',
#:Error => 'error',
:Issues => 'issues',
:User => 'user',
:Users => 'users',
:Invitations => 'invitations',
:Teams => 'teams'

:API => 'api',
:ApiFactory => 'api_factory',
:Authorization => 'authorization',
:Authorizations => 'authorizations',
:Validations => 'validations',
:ParameterFilter => 'parameter_filter',
:Normalizer => 'normalizer',
:Client => 'client',
:CoreExt => 'core_ext',
:Request => 'request',
:Response => 'response',
:Result => 'result',

:Repos => 'repos',
#:Error => 'error',
:Issues => 'issues',
:User => 'user',
:Users => 'users',
:Invitations => 'invitations',
:Privileges => 'privileges',
:Teams => 'teams'

#:Teams => 'teams',
#:PullRequests => 'pull_requests',
#:Users => 'users',
#:Events => 'events',
#:Search => 'search',
#:PageLinks => 'page_links',
Expand Down
4 changes: 4 additions & 0 deletions lib/bitbucket_rest_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ def user_api(options = {})
def invitations(options = {})
@invitations ||= ApiFactory.new "Invitations", options
end

def privileges(options = {})
@privileges ||= ApiFactory.new 'Privileges', options
end
end # Client
end # BitBucket
56 changes: 56 additions & 0 deletions lib/bitbucket_rest_api/privileges.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# encoding: utf-8

module BitBucket
class Privileges < API
VALID_KEY_PARAM_NAMES = %w(filter).freeze

# Creates new Privileges API
def initialize(options = {})
super(options)
end

# Gets a list of the privileges granted on a repository.
#
# = Parameters
# *<tt>filter</tt> - Filters for a particular privilege. The acceptable values are:<tt>read</tt>, <tt>write</tt> and <tt>admin</tt>.
#
# = Examples
# bitbucket = BitBucket.new
# bitbucket.privileges.list 'user-name', 'repo-name', :filter => "admin"
#
def list_on_repo(user_name, repo_name, params={})
_update_user_repo_params(user_name, repo_name)
_validate_user_repo_params(user, repo) unless user? && repo?

normalize! params
filter! VALID_KEY_PARAM_NAMES, params

response = get_request("/1.0/privileges/#{user}/#{repo.downcase}/", params)
return response unless block_given?
response.each { |el| yield el }
end
alias :all_on_repo :list_on_repo

# Gets a list of all the privilege across all an account's repositories.
#
# = Parameters
# *<tt>filter</tt> - Filters for a particular privilege. The acceptable values are:<tt>read</tt>, <tt>write</tt> and <tt>admin</tt>.
#
# = Examples
# bitbucket = BitBucket.new
# bitbucket.privileges.list 'user-name', :filter => "admin"
#
def list(user_name, params={})
_update_user_repo_params(user_name)
_validate_presence_of user_name

normalize! params
filter! VALID_KEY_PARAM_NAMES, params

response = get_request("/1.0/privileges/#{user}/", params)
return response unless block_given?
response.each { |el| yield el }
end
alias :all :list
end # Privileges
end # BitBucket
1 change: 1 addition & 0 deletions spec/bitbucket_rest_api/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
expect(client.teams).to be_a BitBucket::Teams
expect(client.pull_requests).to be_a BitBucket::Repos::PullRequest
expect(client.oauth).to be_a BitBucket::Request::OAuth
expect(client.privileges).to be_a BitBucket::Privileges
end
end
35 changes: 35 additions & 0 deletions spec/bitbucket_rest_api/privileges_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'spec_helper'

describe BitBucket::Privileges do
subject { described_class.new }

describe '#list_on_repo' do
before do
expect(subject).to receive(:request).with(
:get,
"/1.0/privileges/mock_username/mock_repo/",
{ 'filter' => 'admin' },
{}
)
end

it 'sends a GET request for privileges granted on the given repo filtered with filter param' do
subject.list_on_repo('mock_username', 'mock_repo', filter: "admin")
end
end

describe '#list' do
before do
expect(subject).to receive(:request).with(
:get,
"/1.0/privileges/mock_username/",
{ 'filter' => 'admin' },
{}
)
end

it "sends a GET request for privileges granted on all user's repositories filtered with filter param" do
subject.list('mock_username', filter: "admin")
end
end
end