2021-05-09 22:59:10 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module AccessPermissions
|
|
|
|
class MyModulesController < ApplicationController
|
|
|
|
before_action :set_project
|
|
|
|
before_action :set_experiment
|
|
|
|
before_action :set_my_module
|
|
|
|
before_action :check_read_permissions, only: %i(show)
|
2021-05-22 20:41:56 +08:00
|
|
|
before_action :check_manage_permissions, only: %i(edit update)
|
2021-05-09 22:59:10 +08:00
|
|
|
|
|
|
|
def show
|
|
|
|
respond_to do |format|
|
|
|
|
format.json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
|
|
|
respond_to do |format|
|
|
|
|
format.json
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@my_module_member = MyModuleMember.new(current_user, @my_module, @experiment, @project)
|
2021-11-15 18:12:31 +08:00
|
|
|
|
|
|
|
if permitted_update_params[:user_role_id] == 'reset'
|
|
|
|
@my_module_member.reset(permitted_update_params)
|
|
|
|
else
|
|
|
|
@my_module_member.update(permitted_update_params)
|
|
|
|
end
|
2021-05-09 22:59:10 +08:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render :my_module_member
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def permitted_update_params
|
|
|
|
params.require(:my_module_member)
|
|
|
|
.permit(%i(user_role_id user_id))
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_project
|
|
|
|
@project = current_team.projects.find_by(id: params[:project_id])
|
|
|
|
|
|
|
|
render_404 unless @project
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_experiment
|
|
|
|
@experiment = @project.experiments.find_by(id: params[:experiment_id])
|
|
|
|
|
|
|
|
render_404 unless @experiment
|
|
|
|
end
|
|
|
|
|
|
|
|
def set_my_module
|
|
|
|
@my_module = @experiment.my_modules.includes(user_assignments: %i(user user_role)).find_by(id: params[:id])
|
|
|
|
|
|
|
|
render_404 unless @my_module
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_manage_permissions
|
2021-09-14 17:08:35 +08:00
|
|
|
render_403 unless can_manage_my_module_users?(@my_module)
|
2021-05-09 22:59:10 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def check_read_permissions
|
2021-09-14 17:08:35 +08:00
|
|
|
render_403 unless can_read_my_module?(@my_module)
|
2021-05-09 22:59:10 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|