diff --git a/pagure/ui/repo.py b/pagure/ui/repo.py index 5a17114..52fd809 100644 --- a/pagure/ui/repo.py +++ b/pagure/ui/repo.py @@ -39,7 +39,7 @@ import pagure.forms import pagure import pagure.ui.plugins from pagure import (APP, SESSION, LOG, __get_file_in_tree, login_required, - is_repo_admin, admin_session_timedout) + is_repo_admin, admin_session_timedout, authenticated) # pylint: disable=E1101 @@ -130,6 +130,10 @@ def view_repo(repo, username=None): break diff_commits.append(commit.oid.hex) + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'repo_info.html', select='overview', @@ -147,7 +151,7 @@ def view_repo(repo, username=None): diff_commits=diff_commits, repo_admin=is_repo_admin(repo), form=pagure.forms.ConfirmationForm(), - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -232,6 +236,10 @@ def view_repo_branch(repo, branchname, username=None): 'view_raw_file', username=username, repo=repo.name, identifier=branchname, filename='')) + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'repo_info.html', select='overview', @@ -248,7 +256,7 @@ def view_repo_branch(repo, branchname, username=None): diff_commits=diff_commits, repo_admin=is_repo_admin(repo), form=pagure.forms.ConfirmationForm(), - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -345,6 +353,10 @@ def view_commits(repo, branchname=None, username=None): diff_commits.append(commit.oid.hex) diff_commits_full.append(commit) + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'commits.html', select='commits', @@ -363,7 +375,7 @@ def view_commits(repo, branchname=None, username=None): total_page=total_page, repo_admin=is_repo_admin(repo), form=pagure.forms.ConfirmationForm(), - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -461,6 +473,10 @@ def view_file(repo, identifier, filename, username=None): if encoding: headers['Content-Encoding'] = encoding + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return ( flask.render_template( 'file.html', @@ -474,7 +490,7 @@ def view_file(repo, identifier, filename, username=None): content=content, output_type=output_type, repo_admin=is_repo_admin(repo), - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ), 200, headers @@ -626,6 +642,10 @@ def view_commit(repo, commitid, username=None): # First commit in the repo diff = commit.tree.diff_to_tree(swap=True) + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'commit.html', select='commits', @@ -636,7 +656,7 @@ def view_commit(repo, commitid, username=None): commitid=commitid, commit=commit, diff=diff, - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -712,6 +732,10 @@ def view_tree(repo, identifier=None, username=None): content = sorted(commit.tree, key=lambda x: x.filemode) output_type = 'tree' + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'file.html', select='tree', @@ -725,7 +749,7 @@ def view_tree(repo, identifier=None, username=None): content=content, output_type=output_type, repo_admin=is_repo_admin(repo), - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -741,13 +765,17 @@ def view_forks(repo, username=None): if not repo: flask.abort(404, 'Project not found') + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'forks.html', select='forks', username=username, repo=repo, repo_admin=is_repo_admin(repo), - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -767,6 +795,11 @@ def view_tags(repo, username=None): repo_obj = pygit2.Repository(reponame) tags = pagure.lib.git.get_git_tags_objects(repo) + + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'releases.html', select='tags', @@ -775,7 +808,7 @@ def view_tags(repo, username=None): tags=tags, repo_admin=is_repo_admin(repo), repo_obj=repo_obj, - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -820,13 +853,17 @@ def new_release(repo, username=None): return flask.redirect( flask.url_for('view_tags', repo=repo.name, username=username)) + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'new_release.html', select='tags', username=username, repo=repo, form=form, - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -900,6 +937,10 @@ def view_settings(repo, username=None): if flask.request.method == 'GET' and branchname: branches_form.branches.data = branchname + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'settings.html', select='settings', @@ -913,7 +954,7 @@ def view_settings(repo, username=None): plugins=plugins, repo_admin=repo_admin, branchname = branchname, - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -1388,11 +1429,16 @@ def add_user(repo, username=None): APP.logger.exception(err) flask.flash('User could not be added', 'error') + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'add_user.html', form=form, username=username, repo=repo, + watch=watch, ) @@ -1505,12 +1551,16 @@ def add_group_project(repo, username=None): APP.logger.exception(err) flask.flash('Group could not be added', 'error') + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'add_group_project.html', form=form, username=username, repo=repo, - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -1609,6 +1659,10 @@ def add_token(repo, username=None): APP.logger.exception(err) flask.flash('User could not be added', 'error') + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'add_token.html', select='settings', @@ -1617,7 +1671,7 @@ def add_token(repo, username=None): repo_admin=repo_admin, username=username, repo=repo, - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -1749,6 +1803,10 @@ def edit_file(repo, branchname, filename, username=None): else: data = form.content.data.decode('utf-8') + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'edit_file.html', select='tree', @@ -1760,7 +1818,7 @@ def edit_file(repo, branchname, filename, username=None): form=form, user=user, branches=repo_obj.listall_branches(), - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo), + watch=watch, ) @@ -1817,6 +1875,10 @@ def view_docs(repo, username=None, filename=None): if not APP.config.get('DOC_APP_URL'): flask.abort(404, 'This pagure instance has no doc server') + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'docs.html', select='docs', @@ -1824,9 +1886,10 @@ def view_docs(repo, username=None, filename=None): username=username, filename=filename, endpoint='view_docs', - watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo_obj), + watch=watch2, ) + @APP.route('//activity/') @APP.route('//activity') def view_project_activity(repo): @@ -1841,11 +1904,17 @@ def view_project_activity(repo): if not repo_obj: flask.abort(404, 'Project not found') + watch = False + if authenticated(): + watch=pagure.lib.is_watching(SESSION, flask.g.fas_user, repo) + return flask.render_template( 'activity.html', repo=repo_obj, + watch=watch, ) + @APP.route('/watch//settings/', methods=['POST']) @APP.route('/watch/fork///settings/', methods=['POST']) @login_required