Пример #1
0
    def settings(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not team:
            raise TraversalError
        projects = team.projects

        input_uid = request.get_form_var("uid", "")
        input_name = request.get_form_var("name", "")
        input_description = request.get_form_var("description", "")

        error = ""
        if request.method == "POST":
            if not user:
                return request.redirect("/")

            if not team.is_owner(user.name):
                return request.redirect(team.url)

            teams = Team.gets()
            team_uid_pattern = re.compile(r"[a-zA-Z0-9\_]*")
            if not input_uid:
                error = "uid_not_exists"
            elif not input_name:
                error = "name_not_exists"
            elif input_uid != re.findall(team_uid_pattern, input_uid)[0]:
                error = "invilid_uid"
            elif input_uid in [t.uid for t in teams] and team.uid != input_uid:
                error = "uid_existed"
            elif input_name in [t.name for t in teams] and team.name != input_name:
                error = "name_existed"
            else:
                team.update(input_uid, input_name, input_description)
                return request.redirect("/hub/team/%s/settings" % input_uid)
        return st("/teams/team_settings.html", **locals())
Пример #2
0
def add_team(request):
    user = request.user
    if not user:
        return request.redirect("/")

    uid = request.get_form_var('uid') or ''
    name = request.get_form_var('name') or ''
    description = request.get_form_var('description') or ''

    errors = ""
    if request.method == "POST":
        teams = Team.gets()
        team_uid_pattern = re.compile(r'[a-zA-Z0-9\_]*')
        if not uid:
            error = 'uid_not_exists'
        elif not name:
            error = 'name_not_exists'
        elif uid != re.findall(team_uid_pattern, uid)[0]:
            error = 'invilid_uid'
        elif uid in [team.uid for team in teams]:
            error = 'uid_existed'
        elif User.check_exist(uid):
            error = 'user_id_existed'
        elif name in [team.name for team in teams]:
            error = 'name_existed'
        else:
            team = Team.add(uid, name, description)
            if team:
                team_created_signal.send(user.name,
                                         team_name=team.name,
                                         team_uid=team.uid)
                team.add_user(user, TEAM_OWNER)
                return request.redirect(team.url)

    return st('/teams/add_team.html', **locals())
Пример #3
0
def add_team(request):
    user = request.user
    if not user:
        return request.redirect("/")

    uid = request.get_form_var('uid') or ''
    name = request.get_form_var('name') or ''
    description = request.get_form_var('description') or ''

    errors = ""
    if request.method == "POST":
        teams = Team.gets()
        team_uid_pattern = re.compile(r'[a-zA-Z0-9\_]*')
        if not uid:
            error = 'uid_not_exists'
        elif not name:
            error = 'name_not_exists'
        elif uid != re.findall(team_uid_pattern, uid)[0]:
            error = 'invilid_uid'
        elif uid in [team.uid for team in teams]:
            error = 'uid_existed'
        elif User.check_exist(uid):
            error = 'user_id_existed'
        elif name in [team.name for team in teams]:
            error = 'name_existed'
        else:
            team = Team.add(uid, name, description)
            if team:
                team_created_signal.send(user.name,
                                         team_name=team.name,
                                         team_uid=team.uid)
                team.add_user(user, TEAM_OWNER)
                return request.redirect(team.url)

    return st('/teams/add_team.html', **locals())
Пример #4
0
    def _q_index(self, request):
        page = request.get_form_var('page', 1)
        start = TEAMS_COUNT_PER_PAGE * (int(page) - 1)
        teams = Team.gets_by_page(start=start, limit=TEAMS_COUNT_PER_PAGE)
        total_teams = len(Team.gets())
        n_pages = (total_teams - 1) / TEAMS_COUNT_PER_PAGE + 1 if total_teams else 1  # noqa

        return st('/teams/teams.html', **locals())
Пример #5
0
    def _q_index(self, request):
        page = request.get_form_var('page', 1)
        start = TEAMS_COUNT_PER_PAGE * (int(page) - 1)
        teams = Team.gets_by_page(start=start, limit=TEAMS_COUNT_PER_PAGE)
        total_teams = len(Team.gets())
        n_pages = (total_teams -
                   1) / TEAMS_COUNT_PER_PAGE + 1 if total_teams else 1  # noqa

        return st('/teams/teams.html', **locals())
Пример #6
0
 def test_add_and_delete_team(self):
     team_id = "test_team"
     team_name = "测试team"
     description = "测试"
     n_team = len(Team.gets())
     team = Team.add(team_id, team_name, description)
     new_n_team = len(Team.gets())
     ok_(new_n_team == n_team + 1)
     ok_(team_id == team.uid)
     team.delete()
     new_n_team = len(Team.gets())
     ok_(new_n_team == n_team)
Пример #7
0
 def test_add_and_delete_team(self):
     team_id = "test_team"
     team_name = "测试team"
     description = "测试"
     n_team = len(Team.gets())
     team = Team.add(team_id, team_name, description)
     new_n_team = len(Team.gets())
     ok_(new_n_team == n_team + 1)
     ok_(team_id == team.uid)
     team.delete()
     new_n_team = len(Team.gets())
     ok_(new_n_team == n_team)
Пример #8
0
    def test_new_team_issue_participant_count(self):
        app = TestApp(M.app)
        for team in Team.gets():
            if team:
                team.delete()
        team = Team.add("test_team", "test team", "test")
        issue = TeamIssue.add('test', 'test description', 'test', team=team.id)
        resp = app.get(issue.url)

        assert resp.status_int == 200
        assert 'Issues' in resp.body
        assert '<strong>1</strong> participant' in resp.text
        assert '<strong>1</strong> participants' not in resp.text
Пример #9
0
    def add_user(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user or not team:
            return dict(r=1, error="team不存在")

        user_id = request.get_form_var("user_id", "")
        identity = int(request.get_form_var("identity", 0))

        if not team.is_owner(user.name) or identity not in TEAM_IDENTITY_INFO.keys():
            return dict(r=1, error="没有权限")

        rl = TeamUserRelationship.get(team_id=team.id, user_id=user_id)
        if not rl:
            team.add_user(User(user_id), identity)
        elif identity == rl.identity:
            return dict(r=1, error="该用户已存在")
        elif rl.is_owner and team.n_owners == 1:
            return dict(r=1, error="只剩一个creator, 不能改变身份")
        else:
            rl.identity = identity
            rl.save()

        avatar_url = User(user_id).avatar_url
        team_add_member_signal.send(
            user.name,
            team_uid=team.uid,
            team_name=team.name,
            receiver=user_id,
            identity=TEAM_IDENTITY_INFO[identity]["name"],
        )
        return dict(r=0, uid=user_id, avatar_url=avatar_url)
Пример #10
0
def _q_index(request):
    user = request.user
    my_issues = []
    if user:
        username = user.username

        your_projects = CodeDoubanProject.get_projects(owner=username,
                                                       sortby='lru')
        watched_projects = CodeDoubanProject.get_watched_others_projects_by_user(  # noqa
            user=username, sortby='lru')

        teams = Team.get_by_user_id(user.name)
        actions = get_user_inbox(username).get_actions(
            stop=PAGE_ACTIONS_COUNT - 1)
        badge_items = user.get_badge_items()

        # pull request
        # your_tickets = user.get_user_pull_requests_rank(limit=5)
        your_tickets = user.get_user_submit_pull_requests(limit=5)

        # issue
        project_ids = CodeDoubanProject.get_ids(user.name)
        dt = {
            'state': "open",
            'limit': 5,
            'start': 0,
        }
        my_issues = ProjectIssue.gets_by_project_ids(project_ids, **dt)

        return st('newsfeed.html', **locals())
    return request.redirect("/teams/")
Пример #11
0
    def comment(self, request):
        target = self.target
        issue = self.issue
        issue_id = self.issue_id
        current_user = request.user

        if request.method == 'POST':
            content = request.get_form_var('content', '').decode('utf-8')
            user = request.user
            user = user.name if user else None
            if user:
                author = user
                if content.strip():
                    comment = issue.add_comment(content, user)
                    issue.add_participant(user)
                    html = st('/widgets/issue/issue_comment.html', **locals())
                else:
                    return {'error': 'Content is empty'}

                if request.get_form_var('comment_and_close'):
                    issue.close(author)
                    # TODO: 重构feed后取消信号发送
                    issue_signal.send(author=author, content=content,
                                      issue_id=issue_id)
                    dispatch('issue', data={
                             'sender': author,
                             'content': content,
                             'issue': issue,
                             })
                    return dict(r=0, reload=1, redirect_to=issue.url)
                elif request.get_form_var('comment_and_open'):
                    issue.open()
                    # TODO: 重构feed后取消信号发送
                    issue_signal.send(author=author, content=content,
                                      issue_id=issue_id)
                    dispatch('issue', data={
                             'sender': author,
                             'content': content,
                             'issue': issue,
                             })
                    return dict(r=0, reload=1, redirect_to=issue.url)
                elif content:
                    issue_comment_signal.send(author=author,
                                              content=comment.content,
                                              issue_id=comment.issue_id,
                                              comment_id=comment.id)
                    dispatch('issue_comment', data={
                             'sender': author,
                             'content': comment.content,
                             'issue': issue,
                             'comment': comment})
                participants = issue.participants

                teams = Team.get_all_team_uids()

                participants_html = st('/widgets/participation.html',
                                       **locals())  # FIXME: locals()?
                return dict(
                    r=0, html=html, participants_html=participants_html)
        return request.redirect(issue.url)
Пример #12
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)
Пример #13
0
def _q_index(request):
    user = request.user
    my_issues = []
    if user:
        username = user.username

        your_projects = CodeDoubanProject.get_projects(owner=username,
                                                       sortby='lru')
        watched_projects = CodeDoubanProject.get_watched_others_projects_by_user(  # noqa
            user=username,
            sortby='lru')

        teams = Team.get_by_user_id(user.name)
        actions = get_user_inbox(username).get_actions(
            stop=PAGE_ACTIONS_COUNT - 1)
        badge_items = user.get_badge_items()

        # pull request
        # your_tickets = user.get_user_pull_requests_rank(limit=5)
        your_tickets = user.get_user_submit_pull_requests(limit=5)

        # issue
        project_ids = CodeDoubanProject.get_ids(user.name)
        dt = {
            'state': "open",
            'limit': 5,
            'start': 0,
        }
        my_issues = ProjectIssue.gets_by_project_ids(project_ids, **dt)

        return st('newsfeed.html', **locals())
    return request.redirect("/teams/")
Пример #14
0
    def add_user(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user or not team:
            return dict(r=1, error="team不存在")

        user_id = request.get_form_var('user_id', '')
        identity = int(request.get_form_var('identity', 0))

        if not team.is_owner(user.name) \
                or identity not in TEAM_IDENTITY_INFO.keys():
            return dict(r=1, error="没有权限")

        rl = TeamUserRelationship.get(team_id=team.id, user_id=user_id)
        if not rl:
            team.add_user(User(user_id), identity)
        elif identity == rl.identity:
            return dict(r=1, error="该用户已存在")
        elif rl.is_owner and team.n_owners == 1:
            return dict(r=1, error="只剩一个creator, 不能改变身份")
        else:
            rl.identity = identity
            rl.save()

        avatar_url = User(user_id).avatar_url
        team_add_member_signal.send(
            user.name, team_uid=team.uid, team_name=team.name,
            receiver=user_id, identity=TEAM_IDENTITY_INFO[identity]["name"])
        return dict(r=0, uid=user_id, avatar_url=avatar_url)
Пример #15
0
def card_info(request):
    user_or_team_id = request.get_form_var('user')
    team = Team.get_by_uid(user_or_team_id)
    user_existed = User.check_exist(user_or_team_id)
    if not team or user_existed:
        user = User(user_or_team_id)
        data = {
            'user': {'name': user_or_team_id, 'avatar': user.avatar_url,
                     'url': user.url,
                     'badges': [{'img': item.badge.get_image_url(),
                                 'name': item.badge.name,
                                 'reason': item.reason or item.badge.summary}
                                for item in user.get_badge_items()]}
        }
    else:
        members = team.user_ids[::-1]  # 根据团队的时间排序
        displayed_users = [User(uid) for uid in team.user_ids[:8]]
        data = {
            'team': {
                'id': team.uid,
                'name': team.name,
                'url': team.url,
                'desc': team.short_description,
                'profile_url': team.profile_url(),
                'members': [{'uid': u.name, 'avatar_url': u.avatar_url}
                            for u in displayed_users],
                'member_count': len(members)
            }
        }
    return json.dumps(data)
Пример #16
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)
Пример #17
0
 def new(self, request):
     project_name = self.proj_name
     project = self.project
     user = request.user
     tags = project.tags
     error = request.get_form_var('error')
     teams = Team.get_all_team_uids()
     return st('issue/new.html', **locals())
Пример #18
0
    def __init__(self, team_uid, issue_number):
        self.target = Team.get_by_uid(team_uid)
        self.issue_number = issue_number

        team_issue = TeamIssue.get(self.target.id, number=self.issue_number)
        self.issue_id = team_issue.issue_id
        self.issue = Issue.get_cached_issue(self.issue_id)
        self.issue_template = 'issue/team_issue.html'
Пример #19
0
    def leave(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user or not team:
            return dict(r=1)

        team.remove_user(user)
        return dict(r=0)
Пример #20
0
 def new(self, request):
     user = request.user
     current_user = request.user
     team = self.team
     tags = team.tags
     error = request.get_form_var('error')
     teams = Team.get_all_team_uids()
     return st('issue/new_team_issue.html', **locals())
Пример #21
0
 def new(self, request):
     project_name = self.proj_name
     project = self.project
     user = request.user
     tags = project.tags
     error = request.get_form_var('error')
     teams = Team.get_all_team_uids()
     return st('issue/new.html', **locals())
Пример #22
0
    def __init__(self, team_uid, issue_number):
        self.target = Team.get_by_uid(team_uid)
        self.issue_number = issue_number

        team_issue = TeamIssue.get(self.target.id, number=self.issue_number)
        self.issue_id = team_issue.issue_id
        self.issue = Issue.get_cached_issue(self.issue_id)
        self.issue_template = "issue/team_issue.html"
Пример #23
0
    def leave(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user or not team:
            return dict(r=1)

        team.remove_user(user)
        return dict(r=0)
Пример #24
0
def _get_team_by_uid(uid):
    _team = Team.get_by_uid(uid)
    team = dict(
        id=_team.id,
        uid=_team.uid,
        name=_team.name,
    )
    return team
Пример #25
0
 def new(self, request):
     user = request.user
     current_user = request.user
     team = self.team
     tags = team.tags
     error = request.get_form_var("error")
     teams = Team.get_all_team_uids()
     return st("issue/new_team_issue.html", **locals())
Пример #26
0
    def join(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user or not team:
            return dict(r=1)

        team.add_user(user, TEAM_MEMBER)
        team_joined_signal.send(user.name, team_id=team.id, team_uid=team.uid, team_name=team.name)
        return dict(r=0)
Пример #27
0
    def new(self, request):
        user = request.user
        if not user:
            raise AccessError
        from_proj = self.project
        from_ref = request.get_form_var('head_ref', from_proj.default_branch)
        parent_proj = from_proj.get_forked_from()
        to_proj = request.get_form_var('base_repo')
        if to_proj:
            to_proj = CodeDoubanProject.get_by_name(to_proj)
        elif parent_proj:
            to_proj = parent_proj
        else:
            to_proj = from_proj
        if not to_proj:
            raise TraversalError("The PR's upstream project is not existed")
        to_ref = request.get_form_var('base_ref', to_proj.default_branch)
        if from_proj != to_proj:
            # Allow to create PR to a different project only if user has push perm
            # ~~A bit weird, maybe should be separate perms
            # ~~If from and to projects are the same, we should be in online edit mode
            if not from_proj.has_push_perm(user.name):
                raise AccessError(
                    "Need push permission to add a PR on another project")
        pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
        family = from_proj.get_fork_network()
        from_branches = from_proj.repo.branches
        to_branches = to_proj.repo.branches
        from_commit = pullreq.from_commit
        to_commit = pullreq.to_commit
        if not pullreq.can_pull:
            raise TraversalError(
                "The PR's head_ref or base_ref is not existed")
        highlighted_projects = filter(None, [from_proj, parent_proj])
        commits = pullreq.commits
        n_commits = len(commits)
        n_authors = len(set(c.author.username for c in commits))
        ticket_title, ticket_desc = self._choose_default_PR_title_and_description(
            commits)  # noqa

        # get diff
        diff = pullreq.get_diff(rename_detection=True)
        n_files = diff.length

        grouped_commits = groupby(commits, lambda c: c.author_time.date())

        prs = PullRequest.get_by_from_and_to(from_proj.id, from_ref,
                                             to_proj.id, to_ref)
        open_pullreqs = []
        for pr in prs:
            t = Ticket.get_by_projectid_and_ticketnumber(
                to_proj.id, pr.ticket_id)
            if t and t.closed is None:
                open_pullreqs.append(pr)
        guideline_url = get_project_guidelines(to_proj)
        teams = Team.get_all_team_uids()
        return st('/pull/new.html', **locals())
Пример #28
0
def judge_user(name):
    from vilya.models.team import Team
    if CodeUser.get(name=name):
        return "people"
    else:
        if Team.get_by_uid(name):
            return "team"
        else:
            return "people"
Пример #29
0
def judge_user(name):
    from vilya.models.team import Team
    if CodeUser.get(name=name):
        return "people"
    else:
        if Team.get_by_uid(name):
            return "team"
        else:
            return "people"
Пример #30
0
    def new(self, request):
        user = request.user
        if not user:
            raise AccessError
        from_proj = self.project
        from_ref = request.get_form_var('head_ref', from_proj.default_branch)
        parent_proj = from_proj.get_forked_from()
        to_proj = request.get_form_var('base_repo')
        if to_proj:
            to_proj = CodeDoubanProject.get_by_name(to_proj)
        elif parent_proj:
            to_proj = parent_proj
        else:
            to_proj = from_proj
        if not to_proj:
            raise TraversalError("The PR's upstream project is not existed")
        to_ref = request.get_form_var('base_ref', to_proj.default_branch)
        if from_proj != to_proj:
            # Allow to create PR to a different project only if user has push perm
            # ~~A bit weird, maybe should be separate perms
            # ~~If from and to projects are the same, we should be in online edit mode
            if not from_proj.has_push_perm(user.name):
                raise AccessError(
                    "Need push permission to add a PR on another project")
        pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
        family = from_proj.get_fork_network()
        from_branches = from_proj.repo.branches
        to_branches = to_proj.repo.branches
        from_commit = pullreq.from_commit
        to_commit = pullreq.to_commit
        if not pullreq.can_pull:
            raise TraversalError(
                "The PR's head_ref or base_ref is not existed")
        highlighted_projects = filter(None, [from_proj, parent_proj])
        commits = pullreq.commits
        n_commits = len(commits)
        n_authors = len(set(c.author.username for c in commits))
        ticket_title, ticket_desc = self._choose_default_PR_title_and_description(commits)  # noqa

        # get diff
        diff = pullreq.get_diff(rename_detection=True)
        n_files = diff.length

        grouped_commits = groupby(commits, lambda c: c.author_time.date())

        prs = PullRequest.get_by_from_and_to(
            from_proj.id, from_ref, to_proj.id, to_ref)
        open_pullreqs = []
        for pr in prs:
            t = Ticket.get_by_projectid_and_ticketnumber(
                to_proj.id, pr.ticket_id)
            if t and t.closed is None:
                open_pullreqs.append(pr)
        guideline_url = get_project_guidelines(to_proj)
        teams = Team.get_all_team_uids()
        return st('/pull/new.html', **locals())
Пример #31
0
 def _q_lookup(self, request, num):
     if not num.isdigit():
         raise TraversalError
     num = int(num)
     team = Team.get_by_uid(self.team_uid)
     actions = get_team_feed(team.id).get_actions(start=num,
                                                  stop=num+PAGE_ACTIONS_COUNT-1)
     length = len(actions)
     render_html = render_actions(actions, show_avatar=True)
     return {'result': render_html, 'length': length}
Пример #32
0
 def _q_index(self, request):
     user = request.user
     team = Team.get_by_uid(self.team_uid)
     if not team:
         raise TraversalError
     projects = team.projects
     is_admin = False
     if user and team.is_owner(user.name):
         is_admin = True
     return st('/teams/team.html', **locals())
Пример #33
0
 def _q_index(self, request):
     user = request.user
     team = Team.get_by_uid(self.team_uid)
     if not team:
         raise TraversalError
     projects = team.projects
     is_admin = False
     if user and team.is_owner(user.name):
         is_admin = True
     return st("/teams/team.html", **locals())
Пример #34
0
    def remove(self, request):
        team = Team.get_by_uid(self.team_uid)
        if not team:
            return dict(r=1)

        user = request.user
        if not user or not team.is_owner(user.name):
            return dict(r=1)

        team.delete()
        return {'r': 0}
Пример #35
0
    def remove(self, request):
        team = Team.get_by_uid(self.team_uid)
        if not team:
            return dict(r=1)

        user = request.user
        if not user or not team.is_owner(user.name):
            return dict(r=1)

        team.delete()
        return {"r": 0}
Пример #36
0
 def _q_lookup(self, request, num):
     if not num.isdigit():
         raise TraversalError
     num = int(num)
     team = Team.get_by_uid(self.team_uid)
     actions = get_team_feed(team.id).get_actions(start=num,
                                                  stop=num +
                                                  PAGE_ACTIONS_COUNT - 1)
     length = len(actions)
     render_html = render_actions(actions, show_avatar=True)
     return {'result': render_html, 'length': length}
Пример #37
0
 def join(self, request):
     issue = self.issue
     user = request.user
     if user:
         issue.add_participant(user.name)
         participants = issue.participants
         teams = Team.get_all_team_uids()
         participants_html = st('/widgets/participation.html',
                                participants=participants, teams=teams)
         return dict(r=0, participants_html=participants_html)
     return dict(r=1)
Пример #38
0
 def _q_index(self, request):
     name = self.name
     your_projects = CodeDoubanProject.get_projects(owner=name, sortby="lru")
     actions = get_user_feed(name).get_actions(0, 20)
     user = User(name)
     teams = Team.get_by_user_id(user.name)
     badge_items = user.get_badge_items()
     followers_count = user.followers_count
     following_count = user.following_count
     if user and user.username == name and user.get_new_badges():
         user.clear_new_badges()
     return st("people.html", **locals())
Пример #39
0
 def news(self, request):
     user = request.user
     team = Team.get_by_uid(self.team_uid)
     if not team:
         raise TraversalError
     feed = get_team_feed(team.id)
     actions = feed.get_actions(stop=PAGE_ACTIONS_COUNT - 1)
     projects = team.projects
     is_admin = False
     if user and team.is_owner(user.name):
         is_admin = True
     return st('/teams/news.html', **locals())
Пример #40
0
 def join(self, request):
     issue = self.issue
     user = request.user
     if user:
         issue.add_participant(user.name)
         participants = issue.participants
         teams = Team.get_all_team_uids()
         participants_html = st('/widgets/participation.html',
                                participants=participants,
                                teams=teams)
         return dict(r=0, participants_html=participants_html)
     return dict(r=1)
Пример #41
0
 def news(self, request):
     user = request.user
     team = Team.get_by_uid(self.team_uid)
     if not team:
         raise TraversalError
     feed = get_team_feed(team.id)
     actions = feed.get_actions(stop=PAGE_ACTIONS_COUNT - 1)
     projects = team.projects
     is_admin = False
     if user and team.is_owner(user.name):
         is_admin = True
     return st("/teams/news.html", **locals())
Пример #42
0
    def join(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user or not team:
            return dict(r=1)

        team.add_user(user, TEAM_MEMBER)
        team_joined_signal.send(user.name,
                                team_id=team.id,
                                team_uid=team.uid,
                                team_name=team.name)
        return dict(r=0)
Пример #43
0
 def _q_index(self, request):
     show_close = True
     target = self.target
     issue = self.issue
     user = request.user
     current_user = request.user
     author = issue.creator
     i_am_author = user and issue.creator_id == user.username
     i_am_admin = user and target.is_admin(user.name)
     has_user_voted = issue.has_user_voted(user.name) if user else False
     vote_count = issue.vote_count
     teams = Team.get_all_team_uids()
     return st(self.issue_template, **locals())
Пример #44
0
 def leave(self, request):
     issue = self.issue
     user = request.user
     if user:
         if user.name == issue.creator_id:
             return dict(r=1, msg="Can't leave the issue created by you.")
         issue.delete_participant(user.name)
         participants = issue.participants
         teams = Team.get_all_team_uids()
         participants_html = st('/widgets/participation.html',
                                participants=participants, teams=teams)
         return dict(r=0, participants_html=participants_html)
     return dict(r=1)
Пример #45
0
 def _q_index(self, request):
     name = self.name
     your_projects = CodeDoubanProject.get_projects(owner=name,
                                                    sortby='lru')
     actions = get_user_feed(name).get_actions(0, 20)
     user = User(name)
     teams = Team.get_by_user_id(user.name)
     badge_items = user.get_badge_items()
     followers_count = user.followers_count
     following_count = user.following_count
     if user and user.username == name and user.get_new_badges():
         user.clear_new_badges()
     return st('people.html', **locals())
Пример #46
0
 def _q_index(self, request):
     show_close = True
     target = self.target
     issue = self.issue
     user = request.user
     current_user = request.user
     author = issue.creator
     i_am_author = user and issue.creator_id == user.username
     i_am_admin = user and target.is_admin(user.name)
     has_user_voted = issue.has_user_voted(user.name) if user else False
     vote_count = issue.vote_count
     teams = Team.get_all_team_uids()
     return st(self.issue_template, **locals())
Пример #47
0
 def destroy(self, request):
     project = self.project
     group_name = request.get_form_var('group', '')
     if not group_name:
         return request.redirect("%ssettings/" % project.url)
     team, _, group = group_name.rpartition('/')
     t = Team.get_by_uid(team)
     if not t:
         return request.redirect("%ssettings/" % project.url)
     g = TeamGroup.get(team_id=t.id, name=group)
     if not g:
         return request.redirect("%ssettings/" % project.url)
     g.remove_project(project_id=project.id)
     return request.redirect("%ssettings/" % project.url)
Пример #48
0
 def destroy(self, request):
     project = self.project
     group_name = request.get_form_var('group', '')
     if not group_name:
         return request.redirect("%ssettings/" % project.url)
     team, _, group = group_name.rpartition('/')
     t = Team.get_by_uid(team)
     if not t:
         return request.redirect("%ssettings/" % project.url)
     g = TeamGroup.get(team_id=t.id, name=group)
     if not g:
         return request.redirect("%ssettings/" % project.url)
     g.remove_project(project_id=project.id)
     return request.redirect("%ssettings/" % project.url)
Пример #49
0
 def leave(self, request):
     issue = self.issue
     user = request.user
     if user:
         if user.name == issue.creator_id:
             return dict(r=1, msg="Can't leave the issue created by you.")
         issue.delete_participant(user.name)
         participants = issue.participants
         teams = Team.get_all_team_uids()
         participants_html = st('/widgets/participation.html',
                                participants=participants,
                                teams=teams)
         return dict(r=0, participants_html=participants_html)
     return dict(r=1)
Пример #50
0
    def settings(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not team:
            raise TraversalError
        projects = team.projects

        input_uid = request.get_form_var('uid', '')
        input_name = request.get_form_var('name', '')
        input_description = request.get_form_var('description', '')

        error = ''
        if request.method == "POST":
            if not user:
                return request.redirect("/")

            if not team.is_owner(user.name):
                return request.redirect(team.url)

            teams = Team.gets()
            team_uid_pattern = re.compile(r'[a-zA-Z0-9\_]*')
            if not input_uid:
                error = 'uid_not_exists'
            elif not input_name:
                error = 'name_not_exists'
            elif input_uid != re.findall(team_uid_pattern, input_uid)[0]:
                error = 'invilid_uid'
            elif input_uid in [t.uid for t in teams] and team.uid != input_uid:
                error = 'uid_existed'
            elif input_name in [t.name for t in teams] \
                 and team.name != input_name:
                error = 'name_existed'
            else:
                team.update(input_uid, input_name, input_description)
                return request.redirect("/hub/team/%s/settings" % input_uid)
        return st('/teams/team_settings.html', **locals())
Пример #51
0
    def remove_project(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user or not team:
            return dict(r=1)

        if not team.is_owner(user.name):
            return dict(r=1)

        project_name = request.get_form_var("project_name", "")
        project = CodeDoubanProject.get_by_name(project_name)
        if not project:
            return dict(r=1)

        team.remove_project(project)
        return dict(r=0)
Пример #52
0
    def remove_project(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user or not team:
            return dict(r=1)

        if not team.is_owner(user.name):
            return dict(r=1)

        project_name = request.get_form_var('project_name', '')
        project = CodeDoubanProject.get_by_name(project_name)
        if not project:
            return dict(r=1)

        team.remove_project(project)
        return dict(r=0)
Пример #53
0
def card_info(request):
    user_or_team_id = request.get_form_var('user')
    team = Team.get_by_uid(user_or_team_id)
    user_existed = User.check_exist(user_or_team_id)
    if not team or user_existed:
        user = User(user_or_team_id)
        data = {
            'user': {
                'name':
                user_or_team_id,
                'avatar':
                user.avatar_url,
                'url':
                user.url,
                'badges': [{
                    'img': item.badge.get_image_url(),
                    'name': item.badge.name,
                    'reason': item.reason or item.badge.summary
                } for item in user.get_badge_items()]
            }
        }
    else:
        members = team.user_ids[::-1]  # 根据团队的时间排序
        displayed_users = [User(uid) for uid in team.user_ids[:8]]
        data = {
            'team': {
                'id':
                team.uid,
                'name':
                team.name,
                'url':
                team.url,
                'desc':
                team.short_description,
                'profile_url':
                team.profile_url(),
                'members': [{
                    'uid': u.name,
                    'avatar_url': u.avatar_url
                } for u in displayed_users],
                'member_count':
                len(members)
            }
        }
    return json.dumps(data)
Пример #54
0
    def upload_profile(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user and not team:
            return dict(r=1)
        if team and not team.is_owner(user.name):
            return dict(r=1)

        upload_url = request.get_form_var('url', '')
        hash_png = request.get_form_var('hash', '')
        profile = {'origin': upload_url}
        if upload_url and hash_png:
            rsize_url = '{0}/r/{1}?w=100&h=100'.format(UPLOAD_URL, hash_png)
            r = requests.get(rsize_url)
            r.raise_for_status()
            profile.update({'icon': r.text})
        team.profile = profile
        return dict(r=0)
Пример #55
0
    def upload_profile(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user and not team:
            return dict(r=1)
        if team and not team.is_owner(user.name):
            return dict(r=1)

        upload_url = request.get_form_var("url", "")
        hash_png = request.get_form_var("hash", "")
        profile = {"origin": upload_url}
        if upload_url and hash_png:
            rsize_url = "{0}/r/{1}?w=100&h=100".format(UPLOAD_URL, hash_png)
            r = requests.get(rsize_url)
            r.raise_for_status()
            profile.update({"icon": r.text})
        team.profile = profile
        return dict(r=0)
Пример #56
0
def main():
    public_feed = get_public_feed()
    public_feed_v2 = get_public_feed_v2()
    feeds = public_feed.get_actions()
    for feed in feeds:
        date = datetime.strptime(feed['date'], "%Y-%m-%d %H:%M:%S")
        feed['date'] = date
        public_feed_v2.add_action(feed)
    print "updated %s public feeds." % len(feeds)

    teams = Team.gets()
    for team in teams:
        team_feed = get_team_feed(team.id)
        team_feed_v2 = get_team_feed_v2(team.id)
        feeds = team_feed.get_actions()
        for feed in feeds:
            date = datetime.strptime(feed['date'], "%Y-%m-%d %H:%M:%S")
            feed['date'] = date
            team_feed_v2.add_action(feed)
        print "updated %s team %s feeds." % (len(feeds), team.name)

    user_inbox_keys = rds.keys('feed:private:user:v1:*')
    for key in user_inbox_keys:
        _, _, _, _, user = key.split(':')
        user_feed = get_user_inbox(user)
        user_feed_v2 = get_user_inbox_v2(user)
        feeds = user_feed.get_actions()
        for feed in feeds:
            date = datetime.strptime(feed['date'], "%Y-%m-%d %H:%M:%S")
            feed['date'] = date
            user_feed_v2.add_action(feed)
        print "updated %s user %s inbox feeds." % (len(feeds), user)

    user_feed_keys = rds.keys('feed:public:user:v1:*')
    for key in user_feed_keys:
        _, _, _, _, user = key.split(':')
        user_feed = get_user_feed(user)
        user_feed_v2 = get_user_feed_v2(user)
        feeds = user_feed.get_actions()
        for feed in feeds:
            date = datetime.strptime(feed['date'], "%Y-%m-%d %H:%M:%S")
            feed['date'] = date
            user_feed_v2.add_action(feed)
        print "updated %s user %s feeds." % (len(feeds), user)
Пример #57
0
def main():
    public_feed = get_public_feed()
    public_feed_v2 = get_public_feed_v2()
    feeds = public_feed.get_actions()
    for feed in feeds:
        date = datetime.strptime(feed['date'], "%Y-%m-%d %H:%M:%S")
        feed['date'] = date
        public_feed_v2.add_action(feed)
    print "updated %s public feeds." % len(feeds)

    teams = Team.gets()
    for team in teams:
        team_feed = get_team_feed(team.id)
        team_feed_v2 = get_team_feed_v2(team.id)
        feeds = team_feed.get_actions()
        for feed in feeds:
            date = datetime.strptime(feed['date'], "%Y-%m-%d %H:%M:%S")
            feed['date'] = date
            team_feed_v2.add_action(feed)
        print "updated %s team %s feeds." % (len(feeds), team.name)

    user_inbox_keys = rds.keys('feed:private:user:v1:*')
    for key in user_inbox_keys:
        _, _, _, _, user = key.split(':')
        user_feed = get_user_inbox(user)
        user_feed_v2 = get_user_inbox_v2(user)
        feeds = user_feed.get_actions()
        for feed in feeds:
            date = datetime.strptime(feed['date'], "%Y-%m-%d %H:%M:%S")
            feed['date'] = date
            user_feed_v2.add_action(feed)
        print "updated %s user %s inbox feeds." % (len(feeds), user)

    user_feed_keys = rds.keys('feed:public:user:v1:*')
    for key in user_feed_keys:
        _, _, _, _, user = key.split(':')
        user_feed = get_user_feed(user)
        user_feed_v2 = get_user_feed_v2(user)
        feeds = user_feed.get_actions()
        for feed in feeds:
            date = datetime.strptime(feed['date'], "%Y-%m-%d %H:%M:%S")
            feed['date'] = date
            user_feed_v2.add_action(feed)
        print "updated %s user %s feeds." % (len(feeds), user)
Пример #58
0
def _q_index(request):
    sortby = request.get_form_var('sortby')
    if sortby in CodeDoubanProject.PROJECTS_SORT_BYS:
        project_list = CodeDoubanProject.get_projects(sortby=sortby)
    else:
        project_list = CodeDoubanProject.get_projects()

    team_uid = request.get_form_var('by_dept', '')
    team = Team.get_by_uid(team_uid)
    if team:
        project_ids = team.project_ids
        project_list = (CodeDoubanProject.gets(project_ids)
                        if project_ids else [])

    without_commits = request.get_form_var('without_commits') or False
    data = {}
    data['projects'] = [project.get_info(
        without_commits=without_commits) for project in project_list]
    return json.dumps(data)
Пример #59
0
    def add_project(self, request):
        user = request.user
        team = Team.get_by_uid(self.team_uid)
        if not user and not team:
            return request.redirect('/')
        if team and not team.is_owner(user.name):
            return request.redirect(team.url)

        project_name = request.get_form_var('project_name') or ''
        project = CodeDoubanProject.get_by_name(project_name)
        error = ''
        if request.method == 'POST':
            if not project_name:
                error = 'project_name_not_exists'
            elif not project:
                error = 'project_not_exists'
            else:
                team.add_project(project)
                return request.redirect(team.url)
        return st('/teams/team_add_project.html', **locals())