Merge branch 'master' of https://bitbucket.org/yackob03/quay
This commit is contained in:
commit
d41f651a38
11 changed files with 241 additions and 51 deletions
172
static/js/app.js
172
static/js/app.js
|
@ -1,3 +1,6 @@
|
|||
var TEAM_PATTERN = '^[a-zA-Z][a-zA-Z0-9]+$';
|
||||
var ROBOT_PATTERN = '^[a-zA-Z][a-zA-Z0-9]+$';
|
||||
|
||||
function getFirstTextLine(commentString) {
|
||||
if (!commentString) { return ''; }
|
||||
|
||||
|
@ -31,6 +34,45 @@ function getFirstTextLine(commentString) {
|
|||
return '';
|
||||
}
|
||||
|
||||
function createRobotAccount(Restangular, is_org, orgname, name, callback) {
|
||||
var url = is_org ? getRestUrl('organization', orgname, 'robots', name) :
|
||||
getRestUrl('user/robots', name);
|
||||
var createRobot = Restangular.one(url);
|
||||
createRobot.customPUT().then(callback, function(resp) {
|
||||
bootbox.dialog({
|
||||
"message": resp.data ? resp.data : 'The robot account could not be created',
|
||||
"title": "Cannot create robot account",
|
||||
"buttons": {
|
||||
"close": {
|
||||
"label": "Close",
|
||||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function createOrganizationTeam(Restangular, orgname, teamname, callback) {
|
||||
var createTeam = Restangular.one(getRestUrl('organization', orgname, 'team', teamname));
|
||||
var data = {
|
||||
'name': teamname,
|
||||
'role': 'member'
|
||||
};
|
||||
|
||||
createTeam.customPOST(data).then(callback, function() {
|
||||
bootbox.dialog({
|
||||
"message": resp.data ? resp.data : 'The team could not be created',
|
||||
"title": "Cannot create team",
|
||||
"buttons": {
|
||||
"close": {
|
||||
"label": "Close",
|
||||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function getRestUrl(args) {
|
||||
var url = '';
|
||||
for (var i = 0; i < arguments.length; ++i) {
|
||||
|
@ -95,6 +137,19 @@ quayApp = angular.module('quay', ['ngRoute', 'restangular', 'angularMoment', 'an
|
|||
return null;
|
||||
};
|
||||
|
||||
userService.isNamespaceAdmin = function(namespace) {
|
||||
if (namespace == userResponse.username) {
|
||||
return true;
|
||||
}
|
||||
|
||||
var org = userService.getOrganization(namespace);
|
||||
if (!org) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return org.is_org_admin;
|
||||
};
|
||||
|
||||
userService.currentUser = function() {
|
||||
return userResponse;
|
||||
};
|
||||
|
@ -476,7 +531,11 @@ quayApp.directive('entityReference', function () {
|
|||
'team': '=team',
|
||||
'isrobot': '=isrobot'
|
||||
},
|
||||
controller: function($scope, $element) {
|
||||
controller: function($scope, $element, UserService) {
|
||||
$scope.getIsAdmin = function(orgname) {
|
||||
return UserService.isNamespaceAdmin(orgname);
|
||||
};
|
||||
|
||||
$scope.getPrefix = function(name) {
|
||||
if (!name) { return ''; }
|
||||
var plus = name.indexOf('+');
|
||||
|
@ -952,6 +1011,7 @@ quayApp.directive('robotsManager', function () {
|
|||
'user': '=user'
|
||||
},
|
||||
controller: function($scope, $element, Restangular) {
|
||||
$scope.ROBOT_PATTERN = ROBOT_PATTERN;
|
||||
$scope.robots = null;
|
||||
$scope.loading = false;
|
||||
$scope.shownRobot = null;
|
||||
|
@ -975,23 +1035,10 @@ quayApp.directive('robotsManager', function () {
|
|||
$scope.createRobot = function(name) {
|
||||
if (!name) { return; }
|
||||
|
||||
var url = $scope.organization ? getRestUrl('organization', $scope.organization.name, 'robots', name) :
|
||||
getRestUrl('user/robots', name);
|
||||
var createRobot = Restangular.one(url);
|
||||
createRobot.customPUT().then(function(resp) {
|
||||
$scope.robots.push(resp);
|
||||
}, function(resp) {
|
||||
bootbox.dialog({
|
||||
"message": resp.data ? resp.data : 'The robot account could not be created',
|
||||
"title": "Cannot create robot account",
|
||||
"buttons": {
|
||||
"close": {
|
||||
"label": "Close",
|
||||
"className": "btn-primary"
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
createRobotAccount(Restangular, !!$scope.organization, $scope.organization ? $scope.organization.name : '', name,
|
||||
function(created) {
|
||||
$scope.robots.push(created);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.deleteRobot = function(info) {
|
||||
|
@ -1265,14 +1312,93 @@ quayApp.directive('entitySearch', function () {
|
|||
'namespace': '=namespace',
|
||||
'inputTitle': '=inputTitle',
|
||||
'entitySelected': '=entitySelected',
|
||||
'includeTeams': '=includeTeams'
|
||||
'includeTeams': '=includeTeams',
|
||||
'isOrganization': '=isOrganization'
|
||||
},
|
||||
controller: function($scope, $element) {
|
||||
controller: function($scope, $element, Restangular, UserService) {
|
||||
$scope.lazyLoading = true;
|
||||
$scope.isAdmin = false;
|
||||
|
||||
$scope.lazyLoad = function() {
|
||||
if (!$scope.namespace || !$scope.lazyLoading) { return; }
|
||||
|
||||
$scope.isAdmin = UserService.isNamespaceAdmin($scope.namespace);
|
||||
|
||||
if ($scope.isOrganization && $scope.includeTeams) {
|
||||
var url = getRestUrl('organization', $scope.namespace);
|
||||
var getOrganization = Restangular.one(url);
|
||||
getOrganization.customGET().then(function(resp) {
|
||||
$scope.teams = resp.teams;
|
||||
});
|
||||
}
|
||||
|
||||
var url = $scope.isOrganization ? getRestUrl('organization', $scope.namespace, 'robots') : 'user/robots';
|
||||
var getRobots = Restangular.one(url);
|
||||
getRobots.customGET().then(function(resp) {
|
||||
$scope.robots = resp.robots;
|
||||
$scope.lazyLoading = false;
|
||||
}, function() {
|
||||
$scope.lazyLoading = false;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.createTeam = function() {
|
||||
if (!$scope.isAdmin) { return; }
|
||||
|
||||
bootbox.prompt('Enter the name of the new team', function(teamname) {
|
||||
if (!teamname) { return; }
|
||||
|
||||
var regex = new RegExp(TEAM_PATTERN);
|
||||
if (!regex.test(teamname)) {
|
||||
bootbox.alert('Invalid team name');
|
||||
return;
|
||||
}
|
||||
|
||||
createOrganizationTeam(Restangular, $scope.namespace, teamname, function(created) {
|
||||
$scope.setEntity(created.name, 'team', false);
|
||||
$scope.teams[teamname] = created;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.createRobot = function() {
|
||||
if (!$scope.isAdmin) { return; }
|
||||
|
||||
bootbox.prompt('Enter the name of the new robot account', function(robotname) {
|
||||
if (!robotname) { return; }
|
||||
|
||||
var regex = new RegExp(ROBOT_PATTERN);
|
||||
if (!regex.test(robotname)) {
|
||||
bootbox.alert('Invalid robot account name');
|
||||
return;
|
||||
}
|
||||
|
||||
createRobotAccount(Restangular, $scope.isOrganization, $scope.namespace, robotname, function(created) {
|
||||
$scope.setEntity(created.name, 'user', true);
|
||||
$scope.robots.push(created);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
$scope.setEntity = function(name, kind, is_robot) {
|
||||
var entity = {
|
||||
'name': name,
|
||||
'kind': kind,
|
||||
'is_robot': is_robot
|
||||
};
|
||||
|
||||
if ($scope.is_organization) {
|
||||
entity['is_org_member'] = true;
|
||||
}
|
||||
|
||||
$scope.entitySelected(entity);
|
||||
};
|
||||
|
||||
if (!$scope.entitySelected) { return; }
|
||||
|
||||
number++;
|
||||
|
||||
var input = $element[0].firstChild;
|
||||
var input = $element[0].firstChild.firstChild;
|
||||
$scope.namespace = $scope.namespace || '';
|
||||
$(input).typeahead({
|
||||
name: 'entities' + number,
|
||||
|
@ -1321,7 +1447,9 @@ quayApp.directive('entitySearch', function () {
|
|||
|
||||
$(input).on('typeahead:selected', function(e, datum) {
|
||||
$(input).typeahead('setQuery', '');
|
||||
$scope.entitySelected(datum.entity);
|
||||
$scope.$apply(function() {
|
||||
$scope.entitySelected(datum.entity);
|
||||
});
|
||||
});
|
||||
|
||||
$scope.$watch('inputTitle', function(title) {
|
||||
|
|
|
@ -418,11 +418,7 @@ function RepoAdminCtrl($scope, Restangular, $routeParams, $rootScope) {
|
|||
return;
|
||||
}
|
||||
|
||||
// Need the $scope.apply for both the permission stuff to change and for
|
||||
// the XHR call to be made.
|
||||
$scope.$apply(function() {
|
||||
$scope.addRole(entity.name, 'read', entity.kind);
|
||||
});
|
||||
$scope.addRole(entity.name, 'read', entity.kind);
|
||||
};
|
||||
|
||||
$scope.deleteRole = function(entityName, kind) {
|
||||
|
@ -1020,6 +1016,7 @@ function OrgViewCtrl($rootScope, $scope, Restangular, $routeParams) {
|
|||
'html': true
|
||||
});
|
||||
|
||||
$scope.TEAM_PATTERN = TEAM_PATTERN;
|
||||
$rootScope.title = 'Loading...';
|
||||
|
||||
var orgname = $routeParams.orgname;
|
||||
|
@ -1071,15 +1068,8 @@ function OrgViewCtrl($rootScope, $scope, Restangular, $routeParams) {
|
|||
return;
|
||||
}
|
||||
|
||||
var createTeam = Restangular.one(getRestUrl('organization', orgname, 'team', teamname));
|
||||
var data = {
|
||||
'name': teamname,
|
||||
'role': 'member'
|
||||
};
|
||||
createTeam.customPOST(data).then(function(resp) {
|
||||
$scope.organization.teams[teamname] = resp;
|
||||
}, function() {
|
||||
$('#cannotChangeTeamModal').modal({});
|
||||
createOrganizationTeam(Restangular, orgname, teamname, function(created) {
|
||||
$scope.organization.teams[teamname] = created;
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -1206,13 +1196,11 @@ function TeamViewCtrl($rootScope, $scope, Restangular, $routeParams) {
|
|||
$scope.addNewMember = function(member) {
|
||||
if ($scope.members[member.name]) { return; }
|
||||
|
||||
$scope.$apply(function() {
|
||||
var addMember = Restangular.one(getRestUrl('organization', $scope.orgname, 'team', teamname, 'members', member.name));
|
||||
addMember.customPOST().then(function(resp) {
|
||||
$scope.members[member.name] = resp;
|
||||
}, function() {
|
||||
$('#cannotChangeMembersModal').modal({});
|
||||
});
|
||||
var addMember = Restangular.one(getRestUrl('organization', $scope.orgname, 'team', teamname, 'members', member.name));
|
||||
addMember.customPOST().then(function(resp) {
|
||||
$scope.members[member.name] = resp;
|
||||
}, function() {
|
||||
$('#cannotChangeMembersModal').modal({});
|
||||
});
|
||||
};
|
||||
|
||||
|
|
Reference in a new issue