43 lines
956 B
Ruby
43 lines
956 B
Ruby
|
#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
|
||
|
|