Skip to content

Commit

Permalink
Bug 1089665: Show application members who have their membership via d…
Browse files Browse the repository at this point in the history
…omain
  • Loading branch information
liggitt committed Apr 21, 2014
1 parent 0e9730c commit 566729f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/rhc/commands/member.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Member < Base
'--ids'.
DESC
option ['--ids'], "Display the IDs of each member", :optional => true
option ['--all'], "Display all members, including indirect members", :optional => true
option ['--all'], "Display all members, including members of teams", :optional => true
takes_application_or_domain :argument => true
alias_action :members, :root_command => true
def list(path)
Expand All @@ -54,7 +54,17 @@ def list(path)
if options.all
show_members = members.sort
else
show_members = members.select{|m| m.owner? || m.explicit_role? }.sort
show_members = members.select do |m|
if m.owner?
true
elsif m.explicit_role?
true
elsif m.from.any? {|f| f["type"] != "team" }
true
else
false
end
end.sort
end
show_name = show_members.any?{ |m| m.name.presence && m.name != m.login }
show_login = show_members.any?{ |m| m.login.presence }
Expand All @@ -81,7 +91,7 @@ def list(path)

if show_members.count < members.count
paragraph do
info "Pass --all to display all members, including indirect members."
info "Pass --all to display all members, including members of teams."
end
end

Expand Down Expand Up @@ -348,6 +358,8 @@ def search_team_members(members, names)
def role_description(member, teams=[])
if member.owner?
"#{member.role} (owner)"
elsif member.explicit_role != member.role && member.from.all? {|f| f['type'] == 'domain'}
"#{member.role} (via domain)"
elsif member.explicit_role != member.role && teams.present? && (teams_with_role = teams.select{|t| t.role == member.role }).present?
"#{member.role} (via #{teams_with_role.map(&:name).sort.join(', ')})"
else
Expand Down
10 changes: 10 additions & 0 deletions spec/rhc/commands/member_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ def with_mock_app
let(:team_viewer_member2){ RHC::Rest::Membership::Member.new(:id => '24', :role => 'view', :login => 'memberviewer2', :type => 'user', :from => [{'id' => '13', 'type' => 'team'}]) }
let(:team_viewer_member3){ RHC::Rest::Membership::Member.new(:id => '25', :role => 'view', :login => 'memberviewer3', :type => 'user', :from => [{'id' => '13', 'type' => 'team'}]) }
let(:team_viewer_and_explicit_member){ RHC::Rest::Membership::Member.new(:id => '26', :role => 'view', :explicit_role => 'view', :login => 'memberviewerexplicitedit', :type => 'user', :from => [{'id' => '13', 'type' => 'team'}]) }
let(:app_member_via_domain) { RHC::Rest::Membership::Member.new(:id => '27', :role => 'view', :login => 'app_member_via_domain', :type => 'user', :from => [{'type' => 'domain'}]) }

describe 'show-domain' do
context 'with members' do
Expand Down Expand Up @@ -122,6 +123,15 @@ def with_mock_app
it { expect { run }.to exit_with_code(1) }
it { run_output.should =~ /The server does not support adding or removing members/ }

context "with only implicit members via domain" do
let(:supports_members){ true }
before{ with_mock_app.add_member(app_member_via_domain) }
it { expect { run }.to exit_with_code(0) }
it { run_output.should =~ /app_member_via_domain\s+view \(via domain\)/ }
it("should not show the name column") { run_output.should =~ /^Login\s+Role\s+Type$/ }
it("should not show the --all message") { run_output.should_not =~ /--all/ }
end

context "with only owner" do
let(:supports_members){ true }
before{ with_mock_app.add_member(owner) }
Expand Down

0 comments on commit 566729f

Please sign in to comment.