Пример #1
0
 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
Пример #2
0
 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()
Пример #3
0
 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()
Пример #4
0
 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
Пример #5
0
    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)
Пример #6
0
    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)
Пример #7
0
 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
Пример #8
0
 def member_ids(self):
     rs = TeamUserRelationship.gets(team_id=self.id, identity=TEAM_MEMBER)
     return [r.user_id for r in rs]
Пример #9
0
 def remove_user(self, user):
     r = TeamUserRelationship.get(team_id=self.id,
                                  user_id=user.name)
     if r:
         r.delete()
         return True
Пример #10
0
    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])
Пример #11
0
 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]
Пример #12
0
 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
Пример #13
0
 def n_users(self):
     return TeamUserRelationship.count(team_id=self.id)
Пример #14
0
 def n_owners(self):
     return TeamUserRelationship.count(team_id=self.id, identity=TEAM_OWNER)
Пример #15
0
 def is_member(self, user_id):
     r = TeamUserRelationship.get(team_id=self.id, user_id=user_id)
     return True if r else False
Пример #16
0
 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()
Пример #17
0
 def had_joined(self, user_id):
     r = TeamUserRelationship.get(team_id=self.id, user_id=user_id)
     return r or False
Пример #18
0
    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])
Пример #19
0
 def user_ids(self):
     rs = TeamUserRelationship.gets(team_id=self.id)
     return [r.user_id for r in rs]