新增:项目邀请链接增加时间限制,以及show_link接口新增

This commit is contained in:
2022-06-20 10:16:39 +08:00
parent 1ebb6cb561
commit 45b7f70d9f
7 changed files with 371 additions and 63 deletions

View File

@@ -1,24 +1,31 @@
class Projects::ProjectInviteLinksController < Projects::BaseController
before_action :require_manager!, except: [:redirect_link]
before_action :require_manager!, except: [:show_link, :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?
role = params[:role]
is_apply = params[:is_apply]
return render_error('请输入正确的参数!') unless role.present? && is_apply.present?
@project_invite_link = ProjectInviteLink.find_by(user_id: current_user.id, project_id: @project.id, role: role, is_apply: is_apply)
@project_invite_link = ProjectInviteLink.build!(@project, current_user, role, is_apply) 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))
@project_invite_link = ProjectInviteLink.build!(project, user, params_data[:role], params_data[:is_apply])
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
def show_link
@project_invite_link = ProjectInviteLink.find_by(sign: params[:invite_sign])
return render_not_found unless @project_invite_link.present?
end
def redirect_link
Projects::LinkJoinService.call(current_user, @project, params[:invite_sign])
render_ok