同步members
This commit is contained in:
parent
9d8596a14c
commit
f082ff745e
|
@ -31,6 +31,7 @@ class Member < ActiveRecord::Base
|
|||
|
||||
before_destroy :set_issue_category_nil
|
||||
|
||||
|
||||
def role
|
||||
end
|
||||
|
||||
|
|
|
@ -35,8 +35,11 @@ class MemberRole < ActiveRecord::Base
|
|||
!inherited_from.nil?
|
||||
end
|
||||
|
||||
include Trustie::Gitlab::ManageMember
|
||||
|
||||
private
|
||||
|
||||
|
||||
def remove_member_if_empty
|
||||
if member.roles.empty?
|
||||
member.destroy
|
||||
|
|
|
@ -77,6 +77,27 @@ class Role < ActiveRecord::Base
|
|||
self.givable[3..5]
|
||||
end
|
||||
|
||||
GUEST = 10
|
||||
REPORTER = 20
|
||||
DEVELOPER = 30
|
||||
MASTER = 40
|
||||
OWNER = 50
|
||||
def to_gitlab_role
|
||||
case self.position
|
||||
when 1,2
|
||||
GUEST
|
||||
when 5
|
||||
REPORTER
|
||||
when 4
|
||||
DEVELOPER
|
||||
when 3
|
||||
MASTER
|
||||
else
|
||||
GUEST
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# Copies attributes from another role, arg can be an id or a Role
|
||||
def copy_from(arg, options={})
|
||||
return unless arg.present?
|
||||
|
|
|
@ -0,0 +1,42 @@
|
|||
#coding=utf-8
|
||||
#
|
||||
#
|
||||
module Trustie
|
||||
module Gitlab
|
||||
|
||||
module ManageMember
|
||||
def self.included(base)
|
||||
base.class_eval {
|
||||
before_create :add_gitlab_member
|
||||
before_destroy :delete_gitlab_member
|
||||
after_save :change_gitlab_member
|
||||
}
|
||||
end
|
||||
|
||||
def change_gitlab_member
|
||||
if self.member.project_id == 2
|
||||
@g ||= ::Gitlab.client
|
||||
@g.edit_team_member(11, self.member.user.gid, self.role.to_gitlab_role )
|
||||
end
|
||||
end
|
||||
|
||||
def add_gitlab_member
|
||||
if self.member.project_id == 2
|
||||
@g ||= ::Gitlab.client
|
||||
@g.add_team_member(11, self.member.user.gid, self.role.to_gitlab_role )
|
||||
end
|
||||
end
|
||||
|
||||
def delete_gitlab_member
|
||||
if member.roles.count <=1
|
||||
if self.member.project_id == 2
|
||||
@g ||= ::Gitlab.client
|
||||
@g.remove_team_member(11, self.member.user.gid)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue