##// END OF EJS Templates
admin-users: use full ilike search on filtering
admin-users: use full ilike search on filtering

File last commit:

r1507:a630e423 default
r1521:6db2b5b9 default
Show More
views.py
120 lines | 4.1 KiB | text/x-python | PythonLexer
my-account-auth-tokens: moved into pyramid apps....
r1505 # -*- coding: utf-8 -*-
# Copyright (C) 2016-2017 RhodeCode GmbH
#
# 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
from pyramid.httpexceptions import HTTPFound
from pyramid.view import view_config
from rhodecode.apps._base import BaseAppView
from rhodecode.lib.auth import LoginRequired, NotAnonymous, CSRFRequired
from rhodecode.lib.utils2 import safe_int
from rhodecode.lib import helpers as h
from rhodecode.model.auth_token import AuthTokenModel
from rhodecode.model.meta import Session
log = logging.getLogger(__name__)
class MyAccountView(BaseAppView):
auth-tokens: extended views to allowed override of adding scope in EE edition.
r1507 ALLOW_SCOPED_TOKENS = False
"""
This view has alternative version inside EE, if modified please take a look
in there as well.
"""
my-account-auth-tokens: moved into pyramid apps....
r1505
def load_default_context(self):
c = self._get_local_tmpl_context()
c.auth_user = self.request.user
c.user = c.auth_user.get_instance()
auth-tokens: extended views to allowed override of adding scope in EE edition.
r1507 c.allow_scoped_tokens = self.ALLOW_SCOPED_TOKENS
my-account-auth-tokens: moved into pyramid apps....
r1505 self._register_global_c(c)
return c
@LoginRequired()
@NotAnonymous()
@view_config(
route_name='my_account_auth_tokens', request_method='GET',
renderer='rhodecode:templates/admin/my_account/my_account.mako')
def my_account_auth_tokens(self):
_ = self.request.translate
c = self.load_default_context()
c.active = 'auth_tokens'
c.lifetime_values = [
(str(-1), _('forever')),
(str(5), _('5 minutes')),
(str(60), _('1 hour')),
(str(60 * 24), _('1 day')),
(str(60 * 24 * 30), _('1 month')),
]
c.lifetime_options = [(c.lifetime_values, _("Lifetime"))]
c.role_values = [
(x, AuthTokenModel.cls._get_role_name(x))
for x in AuthTokenModel.cls.ROLES]
c.role_options = [(c.role_values, _("Role"))]
c.user_auth_tokens = AuthTokenModel().get_auth_tokens(
auth-tokens: extended views to allowed override of adding scope in EE edition.
r1507 c.user.user_id, show_expired=True)
my-account-auth-tokens: moved into pyramid apps....
r1505 return self._get_template_context(c)
auth-tokens: extended views to allowed override of adding scope in EE edition.
r1507 def maybe_attach_token_scope(self, token):
# implemented in EE edition
pass
my-account-auth-tokens: moved into pyramid apps....
r1505 @LoginRequired()
@NotAnonymous()
@CSRFRequired()
@view_config(
route_name='my_account_auth_tokens_add', request_method='POST')
def my_account_auth_tokens_add(self):
_ = self.request.translate
c = self.load_default_context()
lifetime = safe_int(self.request.POST.get('lifetime'), -1)
description = self.request.POST.get('description')
role = self.request.POST.get('role')
auth-tokens: extended views to allowed override of adding scope in EE edition.
r1507 token = AuthTokenModel().create(
c.user.user_id, description, lifetime, role)
self.maybe_attach_token_scope(token)
my-account-auth-tokens: moved into pyramid apps....
r1505 Session().commit()
auth-tokens: extended views to allowed override of adding scope in EE edition.
r1507
my-account-auth-tokens: moved into pyramid apps....
r1505 h.flash(_("Auth token successfully created"), category='success')
return HTTPFound(h.route_path('my_account_auth_tokens'))
@LoginRequired()
@NotAnonymous()
@CSRFRequired()
@view_config(
route_name='my_account_auth_tokens_delete', request_method='POST')
def my_account_auth_tokens_delete(self):
_ = self.request.translate
c = self.load_default_context()
del_auth_token = self.request.POST.get('del_auth_token')
if del_auth_token:
AuthTokenModel().delete(del_auth_token, c.user.user_id)
Session().commit()
h.flash(_("Auth token successfully deleted"), category='success')
return HTTPFound(h.route_path('my_account_auth_tokens'))