2023-07-03 21:54:11 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class MyModuleShareableLinksController < ApplicationController
|
2023-07-06 15:19:29 +08:00
|
|
|
before_action :load_my_module, except: %i(my_module_protocol_show)
|
2023-07-03 21:54:11 +08:00
|
|
|
before_action :load_shareable_link, only: %i(update destroy)
|
|
|
|
before_action :check_view_permissions, only: :show
|
2023-07-06 15:19:29 +08:00
|
|
|
before_action :check_manage_permissions, except: %i(show my_module_protocol_show)
|
|
|
|
skip_before_action :authenticate_user!, only: %(my_module_protocol_show)
|
2023-07-03 21:54:11 +08:00
|
|
|
|
|
|
|
def show
|
|
|
|
render json: @my_module.shareable_link
|
|
|
|
end
|
|
|
|
|
2023-07-06 15:19:29 +08:00
|
|
|
def my_module_protocol_show
|
|
|
|
shareable_link = ShareableLink.find_by(uuid: params[:uuid])
|
|
|
|
|
|
|
|
return render_403 if shareable_link.blank?
|
|
|
|
|
|
|
|
@my_module = shareable_link.shareable
|
|
|
|
render 'shareable_links/my_module_protocol_show', layout: 'shareable_links'
|
|
|
|
end
|
|
|
|
|
2023-07-03 21:54:11 +08:00
|
|
|
def create
|
2023-07-05 22:21:26 +08:00
|
|
|
@my_module.create_shareable_link(
|
|
|
|
uuid: @my_module.signed_id,
|
2023-07-03 21:54:11 +08:00
|
|
|
description: params[:description],
|
|
|
|
team: @my_module.team,
|
|
|
|
created_by: current_user
|
|
|
|
)
|
|
|
|
|
|
|
|
render json: @my_module.shareable_link
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@my_module.shareable_link.update!(
|
|
|
|
description: params[:description],
|
|
|
|
last_modified_by: current_user
|
|
|
|
)
|
|
|
|
|
|
|
|
render json: @my_module.shareable_link
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
@my_module.shareable_link.destroy!
|
|
|
|
|
|
|
|
render json: {}
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_my_module
|
|
|
|
@my_module = MyModule.find_by(id: params[:my_module_id])
|
|
|
|
render_404 unless @my_module
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_view_permissions
|
|
|
|
render_403 unless can_view_my_module?(@my_module)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_manage_permissions
|
2023-07-05 22:21:26 +08:00
|
|
|
render_403 unless can_share_my_module?(@my_module)
|
2023-07-03 21:54:11 +08:00
|
|
|
end
|
|
|
|
end
|