Skip to content

Commit

Permalink
Remove references to aggregation attribute on Workflows (#4339)
Browse files Browse the repository at this point in the history
* Ignore aggregation column on workflows

* Remove everywhere else

* Hound

* Hound cleanup

* Short circuit scopes & specs for private aggs

* Deprecate AggregationsController

* Spec removal
  • Loading branch information
zwolf authored Jun 5, 2024
1 parent c1516c0 commit db10db4
Show file tree
Hide file tree
Showing 12 changed files with 70 additions and 280 deletions.
21 changes: 7 additions & 14 deletions app/controllers/api/v1/aggregations_controller.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
class Api::V1::AggregationsController < Api::ApiController
include JsonApiController::PunditPolicy
# include JsonApiController::PunditPolicy

require_authentication :create, :update, scopes: [:project]
resource_actions :create, :update, :show, :index
schema_type :json_schema
before_action :filter_by_subject_set, only: :index
# THIS FUNCTIONALITY IS BEING DEPRECATED EFFECTIVE IMMEDIATELY
# A REPLACEMENT IS FORTHCOMING.

private
# require_authentication :create, :update, scopes: [:project]
# resource_actions :create, :update, :show, :index
# schema_type :json_schema
# before_action :filter_by_subject_set, only: :index

def filter_by_subject_set
subject_set_ids = params.delete(:subject_set_id).try(:split, ',')
unless subject_set_ids.blank?
@controlled_resources = controlled_resources
.joins(workflow: :subject_sets)
.where(workflows: { subject_set_id: subject_set_ids } )
end
end
end
4 changes: 3 additions & 1 deletion app/models/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Workflow < ApplicationRecord
include Translatable
include Versioning

self.ignored_columns = ['aggregation']

versioned association: :workflow_versions, attributes: %w(tasks first_task strings major_version minor_version)

belongs_to :project
Expand Down Expand Up @@ -44,7 +46,7 @@ class Workflow < ApplicationRecord
'options' => {'count' => 15}
}.freeze

JSON_ATTRIBUTES = %w(tasks retirement aggregation strings steps).freeze
JSON_ATTRIBUTES = %w[tasks retirement strings steps].freeze

SELECTOR_PAGE_SIZE_KEY = 'subject_queue_page_size'.freeze

Expand Down
9 changes: 3 additions & 6 deletions app/policies/aggregation_policy.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
class AggregationPolicy < ApplicationPolicy
class ReadScope < Scope
# Allow access to public aggregations
# Short circuiting scopes for private aggrevations before they get removed next PR
def resolve(action)
updatable_parents = policy_for(Workflow).scope_for(:update)
updatable_scope = scope.joins(:workflow).merge(updatable_parents)

public_aggregations = scope.joins(:workflow).where("workflows.aggregation ->> 'public' = 'true'")
Aggregation.union(updatable_scope, public_aggregations)
parent_scope = policy_for(Workflow).scope_for(action)
scope.where(workflow_id: parent_scope.select(:id))
end
end

Expand Down
4 changes: 0 additions & 4 deletions app/schemas/workflow_create_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ class WorkflowCreateSchema < JsonSchema
type "array"
end

property "aggregation" do
type "object"
end

property "configuration" do
type "object"
end
Expand Down
4 changes: 0 additions & 4 deletions app/schemas/workflow_update_schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,6 @@ class WorkflowUpdateSchema < JsonSchema
type "array"
end

property "aggregation" do
type "object"
end

property "configuration" do
type "object"
end
Expand Down
2 changes: 1 addition & 1 deletion app/serializers/workflow_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class WorkflowSerializer
:created_at, :updated_at, :finished_at, :first_task, :primary_language,
:version, :content_language, :prioritized, :grouped, :pairwise,
:retirement, :retired_set_member_subjects_count, :href, :active, :mobile_friendly,
:aggregation, :configuration, :public_gold_standard, :completeness
:configuration, :public_gold_standard, :completeness

can_include :project, :subject_sets, :tutorial_subject, :published_version

Expand Down
8 changes: 4 additions & 4 deletions lib/formatter/csv/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ module Csv
class Workflow
attr_reader :workflow_version

JSON_FIELDS = [:tasks, :aggregation, :strings ].freeze
JSON_FIELDS = %i[tasks strings].freeze

def headers
%w(workflow_id display_name version active classifications_count pairwise
grouped prioritized primary_language first_task tutorial_subject_id
retired_set_member_subjects_count tasks retirement aggregation strings minor_version)
%w[workflow_id display_name version active classifications_count pairwise
grouped prioritized primary_language first_task tutorial_subject_id
retired_set_member_subjects_count tasks retirement strings minor_version]
end

def to_rows(workflow_version)
Expand Down
169 changes: 0 additions & 169 deletions spec/controllers/api/v1/aggregations_controller_spec.rb

This file was deleted.

Loading

0 comments on commit db10db4

Please sign in to comment.