同步members

This commit is contained in:
guange 2015-08-01 20:09:53 +08:00
parent 9d8596a14c
commit f082ff745e
4 changed files with 67 additions and 0 deletions

View File

@ -31,6 +31,7 @@ class Member < ActiveRecord::Base
before_destroy :set_issue_category_nil
def role
end

View File

@ -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

View File

@ -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?

View File

@ -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