From a693771345aa9c1611d78b7657f31292b6956a7b Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Fri, 9 Mar 2018 13:55:19 -0500 Subject: [PATCH] Add creation date information to robots API and UI Fixes https://jira.coreos.com/browse/QUAY-846 --- data/model/user.py | 2 +- endpoints/api/robot_models_interface.py | 10 +++++++++- endpoints/api/robot_models_pre_oci.py | 18 ++++++++++-------- static/directives/robots-manager.html | 6 ++++++ static/js/directives/ui/robots-manager.js | 2 ++ 5 files changed, 28 insertions(+), 10 deletions(-) diff --git a/data/model/user.py b/data/model/user.py index 0c86b5a7b..59a15c9da 100644 --- a/data/model/user.py +++ b/data/model/user.py @@ -375,7 +375,7 @@ def _list_entity_robots(entity_name): def list_entity_robot_permission_teams(entity_name, include_permissions=False): query = (_list_entity_robots(entity_name)) - fields = [User.username, FederatedLogin.service_ident] + fields = [User.username, User.creation_date, FederatedLogin.service_ident] if include_permissions: query = (query .join(RepositoryPermission, JOIN_LEFT_OUTER, diff --git a/endpoints/api/robot_models_interface.py b/endpoints/api/robot_models_interface.py index 98b641663..f0ca57354 100644 --- a/endpoints/api/robot_models_interface.py +++ b/endpoints/api/robot_models_interface.py @@ -3,6 +3,8 @@ from collections import namedtuple from six import add_metaclass +from endpoints.api import format_date + class Permission(namedtuple('Permission', ['repository_name', 'repository_visibility_name', 'role_name'])): """ @@ -36,6 +38,7 @@ class RobotWithPermissions( namedtuple('RobotWithPermissions', [ 'name', 'password', + 'created', 'teams', 'repository_names', ])): @@ -43,6 +46,7 @@ class RobotWithPermissions( RobotWithPermissions is a list of robot entries. :type name: string :type password: string + :type created: datetime|None :type teams: [Team] :type repository_names: [string] @@ -52,6 +56,7 @@ class RobotWithPermissions( return { 'name': self.name, 'token': self.password, + 'created': format_date(self.created) if self.created is not None else None, 'teams': [team.to_dict() for team in self.teams], 'repositories': self.repository_names } @@ -61,18 +66,21 @@ class Robot( namedtuple('Robot', [ 'name', 'password', + 'created', ])): """ Robot represents a robot entity. :type name: string :type password: string + :type created: datetime|None """ def to_dict(self): return { 'name': self.name, - 'token': self.password + 'token': self.password, + 'created': format_date(self.created) if self.created is not None else None, } diff --git a/endpoints/api/robot_models_pre_oci.py b/endpoints/api/robot_models_pre_oci.py index abbd75a62..f325591ca 100644 --- a/endpoints/api/robot_models_pre_oci.py +++ b/endpoints/api/robot_models_pre_oci.py @@ -23,6 +23,7 @@ class RobotPreOCIModel(RobotInterface): robot_dict = { 'name': robot_name, 'token': robot_tuple.get(FederatedLogin.service_ident), + 'created': robot_tuple.get(User.creation_date), } if include_permissions: @@ -30,7 +31,7 @@ class RobotPreOCIModel(RobotInterface): 'teams': [], 'repositories': [] }) - robots[robot_name] = Robot(robot_dict['name'], robot_dict['token']) + robots[robot_name] = Robot(robot_dict['name'], robot_dict['token'], robot_dict['created']) if include_permissions: team_name = robot_tuple.get(TeamTable.name) repository_name = robot_tuple.get(Repository.name) @@ -48,40 +49,41 @@ class RobotPreOCIModel(RobotInterface): if repository_name is not None: if repository_name not in robot_dict['repositories']: robot_dict['repositories'].append(repository_name) - robots[robot_name] = RobotWithPermissions(robot_dict['name'], robot_dict['token'], robot_dict['teams'], + robots[robot_name] = RobotWithPermissions(robot_dict['name'], robot_dict['token'], + robot_dict['created'], robot_dict['teams'], robot_dict['repositories']) return robots.values() def regenerate_user_robot_token(self, robot_shortname, owning_user): robot, password = model.user.regenerate_robot_token(robot_shortname, owning_user) - return Robot(robot.username, password) + return Robot(robot.username, password, robot.creation_date) def regenerate_org_robot_token(self, robot_shortname, orgname): parent = model.organization.get_organization(orgname) robot, password = model.user.regenerate_robot_token(robot_shortname, parent) - return Robot(robot.username, password) + return Robot(robot.username, password, robot.creation_date) def delete_robot(self, robot_username): model.user.delete_robot(robot_username) def create_user_robot(self, robot_shortname, owning_user): robot, password = model.user.create_robot(robot_shortname, owning_user) - return Robot(robot.username, password) + return Robot(robot.username, password, robot.creation_date) def create_org_robot(self, robot_shortname, orgname): parent = model.organization.get_organization(orgname) robot, password = model.user.create_robot(robot_shortname, parent) - return Robot(robot.username, password) + return Robot(robot.username, password, robot.creation_date) def get_org_robot(self, robot_shortname, orgname): parent = model.organization.get_organization(orgname) robot, password = model.user.get_robot(robot_shortname, parent) - return Robot(robot.username, password) + return Robot(robot.username, password, robot.creation_date) def get_user_robot(self, robot_shortname, owning_user): robot, password = model.user.get_robot(robot_shortname, owning_user) - return Robot(robot.username, password) + return Robot(robot.username, password, robot.creation_date) pre_oci_model = RobotPreOCIModel() diff --git a/static/directives/robots-manager.html b/static/directives/robots-manager.html index 65908bd21..1890a3ed1 100644 --- a/static/directives/robots-manager.html +++ b/static/directives/robots-manager.html @@ -40,6 +40,9 @@ Teams Repositories + + Created + @@ -78,6 +81,9 @@ + + + diff --git a/static/js/directives/ui/robots-manager.js b/static/js/directives/ui/robots-manager.js index 67bf312ae..eca191984 100644 --- a/static/js/directives/ui/robots-manager.js +++ b/static/js/directives/ui/robots-manager.js @@ -39,6 +39,8 @@ angular.module('quay').directive('robotsManager', function () { robot['teams_string'] = robot.teams.map(function(team) { return team['name'] || ''; }).join(','); + + robot['created_datetime'] = robot.created ? TableService.getReversedTimestamp(robot.created) : null; }); $scope.orderedRobots = TableService.buildOrderedItems(robots, $scope.options,