From 5fc8e632d6563e108460d0e84106afc21b3dce43 Mon Sep 17 00:00:00 2001 From: Joseph Schorr Date: Wed, 1 Apr 2015 14:23:39 -0400 Subject: [PATCH] Redo the permissions table to have different sections for users and robot accounts --- endpoints/api/permission.py | 2 + .../repository-permissions-table.html | 59 ++++++++++++++++--- .../ui/repository-permissions-table.js | 51 ++++++++++++++-- 3 files changed, 100 insertions(+), 12 deletions(-) diff --git a/endpoints/api/permission.py b/endpoints/api/permission.py index 819786c07..4c0b62074 100644 --- a/endpoints/api/permission.py +++ b/endpoints/api/permission.py @@ -17,6 +17,7 @@ def role_view(repo_perm_obj): } def wrap_role_view_user(role_json, user): + role_json['name'] = user.username role_json['is_robot'] = user.robot if not user.robot: role_json['avatar'] = avatar.get_data_for_user(user) @@ -29,6 +30,7 @@ def wrap_role_view_org(role_json, user, org_members): def wrap_role_view_team(role_json, team): + role_json['name'] = team.name role_json['avatar'] = avatar.get_data_for_team(team) return role_json diff --git a/static/directives/repository-permissions-table.html b/static/directives/repository-permissions-table.html index 4e008be03..79e483f7e 100644 --- a/static/directives/repository-permissions-table.html +++ b/static/directives/repository-permissions-table.html @@ -11,14 +11,26 @@ + + +
+
No permissions found.
+
+ To add a permission, enter the information below and click "Add Permission". +
+
+ + + - + Team Permissions @@ -36,13 +48,15 @@ - - User and Robot Account Permissions + + User Permissions - +
- +
- + + Delete Permission + + + + + + + + Robot Account Permissions + + + + + + + +
+ +
+ + + + Delete Permission diff --git a/static/js/directives/ui/repository-permissions-table.js b/static/js/directives/ui/repository-permissions-table.js index 519d12fd7..dd7b3417e 100644 --- a/static/js/directives/ui/repository-permissions-table.js +++ b/static/js/directives/ui/repository-permissions-table.js @@ -2,6 +2,21 @@ * An element which displays a table of permissions on a repository and allows them to be * edited. */ +angular.module('quay').filter('objectFilter', function() { + return function(obj, filterFn) { + if (!obj) { return []; } + + var result = []; + angular.forEach(obj, function(value) { + if (filterFn(value)) { + result.push(value); + } + }); + + return result; + }; +}); + angular.module('quay').directive('repositoryPermissionsTable', function () { var directiveDefinitionObject = { priority: 0, @@ -59,22 +74,50 @@ angular.module('quay').directive('repositoryPermissionsTable', function () { return Restangular.one(url); }; - $scope.buildEntityForPermission = function(name, permission, kind) { - var key = name + ':' + kind; + $scope.buildEntityForPermission = function(permission, kind) { + var key = permission.name + ':' + kind; if ($scope.permissionCache[key]) { return $scope.permissionCache[key]; } return $scope.permissionCache[key] = { 'kind': kind, - 'name': name, + 'name': permission.name, 'is_robot': permission.is_robot, 'is_org_member': permission.is_org_member, 'avatar': permission.avatar }; }; - $scope.addPermission = function() { + $scope.hasPermissions = function(teams, users) { + if (teams && teams.value) { + if (Object.keys(teams.value).length > 0) { + return true; + } + } + + if (users && users.value) { + if (Object.keys(users.value).length > 0) { + return true; + } + } + + return false; + }; + + $scope.allEntries = function() { + return true; + }; + + $scope.onlyRobot = function(permission) { + return permission.is_robot == true; + }; + + $scope.onlyUser = function(permission) { + return !permission.is_robot; + }; + + $scope.addPermission = function() { $scope.addPermissionInfo['working'] = true; $scope.addNewPermission($scope.addPermissionInfo.entity, $scope.addPermissionInfo.role) };