Skip to content

Commit

Permalink
Merge pull request #6193 from Ana06/staging-workflow-fix
Browse files Browse the repository at this point in the history
Store Staging Projects in the Backend
  • Loading branch information
ChrisBr committed Nov 8, 2018
2 parents d84215d + 9f06239 commit 108fd1f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/api/app/models/staging_workflow.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
class StagingWorkflow < ApplicationRecord
belongs_to :project, inverse_of: :staging
has_many :staging_projects, class_name: 'Project', inverse_of: :staging_workflow, dependent: :nullify, autosave: true do
has_many :staging_projects, class_name: 'Project', inverse_of: :staging_workflow, dependent: :nullify do
def without_staged_requests
includes(:staged_requests).where(bs_requests: { id: nil })
end
end
has_many :target_of_bs_requests, through: :project
has_many :staged_requests, class_name: 'BsRequest', through: :staging_projects

after_initialize :init_staging_projects
after_create :create_staging_projects

def unassigned_requests
target_of_bs_requests.in_states(['new', 'review']) - staged_requests - ignored_requests
Expand All @@ -20,10 +20,12 @@ def ignored_requests

private

def init_staging_projects
return unless new_record?
def create_staging_projects
['A', 'B'].each do |letter|
staging_projects << Project.find_or_initialize_by(name: "#{project.name}:Staging:#{letter}")
staging_project = Project.find_or_initialize_by(name: "#{project.name}:Staging:#{letter}")
next if staging_project.staging_workflow # if it belongs to another staging workflow skip it
staging_project.staging_workflow = self
staging_project.store
end
end
end

0 comments on commit 108fd1f

Please sign in to comment.