summaryrefslogtreecommitdiff
path: root/app/models/members
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-10 15:09:37 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-14 12:06:43 +0200
commit629fa7fbe3a8a2f06d7c053ddcbcd78beed24e9c (patch)
tree2cc6008db2598307afcdd85558175718a06977f0 /app/models/members
parent2b2bd402dcee427a43de771036b348e156fea6c9 (diff)
downloadgitlab-ce-629fa7fbe3a8a2f06d7c053ddcbcd78beed24e9c.tar.gz
Add invite logic to Member.
Diffstat (limited to 'app/models/members')
-rw-r--r--app/models/members/group_member.rb23
-rw-r--r--app/models/members/project_member.rb33
2 files changed, 20 insertions, 36 deletions
diff --git a/app/models/members/group_member.rb b/app/models/members/group_member.rb
index 28d0b4483b4..ccbbab6afc5 100644
--- a/app/models/members/group_member.rb
+++ b/app/models/members/group_member.rb
@@ -27,10 +27,6 @@ class GroupMember < Member
scope :with_group, ->(group) { where(source_id: group.id) }
scope :with_user, ->(user) { where(user_id: user.id) }
- after_create :post_create_hook
- after_update :notify_update
- after_destroy :post_destroy_hook
-
def self.access_level_roles
Gitlab::Access.options_with_owner
end
@@ -43,26 +39,19 @@ class GroupMember < Member
access_level
end
+ private
+
def post_create_hook
notification_service.new_group_member(self)
- system_hook_service.execute_hooks_for(self, :create)
+
+ super
end
- def notify_update
+ def post_update_hook
if access_level_changed?
notification_service.update_group_member(self)
end
- end
-
- def post_destroy_hook
- system_hook_service.execute_hooks_for(self, :destroy)
- end
-
- def system_hook_service
- SystemHooksService.new
- end
- def notification_service
- NotificationService.new
+ super
end
end
diff --git a/app/models/members/project_member.rb b/app/models/members/project_member.rb
index 2205041cd51..6c5d161940d 100644
--- a/app/models/members/project_member.rb
+++ b/app/models/members/project_member.rb
@@ -27,10 +27,6 @@ class ProjectMember < Member
validates_format_of :source_type, with: /\AProject\z/
default_scope { where(source_type: SOURCE_TYPE) }
- after_create :post_create_hook
- after_update :post_update_hook
- after_destroy :post_destroy_hook
-
scope :in_project, ->(project) { where(source_id: project.id) }
scope :in_projects, ->(projects) { where(source_id: projects.pluck(:id)) }
scope :with_user, ->(user) { where(user_id: user.id) }
@@ -110,41 +106,40 @@ class ProjectMember < Member
access_level
end
+ def project
+ source
+ end
+
def owner?
project.owner == user
end
+ private
+
def post_create_hook
unless owner?
event_service.join_project(self.project, self.user)
notification_service.new_project_member(self)
end
- system_hook_service.execute_hooks_for(self, :create)
+ super
end
def post_update_hook
- notification_service.update_project_member(self) if self.access_level_changed?
+ if access_level_changed?
+ notification_service.update_project_member(self)
+ end
+
+ super
end
def post_destroy_hook
event_service.leave_project(self.project, self.user)
- system_hook_service.execute_hooks_for(self, :destroy)
+
+ super
end
def event_service
EventCreateService.new
end
-
- def notification_service
- NotificationService.new
- end
-
- def system_hook_service
- SystemHooksService.new
- end
-
- def project
- source
- end
end