Files
@ ffd45b185016
Branch filter:
Location: kallithea/rhodecode/controllers/admin/admin.py - annotation
ffd45b185016
5.2 KiB
text/x-python
Imported some of the GPLv3'd changes from RhodeCode v2.2.5.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3§14 and other relevant sections of GPLv3.
This imports changes between changesets 21af6c4eab3d and 6177597791c2 in
RhodeCode's original repository, including only changes to Python files and HTML.
RhodeCode clearly licensed its changes to these files under GPLv3
in their /LICENSE file, which states the following:
The Python code and integrated HTML are licensed under the GPLv3 license.
(See:
https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE
or
http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE
for an online copy of that LICENSE file)
Conservancy reviewed these changes and confirmed that they can be licensed as
a whole to the Kallithea project under GPLv3-only.
While some of the contents committed herein are clearly licensed
GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the
statement above from RhodeCode indicates that they intend GPLv3-only as their
license, per GPLv3§14 and other relevant sections of GPLv3.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | fb7a3b291e64 a671db5bdd58 a671db5bdd58 a671db5bdd58 a671db5bdd58 6832ef664673 1e757ac98988 1e757ac98988 1e757ac98988 1e757ac98988 6832ef664673 1e757ac98988 a671db5bdd58 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 ffd45b185016 fb7a3b291e64 1e757ac98988 8e49b6ceffe1 a08624dd675e 8e49b6ceffe1 a08624dd675e 13241a4075e9 a08624dd675e 86e087bd75ce 8e49b6ceffe1 13241a4075e9 8e49b6ceffe1 1e757ac98988 ca2b21819dfd a08624dd675e 13241a4075e9 a08624dd675e 1e757ac98988 1e757ac98988 1e757ac98988 5f2fbab7c429 cc7eedb5323c a08624dd675e a08624dd675e a08624dd675e a08624dd675e a08624dd675e a08624dd675e a08624dd675e ca2b21819dfd a08624dd675e a08624dd675e a08624dd675e cc7eedb5323c a08624dd675e ca2b21819dfd ca2b21819dfd ca2b21819dfd ca2b21819dfd ca2b21819dfd ca2b21819dfd 86e087bd75ce ca2b21819dfd ca2b21819dfd ca2b21819dfd ca2b21819dfd 86e087bd75ce a08624dd675e a08624dd675e ca2b21819dfd a08624dd675e a08624dd675e a08624dd675e a08624dd675e a08624dd675e a08624dd675e a08624dd675e ca2b21819dfd a08624dd675e a08624dd675e ca2b21819dfd a08624dd675e a08624dd675e a08624dd675e ca2b21819dfd a08624dd675e 86e087bd75ce cc7eedb5323c cc7eedb5323c 86e087bd75ce a08624dd675e cc7eedb5323c cc7eedb5323c a08624dd675e a08624dd675e a08624dd675e a08624dd675e cc7eedb5323c cc7eedb5323c a08624dd675e a08624dd675e a08624dd675e a08624dd675e a08624dd675e cc7eedb5323c cc7eedb5323c ca2b21819dfd a08624dd675e a08624dd675e a08624dd675e a08624dd675e a08624dd675e 1e757ac98988 fb7a3b291e64 1e757ac98988 1e757ac98988 1e757ac98988 fb7a3b291e64 fb7a3b291e64 1e757ac98988 91c442a489bb 8e49b6ceffe1 a08624dd675e a08624dd675e a08624dd675e a08624dd675e a08624dd675e cc7eedb5323c 10b4e34841a4 a08624dd675e a08624dd675e a08624dd675e a08624dd675e 8e49b6ceffe1 9d743ca9cede a08624dd675e a08624dd675e a08624dd675e a08624dd675e a08624dd675e 1e757ac98988 c6b811f11c94 c6b811f11c94 1e757ac98988 fb7a3b291e64 | # -*- coding: utf-8 -*-
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# 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 General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
rhodecode.controllers.admin.admin
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Controller for Admin panel of Rhodecode
:created_on: Apr 7, 2010
:author: marcink
:copyright: (c) 2013 RhodeCode GmbH.
:license: GPLv3, see LICENSE for more details.
"""
import logging
from pylons import request, tmpl_context as c, url
from sqlalchemy.orm import joinedload
from whoosh.qparser.default import QueryParser
from whoosh.qparser.dateparse import DateParserPlugin
from whoosh import query
from sqlalchemy.sql.expression import or_, and_, func
from rhodecode.model.db import UserLog, User
from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
from rhodecode.lib.base import BaseController, render
from rhodecode.lib.utils2 import safe_int, remove_prefix, remove_suffix
from rhodecode.lib.indexers import JOURNAL_SCHEMA
from rhodecode.lib.helpers import Page
log = logging.getLogger(__name__)
def _journal_filter(user_log, search_term):
"""
Filters sqlalchemy user_log based on search_term with whoosh Query language
http://packages.python.org/Whoosh/querylang.html
:param user_log:
:param search_term:
"""
log.debug('Initial search term: %r' % search_term)
qry = None
if search_term:
qp = QueryParser('repository', schema=JOURNAL_SCHEMA)
qp.add_plugin(DateParserPlugin())
qry = qp.parse(unicode(search_term))
log.debug('Filtering using parsed query %r' % qry)
def wildcard_handler(col, wc_term):
if wc_term.startswith('*') and not wc_term.endswith('*'):
#postfix == endswith
wc_term = remove_prefix(wc_term, prefix='*')
return func.lower(col).endswith(wc_term)
elif wc_term.startswith('*') and wc_term.endswith('*'):
#wildcard == ilike
wc_term = remove_prefix(wc_term, prefix='*')
wc_term = remove_suffix(wc_term, suffix='*')
return func.lower(col).contains(wc_term)
def get_filterion(field, val, term):
if field == 'repository':
field = getattr(UserLog, 'repository_name')
elif field == 'ip':
field = getattr(UserLog, 'user_ip')
elif field == 'date':
field = getattr(UserLog, 'action_date')
elif field == 'username':
field = getattr(UserLog, 'username')
else:
field = getattr(UserLog, field)
log.debug('filter field: %s val=>%s' % (field, val))
#sql filtering
if isinstance(term, query.Wildcard):
return wildcard_handler(field, val)
elif isinstance(term, query.Prefix):
return func.lower(field).startswith(func.lower(val))
elif isinstance(term, query.DateRange):
return and_(field >= val[0], field <= val[1])
return func.lower(field) == func.lower(val)
if isinstance(qry, (query.And, query.Term, query.Prefix, query.Wildcard,
query.DateRange)):
if not isinstance(qry, query.And):
qry = [qry]
for term in qry:
field = term.fieldname
val = (term.text if not isinstance(term, query.DateRange)
else [term.startdate, term.enddate])
user_log = user_log.filter(get_filterion(field, val, term))
elif isinstance(qry, query.Or):
filters = []
for term in qry:
field = term.fieldname
val = (term.text if not isinstance(term, query.DateRange)
else [term.startdate, term.enddate])
filters.append(get_filterion(field, val, term))
user_log = user_log.filter(or_(*filters))
return user_log
class AdminController(BaseController):
@LoginRequired()
def __before__(self):
super(AdminController, self).__before__()
@HasPermissionAllDecorator('hg.admin')
def index(self):
users_log = UserLog.query()\
.options(joinedload(UserLog.user))\
.options(joinedload(UserLog.repository))
#FILTERING
c.search_term = request.GET.get('filter')
try:
users_log = _journal_filter(users_log, c.search_term)
except Exception:
# we want this to crash for now
raise
users_log = users_log.order_by(UserLog.action_date.desc())
p = safe_int(request.GET.get('page', 1), 1)
def url_generator(**kw):
return url.current(filter=c.search_term, **kw)
c.users_log = Page(users_log, page=p, items_per_page=10, url=url_generator)
c.log_data = render('admin/admin_log.html')
if request.environ.get('HTTP_X_PARTIAL_XHR'):
return c.log_data
return render('admin/admin.html')
|