Skip to content

Commit

Permalink
Merge branch 'issue426'
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Nov 25, 2020
2 parents a22d919 + 7706ca9 commit ac2f7a9
Show file tree
Hide file tree
Showing 42 changed files with 1,099 additions and 1,120 deletions.
7 changes: 7 additions & 0 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@ def index
end
end

def project_creation_requests
@requests = MessageLog.pending_project_creation_requests
respond_to do |format|
format.html
end
end

def update_admins
admin_ids = params[:admins].split(',') || []
current_admins = Person.admins
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/people_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def create
respond_to do |format|
if @person.save && current_user.save
if Seek::Config.email_enabled && during_registration
notify_admin_and_project_administrators_of_new_user
Mailer.contact_admin_new_user(current_user).deliver_later
end
if current_user.active?
flash[:notice] = 'Person was successfully created.'
Expand Down Expand Up @@ -159,10 +159,6 @@ def create
end
end

def notify_admin_and_project_administrators_of_new_user
Mailer.contact_admin_new_user(notification_params.to_h, current_user).deliver_later
end

# PUT /people/1
# PUT /people/1.xml
def update
Expand Down
125 changes: 0 additions & 125 deletions app/controllers/programmes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ class ProgrammesController < ApplicationController
before_action :can_activate?, only: [:activation_review, :accept_activation,:reject_activation,:reject_activation_confirmation]
before_action :inactive_view_allowed?, only: [:show]

#specific to the actions that require a MessageLog with a programme definition assigned
before_action :validate_message_log, only: [:administer_create_project_request, :respond_create_project_request]
before_action :parse_message_log_details, only: [:administer_create_project_request]
before_action :check_message_log_programme_permissions, only: [:administer_create_project_request, :respond_create_project_request]


skip_before_action :project_membership_required

Expand Down Expand Up @@ -124,130 +119,10 @@ def storage_report
end
end

def administer_create_project_request

respond_to do |format|
format.html
end

end

def respond_create_project_request

requester = @message_log.sender
make_programme_admin=false

if params['accept_request']=='1'

# @programme already populated in before_filter when checking permissions
make_programme_admin = @programme.new_record?

if params['institution']['id']
@institution = Institution.find(params['institution']['id'])
else
@institution = Institution.new(params.require(:institution).permit([:title, :web_page, :city, :country]))
end

@project = Project.new(params.require(:project).permit([:title, :web_page, :description]))
@project.programme = @programme

validate_error_msg = []

unless @project.valid?
validate_error_msg << "The #{t('project')} is invalid, #{@project.errors.full_messages.join(', ')}"
end
unless @programme.valid?
validate_error_msg << "The #{t('programme')} is invalid, #{@programme.errors.full_messages.join(', ')}"
end
unless @institution.valid?
validate_error_msg << "The #{t('institution')} is invalid, #{@institution.errors.full_messages.join(', ')}"
end

validate_error_msg = validate_error_msg.join('<br/>').html_safe

if validate_error_msg.blank?
requester.add_to_project_and_institution(@project, @institution)
requester.is_project_administrator = true,@project
requester.is_programme_administrator = true, @programme if make_programme_admin

disable_authorization_checks do
requester.save!
end

@message_log.update_column(:response,'Accepted')
flash[:notice]="Request accepted and #{requester.name} added to #{t('project')} and notified"
Mailer.notify_user_projects_assigned(requester,[@project]).deliver_later

redirect_to(@project)
else
flash.now[:error] = validate_error_msg
render action: :administer_create_project_request
end

else
comments = params['reject_details']
@message_log.update_column(:response,comments)
project_name = JSON.parse(@message_log.details)['project']['title']
Mailer.create_project_rejected(requester,project_name,comments).deliver_later
flash[:notice]="Request rejected and #{requester.name} has been notified"

redirect_to :root
end
end

private

def validate_message_log
@message_log = MessageLog.find_by_id(params[:message_log_id])
error_msg ||= "message log not found" unless @message_log
error_msg ||= ("incorrect type of message log" unless @message_log.message_type==MessageLog::PROJECT_CREATION_REQUEST)
error_msg ||= ("message has already been responded to" if @message_log.responded?)
error_msg ||= ('you have no permission to create a project' unless Project.can_create?)
if error_msg
error(error_msg, error_msg)
return false
end

end

def parse_message_log_details
details = JSON.parse(@message_log.details)
@programme = Programme.new(details['programme'])
@programme = Programme.find(@programme.id) unless @programme.id.nil?

@project = Project.new(details['project'])
@project = Project.find(@project.id) unless @project.id.nil?

@institution = Institution.new(details['institution'])
@institution = Institution.find(@institution.id) unless @institution.id.nil?


end

# check programme permissions for responding to a MesasgeLog
def check_message_log_programme_permissions
error_msg = nil

unless @programme
if params['programme']['id']
@programme = Programme.find(params['programme']['id'])
else
@programme = Programme.new(params.require(:programme).permit([:title]))
end
end

if @programme.new_record?
error_msg = "You need to be an administrator" unless User.admin_logged_in?
else
error_msg = "No rights to administer #{t('programme')}" unless @programme.can_manage?
end

if error_msg
error(error_msg, error_msg)
return false
end
end

#whether the item needs or can be activated, which affects steps around activation of rejection
def can_activate?
unless result=@programme.can_activate?
Expand Down
Loading

0 comments on commit ac2f7a9

Please sign in to comment.