def add_user(self, user, identity): r = TeamUserRelationship.get(team_id=self.id, user_id=user.name) if not r: TeamUserRelationship.create(team_id=self.id, user_id=user.name, identity=identity) return True
def test_add_and_delete_team_user_relationship(self): team_id = 1111 user_id = "chengeng" identity = 2 rl = TeamUserRelationship.create(team_id=team_id, user_id=user_id, identity=identity) relationship = TeamUserRelationship.get(team_id=team_id, user_id=user_id) ok_(rl.id == relationship.id) rl.delete()
def add_member(self, username): r = TeamUserRelationship.get(team_id=self.id, user_id=username) if not r: r = TeamUserRelationship.create(team_id=self.id, user_id=username, identity=TEAM_MEMBER) return True if r.identity != TEAM_MEMBER: r.identity = TEAM_MEMBER r.save() return True
def ttest_at_team(self): # FIXME mention = "test_team" team_name = "测试team" description = "测试" team = Team.add(mention, team_name, description) ok_(team.uid == mention) content = "@test_team code" users = get_mentions_from_text(content) # ok_(len(users) == 0) team_id = team.id user_id = "chengeng" identity = 2 rl = TeamUserRelationship.create(team_id=team_id, user_id=user_id, identity=identity) ok_(rl.user_id == user_id) users = get_mentions_from_text(content) ok_(users[0] == user_id) rl.delete() users = get_mentions_from_text(content) ok_(len(users) == 0) team.delete() users = get_mentions_from_text(content) ok_(users[0] == mention)
def test_at_team(self): mention = "test_team" team_name = "测试team" description = "测试" team = Team.add(mention, team_name, description) ok_(team.uid == mention) content = "@test_team code" users = get_mentions_from_text(content) ok_(len(users) == 0) team_id = team.id user_id = "chengeng" identity = 2 rl = TeamUserRelationship.create(team_id=team_id, user_id=user_id, identity=identity) ok_(rl.user_id == user_id) users = get_mentions_from_text(content) ok_(users[0] == user_id) rl.delete() users = get_mentions_from_text(content) ok_(len(users) == 0) team.delete() users = get_mentions_from_text(content) ok_(users[0] == mention)
def remove_member(self, username): r = TeamUserRelationship.get(team_id=self.id, user_id=username) if r: if r.identity != TEAM_MEMBER: return False r.delete() return True
def member_ids(self): rs = TeamUserRelationship.gets(team_id=self.id, identity=TEAM_MEMBER) return [r.user_id for r in rs]
def remove_user(self, user): r = TeamUserRelationship.get(team_id=self.id, user_id=user.name) if r: r.delete() return True
def teams(self): from vilya.models.nteam import TeamUserRelationship from vilya.models.team import Team rs = TeamUserRelationship.gets(user_id=self.name) return filter(None, [Team.get(r.team_id) for r in rs])
def get_by_user_id(cls, user_id): rls = TeamUserRelationship.gets(user_id=user_id) teams = [cls.get(rl.team_id) for rl in rls] return [(team.uid, team.name) for team in teams if team]
def is_owner(self, user_id): r = TeamUserRelationship.get(team_id=self.id, user_id=user_id) return r and r.is_owner or False
def n_users(self): return TeamUserRelationship.count(team_id=self.id)
def n_owners(self): return TeamUserRelationship.count(team_id=self.id, identity=TEAM_OWNER)
def is_member(self, user_id): r = TeamUserRelationship.get(team_id=self.id, user_id=user_id) return True if r else False
def delete(self): TeamProjectRelationship.deletes(team_id=self.id) TeamUserRelationship.deletes(team_id=self.id) del self.profile store.execute("delete from team where team_id=%s", (self.uid,)) store.commit()
def had_joined(self, user_id): r = TeamUserRelationship.get(team_id=self.id, user_id=user_id) return r or False
def user_ids(self): rs = TeamUserRelationship.gets(team_id=self.id) return [r.user_id for r in rs]