Class: Cyclid::Cli::Member
- Defined in:
- lib/cyclid/cli/organization/member.rb
Overview
Commands for managing organization members
Instance Method Summary collapse
- #add(*users) ⇒ Object
- #list ⇒ Object
- #permission(user, permission) ⇒ Object
- #remove(*users) ⇒ Object
- #show(user) ⇒ Object
Instance Method Details
#add(*users) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/cyclid/cli/organization/member.rb', line 20 def add(*users) org = client.org_get(client.config.organization) # Concat the new list with the existing list and remove any # duplicates. user_list = org['users'] user_list.concat users user_list.uniq! client.org_modify(client.config.organization, members: user_list) rescue StandardError => ex abort "Failed to add users to the organization: #{ex}" end |
#list ⇒ Object
70 71 72 73 74 75 76 77 |
# File 'lib/cyclid/cli/organization/member.rb', line 70 def list org = client.org_get(client.config.organization) org['users'].each do |user| puts user end rescue StandardError => ex abort "Failed to get organization members: #{ex}" end |
#permission(user, permission) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/cyclid/cli/organization/member.rb', line 49 def (user, ) perms = case .downcase when 'admin' { 'admin' => true, 'write' => true, 'read' => true } when 'write' { 'admin' => false, 'write' => true, 'read' => true } when 'read' { 'admin' => false, 'write' => false, 'read' => true } when 'none' { 'admin' => false, 'write' => false, 'read' => false } else raise "invalid permission #{permission}" end client.(client.config.organization, user, perms) rescue StandardError => ex abort "Failed to modify user permissions: #{ex}" end |
#remove(*users) ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/cyclid/cli/organization/member.rb', line 101 def remove(*users) org = client.org_get(client.config.organization) # Remove any users that exist as members of this organization; # ask for confirmation on a per-user basis (unless '-f' was passed) user_list = org['users'] user_list.delete_if do |user| if users.include? user if [:force] true else print "Remove user #{user}: are you sure? (Y/n): ".colorize(:red) STDIN.getc.chr.casecmp('y') == 0 end end end user_list.uniq! client.org_modify(client.config.organization, members: user_list) rescue StandardError => ex abort "Failed to remove users from the organization: #{ex}" end |
#show(user) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cyclid/cli/organization/member.rb', line 80 def show(user) user = client.org_user_get(client.config.organization, user) # Pretty print the user details puts 'Username: '.colorize(:cyan) + user['username'] puts 'Email: '.colorize(:cyan) + user['email'] puts 'Permissions'.colorize(:cyan) user['permissions'].each do |k, v| puts "\t#{k.capitalize}: ".colorize(:cyan) + v.to_s end rescue StandardError => ex abort "Failed to get user: #{ex}" end |