Class: Sem::CLI::Teams

Inherits:
Dracula
  • Object
show all
Defined in:
lib/sem/cli/teams.rb

Overview

rubocop:disable Metrics/ClassLength

Defined Under Namespace

Classes: Members, Projects, SharedConfigs

Constant Summary collapse

ALLOWED_PERMISSIONS =
["admin", "edit", "read"].freeze

Instance Method Summary collapse

Instance Method Details

#create(team_name) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/sem/cli/teams.rb', line 73

def create(team_name)
  permission = options[:permission]

  unless ALLOWED_PERMISSIONS.include?(permission)
    abort "Permission must be one of [#{ALLOWED_PERMISSIONS.join(", ")}]"
  end

  team = Sem::API::Team.create!(team_name, :permission => permission)

  Sem::Views::Teams.info(team)
end

#delete(team_name) ⇒ Object



145
146
147
148
149
150
# File 'lib/sem/cli/teams.rb', line 145

def delete(team_name)
  team = Sem::API::Team.find!(team_name)
  team.delete!

  puts "Team #{team_name} deleted."
end

#info(team_name) ⇒ Object



36
37
38
39
40
# File 'lib/sem/cli/teams.rb', line 36

def info(team_name)
  team = Sem::API::Team.find!(team_name)

  Sem::Views::Teams.info(team)
end

#listObject



14
15
16
17
18
19
20
21
22
# File 'lib/sem/cli/teams.rb', line 14

def list
  teams = Sem::API::Team.all

  if !teams.empty?
    Sem::Views::Teams.list(teams)
  else
    Sem::Views::Teams.create_first_team
  end
end

#rename(old_team_name, new_team_name) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
# File 'lib/sem/cli/teams.rb', line 97

def rename(old_team_name, new_team_name)
  old_org_name, _old_name = Sem::SRN.parse_team(old_team_name)
  new_org_name, new_name = Sem::SRN.parse_team(new_team_name)

  abort "Team can't change its organization" unless new_org_name == old_org_name

  team = Sem::API::Team.find!(old_team_name)
  team = team.update!(:name => new_name)

  Sem::Views::Teams.info(team)
end

#set_permission(team_name) ⇒ Object

rubocop:disable Style/AccessorMethodName



125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/sem/cli/teams.rb', line 125

def set_permission(team_name) # rubocop:disable Style/AccessorMethodName
  permission = options[:permission]

  unless ALLOWED_PERMISSIONS.include?(permission)
    abort "Permission must be one of [#{ALLOWED_PERMISSIONS.join(", ")}]"
  end

  team = Sem::API::Team.find!(team_name)
  team = team.update!(:permission => permission)

  Sem::Views::Teams.info(team)
end