##// END OF EJS Templates
file-store: expose additional headers, and content-disposiztion for nicer downloads
file-store: expose additional headers, and content-disposiztion for nicer downloads

File last commit:

r4306:09801de9 default
r4609:a3bacd67 stable
Show More
repo_settings_issue_trackers.py
139 lines | 5.0 KiB | text/x-python | PythonLexer
/ rhodecode / apps / repository / views / repo_settings_issue_trackers.py
repositories: rewrote whole admin section to pyramid....
r2014 # -*- coding: utf-8 -*-
code: update copyrights to 2020
r4306 # Copyright (C) 2017-2020 RhodeCode GmbH
repositories: rewrote whole admin section to pyramid....
r2014 #
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License, version 3
# (only), as published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# This program is dual-licensed. If you wish to learn more about the
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import logging
dan
issue-tracker: moved example to the input box...
r4111 from pyramid.httpexceptions import HTTPFound, HTTPNotFound
repositories: rewrote whole admin section to pyramid....
r2014 from pyramid.view import view_config
issue-trackers: enforce a http or / patterns to avoid JS injections.
r2334 import formencode
repositories: rewrote whole admin section to pyramid....
r2014
from rhodecode.apps._base import RepoAppView
from rhodecode.lib import audit_logger
from rhodecode.lib import helpers as h
from rhodecode.lib.auth import (
LoginRequired, HasRepoPermissionAnyDecorator, CSRFRequired)
from rhodecode.model.forms import IssueTrackerPatternsForm
from rhodecode.model.meta import Session
issue-tracker: use stored issueTracker patterns for repo instead of initializing model every time.
r4201 from rhodecode.model.settings import SettingsModel
repositories: rewrote whole admin section to pyramid....
r2014
log = logging.getLogger(__name__)
class RepoSettingsIssueTrackersView(RepoAppView):
def load_default_context(self):
c = self._get_local_tmpl_context()
pylons: remove pylons as dependency...
r2351
repositories: rewrote whole admin section to pyramid....
r2014 return c
@LoginRequired()
@HasRepoPermissionAnyDecorator('repository.admin')
@view_config(
route_name='edit_repo_issuetracker', request_method='GET',
renderer='rhodecode:templates/admin/repos/repo_edit.mako')
def repo_issuetracker(self):
c = self.load_default_context()
c.active = 'issuetracker'
c.data = 'data'
issue-tracker: use stored issueTracker patterns for repo instead of initializing model every time.
r4201 c.settings_model = self.db_repo_patterns
repositories: rewrote whole admin section to pyramid....
r2014 c.global_patterns = c.settings_model.get_global_settings()
c.repo_patterns = c.settings_model.get_repo_settings()
return self._get_template_context(c)
@LoginRequired()
@HasRepoPermissionAnyDecorator('repository.admin')
@CSRFRequired()
@view_config(
route_name='edit_repo_issuetracker_test', request_method='POST',
dan
issue-tracker: moved example to the input box...
r4111 renderer='string', xhr=True)
repositories: rewrote whole admin section to pyramid....
r2014 def repo_issuetracker_test(self):
return h.urlify_commit_message(
self.request.POST.get('test_text', ''),
self.db_repo_name)
@LoginRequired()
@HasRepoPermissionAnyDecorator('repository.admin')
@CSRFRequired()
@view_config(
route_name='edit_repo_issuetracker_delete', request_method='POST',
dan
issue-tracker: moved example to the input box...
r4111 renderer='json_ext', xhr=True)
repositories: rewrote whole admin section to pyramid....
r2014 def repo_issuetracker_delete(self):
_ = self.request.translate
uid = self.request.POST.get('uid')
issue-tracker: use stored issueTracker patterns for repo instead of initializing model every time.
r4201 repo_settings = self.db_repo_patterns
repositories: rewrote whole admin section to pyramid....
r2014 try:
repo_settings.delete_entries(uid)
except Exception:
h.flash(_('Error occurred during deleting issue tracker entry'),
category='error')
dan
issue-tracker: moved example to the input box...
r4111 raise HTTPNotFound()
SettingsModel().invalidate_settings_cache()
h.flash(_('Removed issue tracker entry.'), category='success')
return {'deleted': uid}
repositories: rewrote whole admin section to pyramid....
r2014
def _update_patterns(self, form, repo_settings):
for uid in form['delete_patterns']:
repo_settings.delete_entries(uid)
for pattern_data in form['patterns']:
for setting_key, pattern, type_ in pattern_data:
sett = repo_settings.create_or_update_setting(
setting_key, pattern.strip(), type_)
Session().add(sett)
Session().commit()
@LoginRequired()
@HasRepoPermissionAnyDecorator('repository.admin')
@CSRFRequired()
@view_config(
route_name='edit_repo_issuetracker_update', request_method='POST',
renderer='rhodecode:templates/admin/repos/repo_edit.mako')
def repo_issuetracker_update(self):
_ = self.request.translate
# Save inheritance
issue-tracker: use stored issueTracker patterns for repo instead of initializing model every time.
r4201 repo_settings = self.db_repo_patterns
repositories: rewrote whole admin section to pyramid....
r2014 inherited = (
self.request.POST.get('inherit_global_issuetracker') == "inherited")
repo_settings.inherit_global_settings = inherited
Session().commit()
issue-trackers: enforce a http or / patterns to avoid JS injections.
r2334 try:
pylons: remove pylons as dependency...
r2351 form = IssueTrackerPatternsForm(self.request.translate)().to_python(self.request.POST)
issue-trackers: enforce a http or / patterns to avoid JS injections.
r2334 except formencode.Invalid as errors:
log.exception('Failed to add new pattern')
error = errors
h.flash(_('Invalid issue tracker pattern: {}'.format(error)),
category='error')
raise HTTPFound(
h.route_path('edit_repo_issuetracker',
repo_name=self.db_repo_name))
repositories: rewrote whole admin section to pyramid....
r2014 if form:
self._update_patterns(form, repo_settings)
h.flash(_('Updated issue tracker entries'), category='success')
raise HTTPFound(
h.route_path('edit_repo_issuetracker', repo_name=self.db_repo_name))