-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a verification model, factory, and spec
update user, audio event and tag models update gems Verification API - closes #705 add a verification model, factory, and spec update user, audio event and tag models update gems verification api in progress: - updates abilities - adds permissions, requests specs - adds model schema - adds verification to spec creation_helper add permission spec for verifications update audio_event foreign key constraint on verification model to have cascade delete update expected cascade delete behaviour in models/audio_event_spec.rb to pass test add api spec for verification (shallow + nested) fix cascade deletes model specs fixes users request spec updates spec/README.md add verifications to AudioEventImportFile association scope fix user account spec - users *can* now update their own profile via api due to previous change in #703 adds verification controller helpers extend verification filter slightly + test update verification migration with FK tags cascade delete add required dependants to tags model add cascade delete test on tag spec change permitted params on verification update action adds verification nested filterable removes rails validation on verification; rely on database unique constraint adds request spec for invalid request - duplicate verification updates confirmation enum values: from 'true' to 'correct'; from 'false' to 'incorrect'
- Loading branch information
1 parent
1b1fbbd
commit aa77668
Showing
34 changed files
with
1,095 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
# frozen_string_literal: true | ||
|
||
# VerificationsController | ||
class VerificationsController < ApplicationController | ||
include Api::ControllerHelper | ||
|
||
# GET /verifications | ||
# GET /audio_recordings/:audio_recording_id/audio_events/:audio_event_id/verifications | ||
def index | ||
do_authorize_class | ||
get_audio_event | ||
|
||
@verifications, opts = Settings.api_response.response_advanced( | ||
api_filter_params, | ||
list_permissions, | ||
Verification, | ||
Verification.filter_settings | ||
) | ||
respond_index(opts) | ||
end | ||
|
||
# GET /verifications/:id | ||
# GET /audio_recordings/:audio_recording_id/audio_events/:audio_event_id/verifications/:id | ||
def show | ||
do_load_resource | ||
do_authorize_instance | ||
|
||
respond_show | ||
end | ||
|
||
# GET /verifications/new | ||
def new | ||
do_new_resource | ||
get_resource | ||
do_set_attributes | ||
do_authorize_instance | ||
|
||
respond_new | ||
end | ||
|
||
# POST /verifications | ||
def create | ||
do_new_resource | ||
do_set_attributes(verification_params) | ||
|
||
do_authorize_instance | ||
|
||
if @verification.save | ||
respond_create_success(shallow_verification_url(@verification)) | ||
else | ||
respond_change_fail | ||
end | ||
end | ||
|
||
# PUT/PATCH /verifications/:id | ||
def update | ||
do_load_resource | ||
do_authorize_instance | ||
|
||
if @verification.update(verification_update_params) | ||
respond_show | ||
else | ||
respond_change_fail | ||
end | ||
end | ||
|
||
# Handled in Archivable | ||
# DELETE /verifications/:id | ||
|
||
# GET|POST /verifications/filter | ||
# GET|POST /audio_recordings/:audio_recording_id/audio_events/:audio_event_id/verifications/filter | ||
def filter | ||
do_authorize_class | ||
get_audio_event | ||
|
||
filter_response, opts = Settings.api_response.response_advanced( | ||
api_filter_params, | ||
list_permissions, | ||
Verification, | ||
Verification.filter_settings | ||
) | ||
respond_filter(filter_response, opts) | ||
end | ||
|
||
private | ||
|
||
def verification_params | ||
params.require(:verification).permit( | ||
:confirmed, :audio_event_id, :tag_id | ||
) | ||
end | ||
|
||
def verification_update_params | ||
params.require(:verification).permit( | ||
:confirmed | ||
) | ||
end | ||
|
||
def get_audio_event #rubocop:disable Naming/AccessorMethodName | ||
@audio_event = AudioEvent.find(params[:audio_event_id]) if params&.key?(:audio_event_id) | ||
end | ||
|
||
def list_permissions | ||
Access::ByPermission.audio_event_verifications(current_user, audio_event: @audio_event) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
# frozen_string_literal: true | ||
|
||
# A Verification represents a user's confirmation that a tag is correctly | ||
# applied to an audio event. | ||
# @see (#AudioEvent) and (#Tag) for more information on these models. | ||
# | ||
# == Schema Information | ||
# | ||
# Table name: verifications | ||
# | ||
# id :bigint not null, primary key | ||
# confirmed :enum not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# audio_event_id :bigint not null | ||
# creator_id :integer not null | ||
# tag_id :bigint not null | ||
# updater_id :integer | ||
# | ||
# Indexes | ||
# | ||
# idx_on_audio_event_id_tag_id_creator_id_f944f25f20 (audio_event_id,tag_id,creator_id) UNIQUE | ||
# index_verifications_on_audio_event_id (audio_event_id) | ||
# index_verifications_on_tag_id (tag_id) | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (audio_event_id => audio_events.id) ON DELETE => cascade | ||
# fk_rails_... (creator_id => users.id) | ||
# fk_rails_... (tag_id => tags.id) ON DELETE => cascade | ||
# fk_rails_... (updater_id => users.id) | ||
# | ||
class Verification < ApplicationRecord | ||
belongs_to :audio_event, inverse_of: :verifications | ||
belongs_to :tag, inverse_of: :verifications | ||
belongs_to :creator, class_name: 'User', inverse_of: :created_verifications | ||
belongs_to :updater, class_name: 'User', inverse_of: :updated_verifications, optional: true | ||
|
||
# Defines the possible values for confirmation | ||
CONFIRMATION_TRUE = 'correct' | ||
CONFIRMATION_FALSE = 'incorrect' | ||
CONFIRMATION_UNSURE = 'unsure' | ||
CONFIRMATION_SKIP = 'skip' | ||
|
||
# @type [Hash{String => String}] | ||
CONFIRMATION_ENUM = { | ||
CONFIRMATION_TRUE => CONFIRMATION_TRUE, | ||
CONFIRMATION_FALSE => CONFIRMATION_FALSE, | ||
CONFIRMATION_UNSURE => CONFIRMATION_UNSURE, | ||
CONFIRMATION_SKIP => CONFIRMATION_SKIP | ||
}.freeze | ||
|
||
# @!method confirmed_true? | ||
# @return [Boolean] true if the verification is confirmed as true | ||
# @!method confirmed_true! | ||
# @return [void] sets the verification as confirmed true | ||
# @!method confirmed_false? | ||
# @return [Boolean] true if the verification is confirmed as false | ||
# @!method confirmed_false! | ||
# @return [void] sets the verification as confirmed false | ||
# @!method confirmed_unsure? | ||
# @return [Boolean] true if the verification is marked as unsure | ||
# @!method confirmed_unsure! | ||
# @return [void] sets the verification as unsure | ||
# @!method confirmed_skip? | ||
# @return [Boolean] true if the verification is marked as skip | ||
# @!method confirmed_skip! | ||
# @return [void] sets the verification as skip | ||
enum :confirmed, CONFIRMATION_ENUM, prefix: :confirmed, validate: true | ||
|
||
def self.filter_settings | ||
fields = [ | ||
:id, :confirmed, :audio_event_id, :tag_id, :creator_id, | ||
:updater_id, :created_at, :updated_at | ||
] | ||
|
||
{ | ||
valid_fields: fields, | ||
render_fields: fields, | ||
text_fields: [], | ||
new_spec_fields: lambda { |_user| | ||
{ | ||
confirmed: nil, | ||
audio_event_id: nil, | ||
tag_id: nil | ||
} | ||
}, | ||
controller: :verifications, | ||
action: :filter, | ||
defaults: { | ||
order_by: :created_at, | ||
direction: :desc | ||
}, | ||
valid_associations: [ | ||
{ | ||
join: AudioEvent, | ||
on: Verification.arel_table[:audio_event_id].eq(AudioEvent.arel_table[:id]), | ||
available: true, | ||
associations: [ | ||
{ | ||
join: AudioRecording, | ||
on: AudioEvent.arel_table[:audio_recording_id].eq(AudioRecording.arel_table[:id]), | ||
available: true | ||
} | ||
] | ||
}, | ||
{ | ||
join: Tag, | ||
on: Verification.arel_table[:tag_id].eq(Tag.arel_table[:id]), | ||
available: true | ||
} | ||
] | ||
} | ||
end | ||
|
||
def self.schema | ||
{ | ||
type: 'object', | ||
additionalProperties: false, | ||
properties: { | ||
id: Api::Schema.id, | ||
confirmed: { | ||
type: 'string', | ||
enum: CONFIRMATION_ENUM.values | ||
}, | ||
audio_event_id: Api::Schema.id(read_only: false), | ||
tag_id: Api::Schema.id(read_only: false), | ||
**Api::Schema.updater_and_creator_user_stamps | ||
}, | ||
required: [ | ||
:id, | ||
:confirmed, | ||
:audio_event_id, | ||
:tag_id, | ||
:creator_id, | ||
:created_at, | ||
:updater_id, | ||
:updated_at | ||
] | ||
}.freeze | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.