Skip to content

Commit

Permalink
Merge branch 'kyle/StudioViews' into kyle/navBar. Updated styles for …
Browse files Browse the repository at this point in the history
…studio dashboard.
  • Loading branch information
kyleqhua committed Apr 13, 2020
2 parents d200ca2 + 12bc2c5 commit 93e9792
Show file tree
Hide file tree
Showing 51 changed files with 857 additions and 1,993 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ gem 'jbuilder', '~> 2.7'
# gem 'bcrypt', '~> 3.1.7'
gem 'rails_admin', '~> 2.0'
gem 'react-rails', '~> 2.6.0'
gem "sentry-raven"
# Use Active Storage variant
# gem 'image_processing', '~> 1.2'
gem 'active_model_serializers', '~> 0.10.0'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ GEM
sprockets (> 3.0)
sprockets-rails
tilt
sentry-raven (2.13.0)
faraday (>= 0.7.6, < 1.0)
solargraph (0.37.2)
backport (~> 1.1)
bundler (>= 1.17.2)
Expand Down Expand Up @@ -363,6 +365,7 @@ DEPENDENCIES
rspec-rails
rubocop
sass-rails (~> 5)
sentry-raven
solargraph
spring
spring-watcher-listen (~> 2.0.0)
Expand Down
114 changes: 85 additions & 29 deletions app/controllers/api/assignments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,35 @@ class Api::AssignmentsController < ApplicationController
respond_to :json

def create
@action_item = authorize ActionItem.new(action_item_params)
@action_item[:is_template] = false

if @action_item.save
created_assignments = []
prepare_bulk_assignment(assigned_to_ids, @action_item.id).each do |assignment_params|
@assignment = authorize Assignment.new(assignment_params)
if @assignment.save
created_assignments.append(@assignment)
else
@action_item.destroy
render json: { error: 'Could not create action item' }, status: :unprocessable_entity
return
created_assignments = []
created_action_items = []
assigned_to_ids = bulk_assignment_params.fetch(:assigned_to_ids, [])
bulk_assignment_params.fetch(:assignments, []).each do |action_item|
action_item = authorize ActionItem.new(action_item.except(:due_date))
template_sentry_helper(action_item)
action_item[:is_template] = false
if !assigned_to_ids.empty? && action_item.save
created_action_items.append(action_item)
prepare_bulk_assignment(assigned_to_ids, action_item).each do |assignment|
assignment_sentry_helper(assignment)
if assignment.save
created_assignments.append(assignment)
else
action_item.destroy
created_action_items.each {|item| item.destroy}
Raven.capture_message("Could not create action item")
render json: { error: 'Could not create action item' }, status: :unprocessable_entity
return
end
end
else
created_action_items.each {|item| item.destroy}
Raven.capture_message("Could not create action item")
render json: { error: 'Could not create action item' }, status: :unprocessable_entity
return
end
render json: created_assignments, status: :created
else
render json: { error: 'Could not create action item' }, status: :unprocessable_entity
end
render json: created_assignments, status: :created
end

def show
Expand All @@ -32,9 +42,23 @@ def show

def update
authorize @assignment
if @assignment.update(assignment_params) && @assignment.action_item.update(action_item_params)
action_item_copied = false
action_item = @assignment.action_item

if !action_item_params.empty? && action_item.assignments.length > 1
action_item = action_item.dup
action_item_copied = true
end

@assignment.assign_attributes(assignment_params)
action_item.assign_attributes(action_item_params)
if (action_item.valid? && @assignment.valid?) && (action_item.save && @assignment.save)
if action_item_copied
@assignment.update(action_item: action_item)
end
render json: @assignment, status: :ok
else
Raven.capture_message("Could not update action item")
render json: { error: 'Could not update action item' }, status: :unprocessable_entity
end
end
Expand All @@ -48,21 +72,29 @@ def destroy
end
render json: {}, status: :ok
else
Raven.capture_message("Failed to delete action item")
render json: { error: 'Failed to delete action item' }, status: :unprocessable_entity
end
end

def create_template
@template = authorize ActionItem.new(action_item_params), :create?
template_sentry_helper(@template)
@template[:is_template] = true

if @template.save
render json: @template, status: :created
else
Raven.capture_message("Could not create template")
render json: { error: 'Could not create template' }, status: :unprocessable_entity
end
end

def get_templates
@action_items = authorize ActionItem.where(is_template: true), :show?
render json: @action_items, status: :ok
end

def show_template
authorize @template, :show?
render json: @template, status: :ok
Expand All @@ -73,51 +105,75 @@ def update_template
if @template.update(action_item_params)
render json: @template, status: :ok
else
Raven.capture_message("Could not update template")
render json: { error: 'Could not update template' }, status: :unprocessable_entity
end
end

def destroy_template
authorize @template, :destroy?
if @template.destroy
if @template.is_template && @template.destroy
render json: @template, status: :ok
else
render json: { error: 'Failed to delete action item template' }, status: :unprocessable_entity
Raven.capture_message("Failed to delete action item template. Action item must be a template.")
render json: { error: 'Failed to delete action item template. Action item must be a template.' }, status: :unprocessable_entity
end
end

private

def set_template
@template = ActionItem.find(params[:id])
rescue ActiveRecord::RecordNotFound
template_sentry_helper(@template)
rescue ActiveRecord::RecordNotFound => exception
Raven.extra_context(action_item_id: params[:id])
Raven.capture_exception(exception)
render json: { error: 'Could not find Action Item Template' }, status: :not_found
end

def template_sentry_helper(action_item)
Raven.extra_context(case_note: action_item.attributes)
end

def set_assignment
@assignment = Assignment.find(params[:id])
rescue ActiveRecord::RecordNotFound
assignment_sentry_helper(@assignment)
rescue ActiveRecord::RecordNotFound => exception
Raven.extra_context(assignment_id: params[:id])
Raven.capture_exception(exception)
render json: { error: 'Could not find Action Item' }, status: :not_found
end

def prepare_bulk_assignment(assigned_to_ids, action_item_id)
def assignment_sentry_helper(assignment)
Raven.extra_context(assignment: assignment.attributes)
Raven.extra_context(action_item: assignment.action_item.attributes)
Raven.extra_context(assigned_by: assignment.assigned_by.user.attributes)
Raven.extra_context(assigned_to: assignment.assigned_to.user.attributes)
end

def prepare_bulk_assignment(assigned_to_ids, action_item)
bulk_assignment_params = []
single_assignment_params = assignment_params
single_assignment_params = {
action_item_id: action_item.id,
assigned_by_id: current_user.staff.id,
due_date: action_item[:due_date],
completed: false,
}
assigned_to_ids.each do |id|
bulk_assignment_params.append(single_assignment_params.merge(assigned_to_id: id,
action_item_id: action_item_id))
assignment = Assignment.new(single_assignment_params.merge(assigned_to_id: id))
bulk_assignment_params.append(assignment)
end
return bulk_assignment_params
end

def action_item_params
action_item_param = params.require(:assignment).permit(:title,
:description)
:description)
end

def assigned_to_ids
params.require(:assignment).permit(assigned_to_ids: []).fetch(:assigned_to_ids, [])
end
def bulk_assignment_params
all_assignment_params = params.permit(assignments: [:title, :description, :due_date], assigned_to_ids: [])
end

def assignment_params
assignment_param = params.require(:assignment).permit(:action_item_id,
Expand Down
18 changes: 16 additions & 2 deletions app/controllers/api/case_notes_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Api::CaseNotesController < ApplicationController
before_action :set_case_note, only: [:show, :update, :visible, :destroy]
before_action :set_case_note, only: [:show, :update, :not_visible, :destroy]
respond_to :json

def show
Expand All @@ -8,9 +8,11 @@ def show

def create
@case_note = authorize CaseNote.new(case_notes_params)
sentry_helper(@case_note)
if @case_note.save
render json: @case_note, status: :created
else
Raven.capture_message("Could not create case note")
render json: { error: 'Could not create case note' }, status: :unprocessable_entity
end
end
Expand All @@ -19,6 +21,7 @@ def update
if @case_note.update(case_notes_params)
render json: @case_note, status: :ok
else
Raven.capture_message("Could not update case note")
render json: { error: 'Could not update case note' }, status: :unprocessable_entity
end
end
Expand All @@ -27,6 +30,7 @@ def destroy
if @case_note.destroy
render json: @case_note, status: :ok
else
Raven.capture_message("Failed to delete case note")
render json: { error: 'Failed to delete case note' }, status: :unprocessable_entity
end
end
Expand All @@ -35,6 +39,7 @@ def not_visible
if @case_note.update(visible: false)
render json: @case_note, status: :ok
else
Raven.capture_message("Failed to change visible to false")
render json: { error: 'Failed to change visible to false' }, status: :unprocessable_entity
end
end
Expand All @@ -47,10 +52,19 @@ def user_not_authorized

def set_case_note
@case_note = authorize CaseNote.find(params[:id])
rescue ActiveRecord::RecordNotFound
sentry_helper(@case_note)
rescue ActiveRecord::RecordNotFound => exception
Raven.extra_context(case_note_id: params[:id])
Raven.capture_exception(exception)
render json: { error: 'Could not find case note' }, status: :not_found
end

def sentry_helper(case_note)
Raven.extra_context(case_note: case_note.attributes)
Raven.extra_context(staff: case_note.staff.user.attributes)
Raven.extra_context(participant: case_note.participant.user.attributes)
end

def case_notes_params
case_notes_param = params.require(:case_note).permit(:title,
:description,
Expand Down
16 changes: 15 additions & 1 deletion app/controllers/api/paperworks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ def show

def create
@paperwork = authorize Paperwork.new(paperwork_params)
sentry_helper(@paperwork)
if @paperwork.save
render json: @paperwork, status: :created
else
Raven.capture_message("Could not create paperwork")
render json: { error: 'Could not create paperwork' }, status: :unprocessable_entity
end
end
Expand All @@ -19,6 +21,7 @@ def update
if @paperwork.update(paperwork_params)
render json: @paperwork, status: :ok
else
Raven.capture_message("Could not update paperwork")
render json: { error: 'Could not update paperwork' }, status: :unprocessable_entity
end
end
Expand All @@ -27,6 +30,7 @@ def complete
if @paperwork.update(agree: true)
render json: @paperwork, status: :ok
else
Raven.capture_message("Failed to mark as agreed")
render json: { error: 'Failed to mark as agreed' }, status: :unprocessable_entity
end
end
Expand All @@ -35,6 +39,7 @@ def viewed
if @paperwork.update(viewed: true)
render json: @paperwork, status: :ok
else
Raven.capture_message("Failed to mark as agreed")
render json: { error: 'Failed to mark as agreed' }, status: :unprocessable_entity
end
end
Expand All @@ -43,6 +48,7 @@ def destroy
if @paperwork.destroy
render json: @paperwork, status: :ok
else
Raven.capture_message("Failed to delete paperwork")
render json: { error: 'Failed to delete paperwork' }, status: :unprocessable_entity
end
end
Expand All @@ -55,10 +61,18 @@ def user_not_authorized

def set_paperwork
@paperwork = authorize Paperwork.find(params[:id])
rescue ActiveRecord::RecordNotFound
rescue ActiveRecord::RecordNotFound => exception
Raven.extra_context(paperwork_id: params[:id])
Raven.capture_exception(exception)
render json: { error: 'Could not find paperwork' }, status: :not_found
end

def sentry_helper(paperwork)
Raven.extra_context(paperwork: paperwork.attributes)
Raven.extra_context(staff: paperwork.staff.user.attributes)
Raven.extra_context(participant: paperwork.participant.user.attributes)
end

def paperwork_params
paperwork_param = params.require(:paperwork).permit(:title,
:link,
Expand Down
14 changes: 13 additions & 1 deletion app/controllers/api/personal_questionnaires_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ def show
def create
@questionnaire = PersonalQuestionnaire.new(questionnaire_params)
authorize @questionnaire, policy_class: QuestionnairePolicy
sentry_helper(@questionnaire)
if @questionnaire.save
render json: @questionnaire, status: :created
else
Raven.capture_message("Could not create personal questionnaire")
render json: { error: 'Could not create personal questionnaire' }, status: :unprocessable_entity
end
end
Expand All @@ -21,6 +23,7 @@ def update
if @questionnaire.update(questionnaire_params)
render json: @questionnaire, status: :ok
else
Raven.capture_message("Could not update personal questionnaire")
render json: { error: 'Could not update personal questionnaire' }, status: :unprocessable_entity
end
end
Expand All @@ -30,16 +33,25 @@ def destroy
if @questionnaire.destroy
render json: @questionnaire, status: :ok
else
Raven.capture_message("Failed to delete personal questionnaire")
render json: { error: 'Failed to delete personal questionnaire' }, status: :unprocessable_entity
end
end

private
def set_questionnaire
@questionnaire = authorize PersonalQuestionnaire.find(params[:id]), policy_class: QuestionnairePolicy
rescue ActiveRecord::RecordNotFound
sentry_helper(@questionnaire)
rescue ActiveRecord::RecordNotFound => exception
Raven.extra_context(personal_questionnaire_id: params[:id])
Raven.capture_exception(exception)
render json: { error: 'Could not find personal questionnaire' }, status: :not_found
end

def sentry_helper(personal_questionnaire)
Raven.extra_context(case_note: personal_questionnaire.attributes)
Raven.extra_context(participant: personal_questionnaire.participant.user.attributes)
end

def questionnaire_params
questionnaire_params = params.require(:personal_questionnaire).permit(:participant_id,
Expand Down
Loading

0 comments on commit 93e9792

Please sign in to comment.