##// END OF EJS Templates
user-api: enable per-user audit logs fetching via API endpoint.
marcink -
r1579:bcde1932 default
parent child Browse files
Show More
@@ -29,7 +29,6 b' from rhodecode.lib.utils2 import safe_in'
29 from rhodecode.model.db import Session, User, Repository
29 from rhodecode.model.db import Session, User, Repository
30 from rhodecode.model.user import UserModel
30 from rhodecode.model.user import UserModel
31
31
32
33 log = logging.getLogger(__name__)
32 log = logging.getLogger(__name__)
34
33
35
34
@@ -471,3 +470,45 b' def get_user_locks(request, apiuser, use'
471 ret.append(_api_data)
470 ret.append(_api_data)
472
471
473 return ret
472 return ret
473
474
475 @jsonrpc_method()
476 def get_user_audit_logs(request, apiuser, userid=Optional(OAttr('apiuser'))):
477 """
478 Fetches all action logs made by the specified user.
479
480 This command takes the following options:
481
482 :param apiuser: This is filled automatically from the |authtoken|.
483 :type apiuser: AuthUser
484 :param userid: Sets the userid whose list of locked |repos| will be
485 displayed.
486 :type userid: Optional(str or int)
487
488 Example output:
489
490 .. code-block:: bash
491
492 id : <id_given_in_input>
493 result : {
494 [action, action,...]
495 }
496 error : null
497 """
498
499 if not has_superadmin_permission(apiuser):
500 # make sure normal user does not pass someone else userid,
501 # he is not allowed to do that
502 if not isinstance(userid, Optional) and userid != apiuser.user_id:
503 raise JSONRPCError('userid is not the same as your user')
504
505 userid = Optional.extract(userid, evaluate_locals=locals())
506 userid = getattr(userid, 'user_id', userid)
507 user = get_user_or_error(userid)
508
509 ret = []
510
511 # show all user actions
512 for entry in UserModel().get_user_log(user, filter_term=None):
513 ret.append(entry)
514 return ret
@@ -1108,9 +1108,19 b' class UserLog(Base, BaseModel):'
1108 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
1108 action_date = Column("action_date", DateTime(timezone=False), nullable=True, unique=None, default=None)
1109
1109
1110 def __unicode__(self):
1110 def __unicode__(self):
1111 return u"<%s('id:%s:%s')>" % (self.__class__.__name__,
1111 return u"<%s('id:%s:%s')>" % (
1112 self.repository_name,
1112 self.__class__.__name__, self.repository_name, self.action)
1113 self.action)
1113
1114 def __json__(self):
1115 return {
1116 'user_id': self.user_id,
1117 'username': self.username,
1118 'repository_id': self.repository_id,
1119 'repository_name': self.repository_name,
1120 'user_ip': self.user_ip,
1121 'action_date': self.action_date,
1122 'action': self.action,
1123 }
1114
1124
1115 @property
1125 @property
1116 def action_as_day(self):
1126 def action_as_day(self):
General Comments 0
You need to be logged in to leave comments. Login now