Show More
@@ -22,10 +22,12 b'' | |||
|
22 | 22 | import logging |
|
23 | 23 | |
|
24 | 24 | from rhodecode.api import jsonrpc_method |
|
25 | from rhodecode.api.exc import JSONRPCValidationError | |
|
26 | from rhodecode.api.utils import Optional | |
|
25 | from rhodecode.api.exc import JSONRPCValidationError, JSONRPCForbidden | |
|
26 | from rhodecode.api.utils import Optional, has_superadmin_permission | |
|
27 | 27 | from rhodecode.lib.index import searcher_from_config |
|
28 | from rhodecode.lib.user_log_filter import user_log_filter | |
|
28 | 29 | from rhodecode.model import validation_schema |
|
30 | from rhodecode.model.db import joinedload, UserLog | |
|
29 | 31 | from rhodecode.model.validation_schema.schemas import search_schema |
|
30 | 32 | |
|
31 | 33 | log = logging.getLogger(__name__) |
@@ -116,3 +118,35 b' def search(request, apiuser, search_quer' | |||
|
116 | 118 | colander_exc=validation_schema.Invalid(node, search_result['error'])) |
|
117 | 119 | |
|
118 | 120 | return data |
|
121 | ||
|
122 | ||
|
123 | @jsonrpc_method() | |
|
124 | def get_audit_logs(request, apiuser, query): | |
|
125 | """ | |
|
126 | return full audit logs based on the query. | |
|
127 | ||
|
128 | Please see `example query in admin > settings > audit logs` for examples | |
|
129 | ||
|
130 | :param apiuser: This is filled automatically from the |authtoken|. | |
|
131 | :type apiuser: AuthUser | |
|
132 | :param query: filter query, example: action:repo.artifact.add date:[20200401 TO 20200601]" | |
|
133 | :type query: str | |
|
134 | """ | |
|
135 | ||
|
136 | if not has_superadmin_permission(apiuser): | |
|
137 | raise JSONRPCForbidden() | |
|
138 | ||
|
139 | filter_term = query | |
|
140 | ret = [] | |
|
141 | ||
|
142 | # show all user actions | |
|
143 | user_log = UserLog.query() \ | |
|
144 | .options(joinedload(UserLog.user)) \ | |
|
145 | .options(joinedload(UserLog.repository)) \ | |
|
146 | .order_by(UserLog.action_date.desc()) | |
|
147 | ||
|
148 | audit_log = user_log_filter(user_log, filter_term) | |
|
149 | ||
|
150 | for entry in audit_log: | |
|
151 | ret.append(entry) | |
|
152 | return ret |
General Comments 0
You need to be logged in to leave comments.
Login now