36 lines
1.2 KiB
Ruby
36 lines
1.2 KiB
Ruby
class Projects::ProjectInviteLinksController < Projects::BaseController
|
|
before_action :require_manager!, except: [:redirect_link]
|
|
before_action :require_login
|
|
|
|
def current_link
|
|
@project_invite_link = ProjectInviteLink.find_by(user_id: current_user.id, project_id: @project.id)
|
|
@project_invite_link = ProjectInviteLink.build!(@project, current_user) unless @project_invite_link.present?
|
|
end
|
|
|
|
def generate_link
|
|
ActiveRecord::Base.transaction do
|
|
params_data = link_params.merge({user_id: current_user.id, project_id: @project.id})
|
|
puts params_data
|
|
Projects::ProjectInviteLinks::CreateForm.new(params_data).validate!
|
|
@project_invite_link = ProjectInviteLink.create!(params_data.merge(sign: ProjectInviteLink.random_hex_sign))
|
|
end
|
|
rescue Exception => e
|
|
uid_logger_error(e.message)
|
|
tip_exception(e.message)
|
|
end
|
|
|
|
def redirect_link
|
|
Projects::LinkJoinService.call(current_user, @project, params[:invite_sign])
|
|
render_ok
|
|
rescue Exception => e
|
|
uid_logger_error(e.message)
|
|
tip_exception(e.message)
|
|
end
|
|
|
|
|
|
private
|
|
def link_params
|
|
params.require(:project_invite_link).permit(:role, :is_apply)
|
|
end
|
|
end
|