diff options
author | James Lopez <james@jameslopez.es> | 2016-06-16 14:07:49 +0200 |
---|---|---|
committer | James Lopez <james@jameslopez.es> | 2016-06-16 14:07:49 +0200 |
commit | 2a747d386dbdc05453fce6b8be3f483e8cd9e796 (patch) | |
tree | 5530f2fb8856c4e29a33afb128843108e2bb5834 /app/models/member.rb | |
parent | 862b359b9a3f271b23f393932fb0e85d65c56c6b (diff) | |
parent | 778d72664f386dfee45dab171f137395739958f6 (diff) | |
download | gitlab-ce-2a747d386dbdc05453fce6b8be3f483e8cd9e796.tar.gz |
fixed merge conflicts
Diffstat (limited to 'app/models/member.rb')
-rw-r--r-- | app/models/member.rb | 53 |
1 files changed, 47 insertions, 6 deletions
diff --git a/app/models/member.rb b/app/models/member.rb index b44b6c55ad8..4ee3f1bb5c2 100644 --- a/app/models/member.rb +++ b/app/models/member.rb @@ -27,20 +27,28 @@ class Member < ActiveRecord::Base allow_nil: true } - scope :invite, -> { where(user_id: nil) } - scope :non_invite, -> { where("user_id IS NOT NULL") } + scope :invite, -> { where.not(invite_token: nil) } + scope :non_invite, -> { where(invite_token: nil) } + scope :request, -> { where.not(requested_at: nil) } + scope :non_request, -> { where(requested_at: nil) } + scope :non_pending, -> { non_request.non_invite } + scope :guests, -> { where(access_level: GUEST) } scope :reporters, -> { where(access_level: REPORTER) } scope :developers, -> { where(access_level: DEVELOPER) } scope :masters, -> { where(access_level: MASTER) } scope :owners, -> { where(access_level: OWNER) } + scope :owners_and_masters, -> { where(access_level: [OWNER, MASTER]) } before_validation :generate_invite_token, on: :create, if: -> (member) { member.invite_email.present? } + after_create :send_invite, if: :invite?, unless: :importing? - after_create :create_notification_setting, unless: [:invite?, :importing?] - after_create :post_create_hook, unless: [:invite?, :importing?] - after_update :post_update_hook, unless: [:invite?, :importing?] - after_destroy :post_destroy_hook, unless: :invite? + after_create :send_request, if: :request?, unless: :importing? + after_create :create_notification_setting, unless: [:pending?, :importing?] + after_create :post_create_hook, unless: [:pending?, :importing?] + after_update :post_update_hook, unless: [:pending?, :importing?] + after_destroy :post_destroy_hook, unless: :pending? + after_destroy :post_decline_request, if: :request? delegate :name, :username, :email, to: :user, prefix: true @@ -97,10 +105,31 @@ class Member < ActiveRecord::Base end end + def real_source_type + source_type + end + def invite? self.invite_token.present? end + def request? + requested_at.present? + end + + def pending? + invite? || request? + end + + def accept_request + return false unless request? + + updated = self.update(requested_at: nil) + after_accept_request if updated + + updated + end + def accept_invite!(new_user) return false unless invite? @@ -158,6 +187,10 @@ class Member < ActiveRecord::Base # override in subclass end + def send_request + # override in subclass + end + def post_create_hook system_hook_service.execute_hooks_for(self, :create) end @@ -178,6 +211,14 @@ class Member < ActiveRecord::Base # override in subclass end + def after_accept_request + post_create_hook + end + + def post_decline_request + # override in subclass + end + def system_hook_service SystemHooksService.new end |