Class: Action::Project::Update

Inherits:
Object
  • Object
show all
Includes:
SetProjectAndBranch, InchCI::Action
Defined in:
app/services/action/project/update.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from SetProjectAndBranch

#set_project_and_branch

Methods included from InchCI::Action

#exposures, included

Constructor Details

#initialize(current_user, params) ⇒ Update

Returns a new instance of Update.


18
19
20
21
22
23
24
# File 'app/services/action/project/update.rb', line 18

def initialize(current_user, params)
  set_project_and_branch(params)
  if current_user && self.class.can_edit?(current_user, @project)
    @project = @project.to_model
    update_project(params[:project])
  end
end

Class Method Details

.can_edit?(current_user, project) ⇒ Boolean

allow if user owns project or user is in project's org

Returns:

  • (Boolean)

12
13
14
15
16
# File 'app/services/action/project/update.rb', line 12

def self.can_edit?(current_user, project)
  organizations = current_user.organizations || []
  project.user_name.downcase == current_user.user_name.downcase ||
    organizations.map(&:downcase).include?(project.user_name.downcase)
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)

26
27
28
# File 'app/services/action/project/update.rb', line 26

def success?
  @project.valid?
end