-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enabled sharing for data sets. Still need to implement an auto refres…
…h of the list of data sets.
- Loading branch information
Showing
10 changed files
with
203 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
angular | ||
.module('refineryApp') | ||
.factory('sharingService', ['$resource', 'settings', | ||
function ($resource, settings) { | ||
|
||
var sharing = $resource( | ||
settings.appRoot + settings.refineryApi + '/:model/:uuid/sharing', | ||
{ | ||
model: '@model', | ||
uuid: '@uuid', | ||
format: 'json' | ||
}, | ||
{ | ||
query: { | ||
method: 'GET', | ||
isArray: false, | ||
}, | ||
update: { | ||
method: 'PUT' | ||
} | ||
} | ||
); | ||
|
||
return sharing; | ||
} | ||
]); |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 126 additions & 26 deletions
152
refinery/ui/src/js/dashboard/controllers/PermissionEditor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,141 @@ | ||
function PermissionEditorCtrl ($scope, $http, $modalInstance, params) { | ||
var ctrl = this; | ||
function PermissionEditorCtrl ($http, $modalInstance, _, sharingService, config) { | ||
var that = this; | ||
|
||
// loadResource(config.api, config.uuid); | ||
this._ = _; | ||
this.config = config; | ||
this.$modalInstance = $modalInstance; | ||
this.sharingService = sharingService; | ||
|
||
console.log($modalInstance); | ||
this.getPermissions( | ||
this.config.model, | ||
this.config.uuid | ||
).then(function (data) { | ||
that.permissions = data; | ||
}).catch(function (error) { | ||
console.error(error); | ||
}); | ||
|
||
ctrl.save = function () { | ||
var pTable = document.getElementById('permission-table'); | ||
var cells = pTable.getElementsByTagName('td'); | ||
// Data is clustered into sets of 4 -- i is name, i+1 is noperm, i+2 is readonly, i+3 is edit. | ||
for (var i = 0; i < cells.length; i += 4) { | ||
// Add the group. | ||
var name = cells[i].innerText; | ||
var id = cells[i].children[0].innerText; | ||
this.permissionLevel = { | ||
none: { | ||
read: false, | ||
change: false | ||
}, | ||
read: { | ||
read: true, | ||
change: false | ||
}, | ||
edit: { | ||
read: true, | ||
change: true | ||
}, | ||
}; | ||
} | ||
|
||
var canRead = cells[i+2].children[0].checked || cells[i+3].children[0].checked; | ||
var canChange = cells[i+3].children[0].checked; | ||
/** | ||
* Cancel permission editing. | ||
* @type {function} | ||
*/ | ||
PermissionEditorCtrl.prototype.cancel = function () { | ||
this.$modalInstance.dismiss('cancel'); | ||
}; | ||
|
||
var data = '{"read": ' + canRead + ', "change": ' + canChange + '}'; | ||
/** | ||
* [getPermissions description] | ||
* @type {function} | ||
* @param {string} model Model which permissions are to be edited. | ||
* @param {string} uuid UUID of the exact model entity. | ||
* @return {object} Angular promise. | ||
*/ | ||
PermissionEditorCtrl.prototype.getPermissions = function (model, uuid) { | ||
var that = this, | ||
permissions; | ||
|
||
// need to somehow store the group id in the cells as a hidden thing | ||
$http({method: 'PATCH', url: 'api/v1/' + config.api + '/' + config.uuid + '_' + id + '/', data: data}); | ||
} | ||
$modalInstance.dismiss('saved'); | ||
}; | ||
permissions = this.sharingService.get({ | ||
model: model, | ||
uuid: uuid | ||
}); | ||
|
||
ctrl.cancel = function () { | ||
$modalInstance.dismiss('cancel'); | ||
}; | ||
} | ||
return permissions | ||
.$promise | ||
.then(function (data) { | ||
groups = []; | ||
for (var i = 0, len = data.share_list.length; i < len; i++) { | ||
groups.push({ | ||
id: data.share_list[i].group_id, | ||
name: data.share_list[i].group_name, | ||
permission: that.getPermissionLevel(data.share_list[i].perms) | ||
}); | ||
} | ||
return { | ||
isOwner: data.is_owner, | ||
groups: groups | ||
}; | ||
}) | ||
.catch(function (error) { | ||
return error; | ||
}); | ||
}; | ||
|
||
/** | ||
* Turns permission object into a simple string. | ||
* @type {function} | ||
* @param {object} perms Object of the precise permissions. | ||
* @return {string} Permission's name. | ||
*/ | ||
PermissionEditorCtrl.prototype.getPermissionLevel = function (perms) { | ||
if (perms.read === false) { | ||
return 'none'; | ||
} | ||
if (perms.change === true) { | ||
return 'edit'; | ||
} | ||
return 'read'; | ||
}; | ||
|
||
/** | ||
* Save permissions | ||
* @type {function} | ||
*/ | ||
PermissionEditorCtrl.prototype.save = function () { | ||
var that = this, | ||
accessList = []; | ||
|
||
this.isSaving = true; | ||
|
||
for (var i = 0, len = this.permissions.groups.length; i < len; i++) { | ||
accessList.push(this._.assign({ | ||
id: this.permissions.groups[i].id | ||
}, this.permissionLevel[this.permissions.groups[i].permission])); | ||
} | ||
|
||
this | ||
.sharingService | ||
.update({ | ||
model: this.config.model, | ||
uuid: this.config.uuid | ||
}, { | ||
'share_list': accessList | ||
}) | ||
.$promise | ||
.then(function () { | ||
console.log('Sweet permissions are saved'); | ||
that.$modalInstance.dismiss('saved'); | ||
}) | ||
.catch(function (error) { | ||
console.error(error); | ||
}) | ||
.finally(function () { | ||
that.isSaving = false; | ||
}); | ||
}; | ||
|
||
angular | ||
.module('refineryDashboard') | ||
.controller('PermissionEditorCtrl', [ | ||
'$scope', | ||
'$http', | ||
'$modalInstance', | ||
'params', | ||
'_', | ||
'sharingService', | ||
'config', | ||
PermissionEditorCtrl | ||
]); |
16 changes: 0 additions & 16 deletions
16
refinery/ui/src/js/dashboard/directives/permissionTable.js
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters