新增:项目邀请链接增加时间限制,以及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

@@ -35,7 +35,8 @@ class ProjectInviteLink < ApplicationRecord
before_create :set_old_data_expired_at
def self.random_hex_sign
SecureRandom.hex
hex = (SecureRandom.hex(32))
return hex unless ProjectInviteLink.where(sign: hex).exists?
end
def self.build!(project, user, role="developer", is_apply=true)
@@ -44,13 +45,14 @@ class ProjectInviteLink < ApplicationRecord
user_id: user&.id,
role: role,
is_apply: is_apply,
sign: random_hex_sign
sign: random_hex_sign,
expired_at: Time.now + 3.days
)
end
private
def set_old_data_expired_at
ProjectInviteLink.where(user_id: self.user_id, project_id: self.project).update_all(expired_at: Time.now)
ProjectInviteLink.where(user_id: self.user_id, project_id: self.project, role: self.role, is_apply: self.is_apply).update_all(expired_at: Time.now)
end