2015-02-19 21:21:54 +00:00
|
|
|
/**
|
|
|
|
* Service which exposes various methods for creating entities on the backend.
|
|
|
|
*/
|
2015-04-08 15:54:04 +00:00
|
|
|
angular.module('quay').factory('CreateService', ['ApiService', 'UserService', function(ApiService, UserService) {
|
2015-02-19 21:21:54 +00:00
|
|
|
var createService = {};
|
|
|
|
|
|
|
|
createService.createRobotAccount = function(ApiService, is_org, orgname, name, callback) {
|
|
|
|
ApiService.createRobot(is_org ? orgname : null, null, {'robot_shortname': name})
|
|
|
|
.then(callback, ApiService.errorDisplay('Cannot create robot account'));
|
|
|
|
};
|
|
|
|
|
|
|
|
createService.createOrganizationTeam = function(ApiService, orgname, teamname, callback) {
|
|
|
|
var data = {
|
|
|
|
'name': teamname,
|
|
|
|
'role': 'member'
|
|
|
|
};
|
|
|
|
|
|
|
|
var params = {
|
|
|
|
'orgname': orgname,
|
|
|
|
'teamname': teamname
|
|
|
|
};
|
|
|
|
|
|
|
|
ApiService.updateOrganizationTeam(data, params)
|
|
|
|
.then(callback, ApiService.errorDisplay('Cannot create team'));
|
|
|
|
};
|
|
|
|
|
2015-04-08 15:54:04 +00:00
|
|
|
createService.askCreateRobot = function(namespace, callback) {
|
|
|
|
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { return; }
|
|
|
|
|
|
|
|
var isorg = UserService.isOrganization(namespace);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
createService.createRobotAccount(ApiService, isorg, namespace, robotname, callback);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
createService.askCreateTeam = function(namespace, callback) {
|
|
|
|
if (!namespace || !UserService.isNamespaceAdmin(namespace)) { 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
CreateService.createOrganizationTeam(ApiService, namespace, teamname, callback);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2015-02-19 21:21:54 +00:00
|
|
|
return createService;
|
|
|
|
}]);
|