Skip to content

Commit

Permalink
Merge pull request #491 from sparc-request/ac-fix-duplicate-users-bug
Browse files Browse the repository at this point in the history
fix adding duplicate users when creating new protocol
  • Loading branch information
jleonardw9 committed Jun 14, 2016
2 parents 9311666 + bc49b9b commit 69fadc9
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions app/controllers/dashboard/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,17 @@ def new

def create
protocol_class = params[:protocol][:type].capitalize.constantize
@protocol = protocol_class.create(params[:protocol])
@protocol.update_attributes(study_type_question_group_id: StudyTypeQuestionGroup.active_id)
@protocol = protocol_class.new(params[:protocol])
@protocol.study_type_question_group_id = StudyTypeQuestionGroup.active_id

if @protocol.valid?
if @protocol.project_roles.where(identity_id: current_user.id).empty?
unless @protocol.project_roles.map(&:identity_id).include? current_user.id
# if current user is not authorized, add them as an authorized user
@protocol.project_roles.new(identity_id: current_user.id, role: 'general-access-user', project_rights: 'approve')
@protocol.save
end

@protocol.save

if USE_EPIC && @protocol.selected_for_epic
@protocol.ensure_epic_user
Notifier.notify_for_epic_user_approval(@protocol).deliver unless QUEUE_EPIC
Expand Down
6 changes: 4 additions & 2 deletions app/controllers/protocols_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ def create
@current_step = 'user_details'
@protocol.populate_for_edit
elsif @current_step == 'user_details' and @protocol.valid?
if @protocol.project_roles.where(identity_id: current_user.id).empty?
unless @protocol.project_roles.map(&:identity_id).include? current_user.id
# if current user is not authorized, add them as an authorized user
@protocol.project_roles.new(identity_id: current_user.id, role: 'general-access-user', project_rights: 'approve')
@protocol.save
end

@protocol.save

@current_step = 'return_to_service_request'

if @service_request
Expand Down

0 comments on commit 69fadc9

Please sign in to comment.