Skip to content

Commit

Permalink
Add RequestExclusion model
Browse files Browse the repository at this point in the history
This model will store bs_requests from a staging workflow that want to
be excluded.

Co-authored-by: David Kang <dkang@suse.com>
Co-authored-by: Moisés Déniz Alemán <mdeniz@suse.com>
Co-authored-by: Saray Cabrera Padrón <scabrerapadron@suse.de>
Co-authored-by: Ana María Martínez Gómez <ammartinez@suse.de>
  • Loading branch information
5 people committed Nov 20, 2018
1 parent 0b8bad4 commit 995715e
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/api/app/models/bs_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class SaveError < APIError
has_many :target_project_objects, through: :bs_request_actions

belongs_to :staging_project, class_name: 'Project', foreign_key: 'staging_project_id'
has_one :request_exclusion, class_name: 'Staging::RequestExclusion', foreign_key: 'bs_request_id', dependent: :destroy

validates :state, inclusion: { in: VALID_REQUEST_STATES }
validates :creator, presence: true
Expand Down
14 changes: 14 additions & 0 deletions src/api/app/models/staging/request_exclusion.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Staging::RequestExclusion < ApplicationRecord
def self.table_name_prefix
'staging_'
end

belongs_to :staging_workflow, class_name: 'Staging::Workflow'
belongs_to :bs_request

validates :staging_workflow, :bs_request, :description, presence: true
validates :bs_request_id, numericality: true, uniqueness: { scope: :staging_workflow_id, message: 'is already excluded' }
validates :description, length: { maximum: 255 }

delegate :number, to: :bs_request, allow_nil: true
end
6 changes: 4 additions & 2 deletions src/api/app/models/staging/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@ def ready_to_stage
end

has_many :staged_requests, class_name: 'BsRequest', through: :staging_projects
has_many :request_exclusions, class_name: 'Staging::RequestExclusion', foreign_key: 'staging_workflow_id', dependent: :destroy
has_many :excluded_requests, through: :request_exclusions, source: :bs_request

validates :managers_group, presence: true

after_create :create_staging_projects
before_update :update_staging_projects_managers_group

def unassigned_requests
target_of_bs_requests.stageable.where.not(id: ignored_requests | staged_requests)
target_of_bs_requests.stageable.where.not(id: excluded_requests | staged_requests)
end

def ready_requests
target_of_bs_requests.ready_to_stage.where.not(id: ignored_requests | staged_requests)
target_of_bs_requests.ready_to_stage.where.not(id: excluded_requests | staged_requests)
end

def ignored_requests
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateStagingRequestExclusions < ActiveRecord::Migration[5.2]
def change
create_table :staging_request_exclusions, id: :integer, options: 'CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC' do |t|
t.references :staging_workflow, index: true, type: :integer, null: false
t.references :bs_request, index: true, type: :integer, null: false
t.string :description

t.timestamps
end
end
end
13 changes: 13 additions & 0 deletions src/api/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1142,6 +1142,18 @@ CREATE TABLE `sessions` (
KEY `index_sessions_on_updated_at` (`updated_at`) USING BTREE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `staging_request_exclusions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`staging_workflow_id` int(11) NOT NULL,
`bs_request_id` int(11) NOT NULL,
`description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `index_staging_request_exclusions_on_staging_workflow_id` (`staging_workflow_id`),
KEY `index_staging_request_exclusions_on_bs_request_id` (`bs_request_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;

CREATE TABLE `staging_workflows` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`project_id` int(11) DEFAULT NULL,
Expand Down Expand Up @@ -1426,6 +1438,7 @@ INSERT INTO `schema_migrations` (version) VALUES
('20181008150453'),
('20181016103905'),
('20181025152009'),
('20181030114152'),
('20181113095753');


0 comments on commit 995715e

Please sign in to comment.