summaryrefslogtreecommitdiff
path: root/app/models/member.rb
diff options
context:
space:
mode:
authorAdam Niedzielski <adamsunday@gmail.com>2016-08-01 20:12:30 +0200
committerAdam Niedzielski <adamsunday@gmail.com>2016-08-01 20:12:30 +0200
commit6d92cd3e836f2252b660479f5b33d15e6456b04d (patch)
tree547f223094b73a62ce033e9526660dd5457a45a8 /app/models/member.rb
parente299504b798c053817f1c866649542ac0c779924 (diff)
downloadgitlab-ce-6d92cd3e836f2252b660479f5b33d15e6456b04d.tar.gz
WIP
Diffstat (limited to 'app/models/member.rb')
-rw-r--r--app/models/member.rb6
1 files changed, 4 insertions, 2 deletions
diff --git a/app/models/member.rb b/app/models/member.rb
index 24ab1276ee9..998144330b1 100644
--- a/app/models/member.rb
+++ b/app/models/member.rb
@@ -31,6 +31,7 @@ class Member < ActiveRecord::Base
scope :non_invite, -> { where(invite_token: nil) }
scope :request, -> { where.not(requested_at: nil) }
scope :has_access, -> { where('access_level > 0') }
+ scope :still_active, -> { where('expires_at IS NULL OR expires_at > ?', Time.current) }
scope :guests, -> { where(access_level: GUEST) }
scope :reporters, -> { where(access_level: REPORTER) }
@@ -54,7 +55,7 @@ class Member < ActiveRecord::Base
class << self
def access_for_user_ids(user_ids)
- where(user_id: user_ids).has_access.pluck(:user_id, :access_level).to_h
+ where(user_id: user_ids).has_access.still_active.pluck(:user_id, :access_level).to_h
end
def find_by_invite_token(invite_token)
@@ -73,7 +74,7 @@ class Member < ActiveRecord::Base
user
end
- def add_user(members, user_id, access_level, current_user = nil)
+ def add_user(members, user_id, access_level, current_user = nil, expires_at = nil)
user = user_for_id(user_id)
# `user` can be either a User object or an email to be invited
@@ -87,6 +88,7 @@ class Member < ActiveRecord::Base
if can_update_member?(current_user, member) || project_creator?(member, access_level)
member.created_by ||= current_user
member.access_level = access_level
+ member.expires_at = expires_at
member.save
end