Skip to content

Commit

Permalink
Store Staging Projects in the Backend
Browse files Browse the repository at this point in the history
Staging projects were created but not stored in the Backend.
  • Loading branch information
Ana06 authored and ChrisBr committed Nov 8, 2018
1 parent d84215d commit 9f06239
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 9f06239

Please sign in to comment.