def render_push_action(action, organization, team=None, repo=None): repo_key = 'repo:%d' % action['repo_id'] repo_url_key = 'repo:url:%d' % action['repo_id'] repo_branch_key = 'repo:branch:url:%d' % action['repo_id'] repo = repo or cache.get(repo_key, None) or get_repo(action['repo_id']) repo_url = cache.get(repo_url_key) action['branch'] = format_branch(action['branch']) branch_url = cache.get(repo_branch_key) repo_url = repo_url or get_repo_url(organization, repo) branch_url = branch_url or get_repo_url(organization, repo, version=action['branch']) cache.set(repo_key, repo) cache.set(repo_url_key, repo_url) cache.set(repo_branch_key, branch_url) action['repo'] = repo action['repo_url'] = repo_url action['branch_url'] = branch_url action['committer'] = cache.get(action['committer_id'], None) or get_user(action['committer_id']) length = len(action['data']) for i in xrange(0, length): log = action['data'][i] author = cache.get(log['author_email'], False) if author is False: author = get_user_from_alias(log['author_email']) cache.set(log['author_email'], author) log['author'] = author log['author_time'] = format_time(log['author_time']) log['message'] = log['message'].decode('utf8') if action['commits_num'] > length: action['more'] = True return action
def post(self, organization, member, repo, admin, team, team_member): name = request.form.get('name') user = get_user(name) if not user: return self.render_template( member=member, repo=repo, organization=organization, \ error=code.ACCOUNT_NO_SUCH_USER, \ admin=admin, team=team, team_member=team_member, \ ) if user.id == repo.uid: return self.render_template( member=member, repo=repo, organization=organization, \ error=code.REPOS_CANT_TRANSPORT_SELF, \ admin=admin, team=team, team_member=team_member, \ ) is_member = get_organization_member(organization.id, user.id) if not is_member: return self.render_template( member=member, repo=repo, organization=organization, \ error=code.ORGANIZATION_MEMBER_NOT_EXISTS, \ admin=admin, team=team, team_member=team_member, \ ) error = transport_repo(organization, user, repo, team) if error: return self.render_template( member=member, repo=repo, organization=organization, \ error=error, \ admin=admin, team=team, team_member=team_member, \ ) return redirect(repo.meta.transport)
def post(self, organization, member, repo, admin, team, team_member): name = request.form.get('name') user = get_user(name) if not user: return self.render_template( member=member, repo=repo, organization=organization, \ commiters = self.get_commiters(repo), \ error=code.ACCOUNT_NO_SUCH_USER, \ admin=admin, team=team, team_member=team_member, \ ) if user.id == repo.uid: return self.render_template( member=member, repo=repo, organization=organization, \ commiters = self.get_commiters(repo), \ error=code.REPOS_COMMITER_EXISTS, \ admin=admin, team=team, team_member=team_member, \ ) is_member = get_organization_member(organization.id, user.id) if not is_member: return self.render_template( member=member, repo=repo, organization=organization, \ commiters = self.get_commiters(repo), \ error=code.ORGANIZATION_MEMBER_NOT_EXISTS, \ admin=admin, team=team, team_member=team_member, \ ) create_commiter(user, repo, organization, team) return redirect(repo.meta.commiter)
def get(self, uid): if uid == g.current_user.id: return redirect(url_for('topic.index')) who = get_user(uid) if not who: raise abort(404) title = request.args.get('title', '') return render_template('topic.create.html', uid=uid, who=who, title=title)
def render_forks(self, organization, forks, team): for fork in forks: view_url = get_url(organization, fork, view='repos.view', team=team) setattr(fork, 'view', view_url) setattr(fork, 'user', get_user(fork.uid)) yield fork
def post(self, organization, member, repo, admin, team, team_member): name = request.form.get('name') user = get_user(name) if not user or user.id == repo.uid: return redirect(repo.meta.commiter) commiter = get_repo_commiter(user.id, repo.id) if user and commiter: delete_commiter(user, commiter, repo, organization, team) return redirect(repo.meta.commiter)
def format_reply_list(items): for item in items: reply = Obj() if item.who != g.current_user.id: reply.user = get_user(item.who) else: reply.user = g.current_user reply.content = item.content reply.time = item.time yield reply
def bind(self, body, message): '''绑定校门口账号, 格式为「-code TOKEN」或者是「bind TOKEN」''' user = get_uid(body) if not user: return "绑定失败,请检查验证码或者返回绑定页面刷新获取新的验证码。" u = get_user(user) if not u: return "绑定失败,请检查验证码或者返回绑定页面刷新获取新的验证码。" u.set_weixin(message.From) clear_user_cache(u) return "绑定成功!"
def format_topic_list(items): for item in items: t = get_topic(item.tid) if not t: #TODO have to log continue topic = Obj() topic.id = t.id topic.user = get_user(item.contact) topic.last_reply = get_reply(t.last_rid) topic.title = t.title topic.has_new = item.has_new yield topic
def post(self, uid): if uid == g.current_user.id: return redirect(url_for('topic.index')) who = get_user(uid) to_uid = request.form.get('to_uid') title = request.form.get('title') content = request.form.get('content') if not who: #TODO return error code # check other params return render_template('topic.create.html', uid=uid) topic = make_topic(g.current_user.id, to_uid, title, content) #clean cache clean_cache(g.current_user.id, uid, topic.id) return redirect(url_for('topic.index'))
def get_commit_user(self, meta): user = Obj() commit = Obj() user.name = meta['committer']['name'] user.email = meta['committer']['email'] user.avatar = None commit.message = meta['message'] commit.user = user commit.sha = meta['sha'] commit.date = meta['committer']['date'] alias = get_alias_by_email(user.email) if alias: user = get_user(alias.uid) commit.user.name = user.name commit.user.avatar = user.avatar(18) return commit
def post(self, stub): forget, error = get_forget_by_stub(stub=stub) if error: return self.render_template(error=error) if g.current_user: clear_forget(forget) return redirect(url_for('index')) password = request.form.get('password', None) if not check_password(password): return self.render_template(error=code.ACCOUNT_PASSWORD_INVAILD) user = get_user(forget.uid) error = update_account(user, _forget=forget, password=password) if error: return self.render_template(error=error) return redirect(url_for('account.login'))
def get(self, organization, member, **kwargs): f = request.args.get('f', None) if f not in ['w', 'm']: f = None else: f = 0 if f == 'w' else 1 tname = kwargs.pop('tname', None) team, team_member = self.get_team(organization, member, tname) users = None if team: members = get_team_members(team.id) users = (get_user(member.uid) for member in members) return self.render_template( organization = organization, \ member = member, \ team = team, \ team_member = team_member, \ repos = self.get_repos(organization, team, f), \ users = users, )
def get(self, organization, member, team, team_member): members = get_team_members(team.id) users = (get_user(member.uid) for member in members) page = request.args.get('p', 1) try: page = int(page) except ValueError: raise abort(403) data, list_page = render_activities_page(page, t='team', organization=organization, team=team) return self.render_template( organization=organization, \ team_member=team_member, \ team=team, member=member, \ users=users, \ data=self.render_activities(data, organization, team), \ list_page=list_page, \ )
def post(self, stub): forget = get_forget_by_stub(stub=stub) if g.current_user: if forget: forget.delete() return redirect(url_for('index')) if not forget: raise abort(404) password = request.form.get('password', None) status = check_password(password) if status: return render_template('account.reset.html', stub=stub, \ error=status[1]) user = get_user(forget.uid) user.change_password(password) account_login(user) forget.delete() clear_user_cache(user) backend.delete('account:%s' % forget.stub) return render_template('account.reset.html', ok=1)
def render_gist_action(action, organization): gist_key = 'gist:%d' % action['gist_id'] gist_url_key = 'gist:url:%d' % action['gist_id'] gist = cache.get(gist_key, None) or get_gist(action['gist_id']) gist_url = cache.get(gist_url_key, None) or get_gist_url(organization, gist) cache.set(gist_key, gist) cache.set(gist_url_key, gist_url) action['gist'] = gist action['gist_url'] = gist_url action['committer'] = cache.get(action['committer_id'], None) or get_user(action['committer_id']) action['commit_time'] = format_time(action['commit_time']) cache.set(action['committer_id'], action['committer']) for log in action['data']: author = cache.get(log['author_email'], False) if author is False: author = get_user_from_alias(log['author_email']) cache.set(log['author_email'], author) log['author'] = author log['author_time'] = format_time(log['author_time']) log['message'] = log['message'].decode('utf8') return action
def authorized(self, resp): csrf = session.pop('%s_oauthcsrf' % self.name, None) state = request.args.get('state') if state and urllib.unquote(state) != csrf: return redirect(url_for('index')) if not session: return redirect(url_for('index')) next_url = session.pop('%s_oauthnext' % self.name) or url_for('index') logger.info(resp) if not resp or not resp.get(self.uid_str, None) \ or not resp.get(self.token_str, None): return redirect(next_url) #safe escape #uid = resp.get(self.uid_str, None) token = resp.get(self.token_str, None) oauth = get_oauth_by(oauth_uid=resp[self.uid_str]) if oauth is None: oauth = create_oauth(None, resp[self.uid_str], self.name) old_token = oauth.oauth_token oauth.oauth_token = token if not g.current_user and oauth.uid: #need profile! user = get_user(oauth.uid) if user: account_login(user) if old_token != oauth.oauth_token: logger.info(old_token) logger.info(oauth.oauth_token) oauth.store() self.update_token(oauth) return redirect(url_for('index')) session['from_oauth'] = oauth return redirect(next_url)
def post(self, organization, member, team, team_member): name = request.form.get('name', None) admin = 1 if 'admin' in request.form else 0 user = get_user(name) if not user: return self.render_template( organization=organization, \ team_member=team_member, \ team=team, member=member, \ error=code.ACCOUNT_NO_SUCH_USER, \ ) is_member = get_organization_member(organization.id, user.id) if not is_member: return self.render_template( organization=organization, \ team_member=team_member, \ team=team, member=member, \ error=code.ORGANIZATION_MEMBER_NOT_EXISTS, \ ) create_team_members(organization, team, user, admin=admin) return redirect( url_for('organization.viewteam', git=organization.git, tname=team.name))
def get(self, username): visit_user = get_user(username) if not visit_user: raise abort(404) return render_template('account.people.html', \ visit_user = visit_user)
def people(uid): people = get_user(uid) if people: return dict(name=people.name, uid=people.id, domain=people.domain, avatar=people.avatar) return
def get_commiters(self, repo): commiters = get_repo_commiters(repo.id) commiters = (get_user(commiter.uid) for commiter in commiters) return commiters
def render_watchers(self, watchers): for watcher in watchers: setattr(watcher, 'user', get_user(watcher.uid)) yield watcher
def get_gists(self, organization, f=None): ret = self.filter_gists(organization, f) for r in ret: setattr(r, 'user', get_user(r.uid)) setattr(r, 'view', get_url(organization, r)) yield r
def render_forks(self, organization, forks): for fork in forks: view_url = get_url(organization, fork, 'gists.view') setattr(fork, 'view', view_url) setattr(fork, 'user', get_user(fork.uid)) yield fork