mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-07-15 06:34:32 +08:00
新增:邀请用户链接生成
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: project_invite_links
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# project_id :integer
|
||||
# user_id :integer
|
||||
# role :integer default("4")
|
||||
# is_apply :boolean default("1")
|
||||
# sign :string(255)
|
||||
# expired_at :datetime
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_project_invite_links_on_project_id (project_id)
|
||||
# index_project_invite_links_on_sign (sign)
|
||||
# index_project_invite_links_on_user_id (user_id)
|
||||
#
|
||||
|
||||
class ProjectInviteLink < ApplicationRecord
|
||||
|
||||
default_scope { where("expired_at > ?", Time.now).or(where(expired_at: nil)) }
|
||||
|
||||
belongs_to :project
|
||||
belongs_to :user
|
||||
has_many :applied_projects
|
||||
|
||||
scope :with_project_id, -> (project_id) {where(project_id: project_id)}
|
||||
scope :with_user_id, -> (user_id) {where(user_id: user_id)}
|
||||
|
||||
enum role: {manager: 3, developer: 4, reporter: 5}
|
||||
|
||||
before_create :set_old_data_expired_at
|
||||
|
||||
def self.random_hex_sign
|
||||
SecureRandom.hex
|
||||
end
|
||||
|
||||
def self.build!(project, user, role="developer", is_apply=true)
|
||||
self.create!(
|
||||
project_id: project&.id,
|
||||
user_id: user&.id,
|
||||
role: role,
|
||||
is_apply: is_apply,
|
||||
sign: random_hex_sign
|
||||
)
|
||||
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)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
Reference in New Issue
Block a user