Commit d6a07468 authored by Sascha Pfeiffer's avatar Sascha Pfeiffer

added sharing capability to file repositories

Signed-off-by: default avatarSascha Pfeiffer <sascha.pfeiffer@psono.com>
parent 1c8c5f88
......@@ -193,6 +193,7 @@ var build = function(build_path, type) {
"src/common/data/js/controller/modal/VerifyCtrl.js",
"src/common/data/js/controller/modal/NewGroupCtrl.js",
"src/common/data/js/controller/modal/PickUserCtrl.js",
"src/common/data/js/controller/modal/SelectUserCtrl.js",
"src/common/data/js/controller/modal/EditGroupCtrl.js",
"src/common/data/js/controller/modal/EncryptMessageGPGCtrl.js",
"src/common/data/js/controller/modal/DecryptMessageGPGCtrl.js",
......
......@@ -189,6 +189,7 @@
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/SelectUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
......
......@@ -116,6 +116,7 @@
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/SelectUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
......
......@@ -422,6 +422,7 @@
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/SelectUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
......
......@@ -164,6 +164,7 @@
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/SelectUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
......
......@@ -296,6 +296,7 @@
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/SelectUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
......
......@@ -189,6 +189,7 @@
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/SelectUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
......
......@@ -506,6 +506,7 @@
<script src="js/controller/modal/VerifyCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/NewGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/PickUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/SelectUserCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EditGroupCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/EncryptMessageGPGCtrl.js" type="application/javascript"></script>
<script src="js/controller/modal/DecryptMessageGPGCtrl.js" type="application/javascript"></script>
......
......@@ -15,11 +15,11 @@
* Controller for the "Edit File Repository" modal in Other
*/
angular.module('psonocli').controller('ModalEditFileRepositoryCtrl', ['$scope', '$q', '$uibModal', '$uibModalInstance',
'managerFileRepository', 'managerDatastorePassword', 'helper', 'DTOptionsBuilder', 'DTColumnDefBuilder',
'languagePicker', 'file_repository',
'managerFileRepository', 'managerDatastorePassword', 'managerDatastoreUser', 'helper',
'DTOptionsBuilder', 'DTColumnDefBuilder', 'languagePicker', 'file_repository',
function ($scope, $q, $uibModal, $uibModalInstance,
managerFileRepository, managerDatastorePassword, helper, DTOptionsBuilder, DTColumnDefBuilder,
languagePicker, file_repository) {
managerFileRepository, managerDatastorePassword, managerDatastoreUser, helper,
DTOptionsBuilder, DTColumnDefBuilder, languagePicker, file_repository) {
$scope.dtOptions = DTOptionsBuilder
.newOptions()
......@@ -45,11 +45,15 @@
$scope.cancel = cancel;
$scope.save = save;
$scope.toggle_input_type = toggle_input_type;
$scope.toggle_read = toggle_read;
$scope.toggle_write = toggle_write;
$scope.toggle_grant = toggle_grant;
$scope.delete_file_repository_right = delete_file_repository_right;
$scope.create_file_repository_right = create_file_repository_right;
activate();
function activate() {
console.log(file_repository);
$scope.title = file_repository.title;
$scope.selected_type = file_repository.type;
$scope.active = file_repository.active;
......@@ -133,6 +137,171 @@
}
}
/**
* @ngdoc
* @name psonocli.controller:ModalEditFileRepositoryCtrl#toggle_read
* @methodOf psonocli.controller:ModalEditFileRepositoryCtrl
*
* @description
* Triggered once someone clicks read Toggle button on a right for a user
*
* @param file_repository_right
*/
function toggle_read(file_repository_right) {
var onError = function(result) {
// pass
console.log(result);
};
var onSuccess = function(result) {
file_repository_right.read = !file_repository_right.read;
};
managerFileRepository.update_file_repository_right(file_repository_right.id, !file_repository_right.read, file_repository_right.write, file_repository_right.grant)
.then(onSuccess, onError);
}
/**
* @ngdoc
* @name psonocli.controller:ModalEditFileRepositoryCtrl#toggle_write
* @methodOf psonocli.controller:ModalEditFileRepositoryCtrl
*
* @description
* Triggered once someone clicks read Toggle button on a right for a user
*
* @param file_repository_right
*/
function toggle_write(file_repository_right) {
var onError = function(result) {
// pass
console.log(result);
};
var onSuccess = function(result) {
file_repository_right.write = !file_repository_right.write;
};
managerFileRepository.update_file_repository_right(file_repository_right.id, file_repository_right.read, !file_repository_right.write, file_repository_right.grant)
.then(onSuccess, onError);
}
/**
* @ngdoc
* @name psonocli.controller:ModalEditFileRepositoryCtrl#toggle_grant
* @methodOf psonocli.controller:ModalEditFileRepositoryCtrl
*
* @description
* Triggered once someone clicks read Toggle button on a right for a user
*
* @param file_repository_right
*/
function toggle_grant(file_repository_right) {
var onError = function(result) {
// pass
console.log(result);
};
var onSuccess = function(result) {
file_repository_right.grant = !file_repository_right.grant;
};
managerFileRepository.update_file_repository_right(file_repository_right.id, file_repository_right.read, file_repository_right.write, !file_repository_right.grant)
.then(onSuccess, onError);
}
/**
* @ngdoc
* @name psonocli.controller:ModalEditFileRepositoryCtrl#delete_file_repository_right
* @methodOf psonocli.controller:ModalEditFileRepositoryCtrl
*
* @description
* Triggered once someone clicks on the delete button for a right
*
* @param file_repository_right
*/
function delete_file_repository_right(file_repository_right) {
var onError = function(result) {
// pass
console.log(result);
};
var onSuccess = function(result) {
helper.remove_from_array($scope.file_repository.file_repository_rights, file_repository_right, function (a, b) {
return a.id === b.id;
});
};
managerFileRepository.delete_file_repository_right(file_repository_right.id)
.then(onSuccess, onError);
}
/**
* @ngdoc
* @name psonocli.controller:ModalEditFileRepositoryCtrl#create_file_repository_right
* @methodOf psonocli.controller:ModalEditFileRepositoryCtrl
*
* @description
* Create and add the created file repository right to the file_repository_rights array
*/
function create_and_add_file_repository_right(user) {
var onError = function(result) {
// pass
console.log(result);
};
var onSuccess = function(result) {
$scope.file_repository.file_repository_rights.push({
id: result.file_repository_right_id,
user_username: user['data']['user_username'],
read: false,
write: false,
grant: false,
accepted: false
});
};
return managerFileRepository.create_file_repository_right($scope.file_repository.id, user['data']['user_id'], false, false, false)
.then(onSuccess, onError);
}
/**
* @ngdoc
* @name psonocli.controller:ModalEditFileRepositoryCtrl#create_file_repository_right
* @methodOf psonocli.controller:ModalEditFileRepositoryCtrl
*
* @description
* Triggered once someone clicks on the Create Right button for a right to create a file repository right
*/
function create_file_repository_right() {
var onError = function(result) {
// pass
};
var onSuccess = function(result) {
if (typeof(result) === "undefined") {
// abort button was clicked
return;
}
for (var i = 0; i < result['users'].length; i++) {
create_and_add_file_repository_right(result['users'][i]);
}
};
return managerDatastoreUser.select_users()
.then(onSuccess, onError);
}
/**
* @ngdoc
* @name psonocli.controller:ModalEditFileRepositoryCtrl#close
......
(function(angular) {
'use strict';
/**
* @ngdoc controller
* @name psonocli.controller:ModalSelectUserCtrl
* @requires $scope
* @requires $uibModal
* @requires $uibModalInstance
* @requires psonocli.helper
* @requires psonocli.managerDatastoreUser
* @requires psonocli.cryptoLibrary
* @requires psonocli.shareBlueprint
* @requires DTOptionsBuilder
* @requires DTColumnDefBuilder
* @requires psonocli.languagePicker
*
* @description
* Controller for the "Select User" modal
*/
angular.module('psonocli').controller('ModalSelectUserCtrl', ['$scope', '$uibModal', '$uibModalInstance', 'helper',
'managerDatastoreUser', 'cryptoLibrary', 'shareBlueprint',
'DTOptionsBuilder', 'DTColumnDefBuilder', 'languagePicker',
function ($scope, $uibModal, $uibModalInstance, helper,
managerDatastoreUser, cryptoLibrary, shareBlueprint,
DTOptionsBuilder, DTColumnDefBuilder, languagePicker) {
$scope.dtOptions = DTOptionsBuilder
.newOptions()
.withLanguageSource('translations/datatables.' + languagePicker.get_active_language_code() + '.json');
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0),
DTColumnDefBuilder.newColumnDef(1)
];
$scope.structure = { data: {}} ;
$scope.errors = [];
$scope.selected_users = [];
$scope.toggle_select = toggle_select;
$scope.save = save;
$scope.cancel = cancel;
$scope.add_user = add_user;
activate();
function activate() {
managerDatastoreUser.get_user_datastore().then(function (user_datastore) {
var users = [];
helper.create_list(user_datastore, users);
$scope.users = users;
})
}
/**
* @ngdoc
* @name psonocli.controller:ModalShareEntryCtrl#add_user
* @methodOf psonocli.controller:ModalShareEntryCtrl
*
* @description
* responsible to add a user to the known users datastore
*/
function add_user() {
var modalInstance = $uibModal.open({
templateUrl: 'view/modal/new-entry.html',
controller: 'ModalShareNewEntryCtrl',
backdrop: 'static',
resolve: {
parent: function () {
},
path: function () {
return [];
},
hide_advanced: function () {
return true
},
hide_history: function () {
return true
}
}
});
modalInstance.result.then(function (content) {
managerDatastoreUser.get_user_datastore()
.then(function (parent) {
if (typeof parent.items === 'undefined') {
parent.items = [];
}
var user_object = {
id: cryptoLibrary.generate_uuid(),
type: content.id,
data: {}
};
if (shareBlueprint.get_blueprint(content.id).getName) {
user_object.name = shareBlueprint.get_blueprint(content.id).getName(content.fields);
}
for (var i = content.fields.length - 1; i >= 0; i--) {
if (!content.fields[i].hasOwnProperty("value")) {
continue;
}
if (!user_object.name && content.title_field === content.fields[i].name) {
user_object.name = content.fields[i].value;
}
if (content.hasOwnProperty("urlfilter_field")
&& content.urlfilter_field === content.fields[i].name) {
user_object.urlfilter = content.fields[i].value;
}
user_object.data[content.fields[i].name] = content.fields[i].value;
}
parent.items.push(user_object);
managerDatastoreUser.save_datastore_content(parent).then(function() {
$scope.users.push(user_object);
$scope.selected_users.push(user_object.id);
}, function() {
// TODO handle error
});
});
}, function () {
// cancel triggered
});
}
/**
* @ngdoc
* @name psonocli.controller:ModalShareEntryCtrl#toggle_select
* @methodOf psonocli.controller:ModalShareEntryCtrl
*
* @description
* responsible to toggle selections of rights and users and adding it to the selected_rights / selected_users
* array
*
* @param {int} index The index of the right in the array
* @param {string} type The type of the toggle
*/
function toggle_select(index, type) {
var search_array;
if (type === 'right') {
search_array = $scope.selected_rights;
} else if (type === 'user') {
search_array = $scope.selected_users;
} else {
search_array = $scope.selected_groups;
}
var array_index = search_array.indexOf(index);
if (array_index > -1) {
//its selected, lets deselect it
search_array.splice(array_index, 1);
} else {
search_array.push(index);
}
}
/**
* @ngdoc
* @name psonocli.controller:ModalSelectUserCtrl#save
* @methodOf psonocli.controller:ModalSelectUserCtrl
*
* @description
* Triggered once someone clicks the save button in the modal
*/
function save() {
var returnvalue = {
users: []
};
for (var i = 0; i < $scope.users.length; i++) {
if ($scope.selected_users.indexOf($scope.users[i].id) > -1){
returnvalue['users'].push($scope.users[i]);
}
}
$uibModalInstance.close(returnvalue);
}
/**
* @ngdoc
* @name psonocli.controller:ModalSelectUserCtrl#cancel
* @methodOf psonocli.controller:ModalSelectUserCtrl
*
* @description
* Triggered once someone clicks the cancel button in the modal
*/
function cancel() {
$uibModalInstance.dismiss('cancel');
}
}]);
}(angular));
......@@ -32,6 +32,9 @@
scope.treeView = scope.treeView;
}, 5000);
scope.attrs = attrs;
scope.element = element;
scope.offline = offlineCache.is_active();
$rootScope.$on('offline_mode_enabled', function() {
......@@ -121,37 +124,40 @@
* returns a list of the property of the nodes from root to the targeted item. Can be used for
* breadcrumbs for example.
*
* @param property The property that should be put into the list
* @param item The item up to which you want to generate the list
* @param orig_path The path as array of IDs to the target
* @returns {Array.<T>} A list of the nodes property
*/
var getPropertyPath = function (property, item) {
var path = [];
var getPropertyPath = function (orig_path){
if (typeof item !== 'undefined') {
if (typeof property === 'undefined') {
path.push(item);
} else {
path.push(item[property]);
}
}
var path = orig_path.slice();
var nodeScope = scope;
while (nodeScope.node) {
if (typeof property === 'undefined') {
path.push(nodeScope.node);
} else {
path.push(nodeScope.node[property]);
var getPropertyPathRecursive = function(path, datastore, current_property_path) {
var to_search = path[0];
var n, l;
var rest = path.slice(1);
if (datastore.hasOwnProperty('folders')) {
for (n = 0, l= datastore.folders.length; n < l; n++) {
if (datastore.folders[n].id === to_search) {
current_property_path.push(datastore.folders[n]);
return getPropertyPathRecursive(rest, datastore.folders[n], current_property_path);
}
}
}
while (nodeScope.$parent && nodeScope.$parent.node) {
if (!nodeScope.node.hasOwnProperty('id') || !nodeScope.$parent.node.hasOwnProperty('id') || nodeScope.node.id !== nodeScope.$parent.node.id) {
break;
if (datastore.hasOwnProperty('items')) {
for (n = 0, l= datastore.items.length; n < l; n++) {
if (datastore.items[n].id === to_search) {
current_property_path.push(datastore.items[n]);
return getPropertyPathRecursive(rest, datastore.items[n], current_property_path);
}
}
nodeScope = nodeScope.$parent;
}
nodeScope = nodeScope.$parent;
}
return path.reverse();
return current_property_path;
};
return getPropertyPathRecursive(path, scope.treeView.data, [])
};
/**
......@@ -167,7 +173,7 @@
}
if (typeof options.onEditNode === "function") {
options.onEditNode(node, getPropertyPath(idProperty));
options.onEditNode(node, node.path);
}
};
......@@ -183,11 +189,10 @@
scope.additionalButtonItem = function (item, event, my_function, folder) {
if (typeof options.onAdditionalButtonItem === "function") {
if (folder) {
options.onAdditionalButtonItem(scope.node, getPropertyPath(idProperty), my_function);
options.onAdditionalButtonItem(item, item.path, my_function);
} else {
options.onAdditionalButtonItem(item, getPropertyPath(idProperty, item), my_function);
options.onAdditionalButtonItem(item, item.path, my_function);
}
}
};
......@@ -204,7 +209,7 @@
}
if (typeof options.onNewFolder === "function") {
options.onNewFolder(node, getPropertyPath(idProperty));
options.onNewFolder(node, node.path);
}
};
......@@ -221,7 +226,7 @@
}
if (typeof options.onNewItem === "function") {
options.onNewItem(node, getPropertyPath(idProperty));
options.onNewItem(node, node.path);
}
};
......@@ -250,7 +255,8 @@
// User clicked the yes button
if (typeof options.onDeleteNode === "function") {
options.onDeleteNode(node, getPropertyPath(idProperty));
console.log(node);
options.onDeleteNode(node, node.path);
}
}, function () {
......@@ -278,9 +284,8 @@
modalInstance.result.then(function (breadcrumbs) {
// User clicked the prime button
var node_path = getPropertyPath(idProperty, node);
var node_path = node.path.slice();
if (typeof options.onMoveItem === "function") {
node_path.pop();
options.onMoveNode(node_path, breadcrumbs['id_breadcrumbs']);
}
......@@ -300,7 +305,7 @@
if (collapsible) {
controller.toggleExpanded(node);
}
controller.selectNode(node, getPropertyPath(), getPropertyPath(idProperty));
controller.selectNode(node, getPropertyPath(node.path), node.path);
};
/**
......@@ -311,7 +316,7 @@
*/
scope.editItem = function (item, event) {
if (typeof options.onEditItem === "function") {
options.onEditItem(item, getPropertyPath(idProperty, item));
options.onEditItem(item, item.path);
}
};
......@@ -324,7 +329,7 @@
scope.newFolderItem = function (item, event) {
if (typeof options.onNewFolder === "function") {
options.onNewFolder(scope.node, getPropertyPath(idProperty));
options.onNewFolder(item, item.path);
}
};
......@@ -338,7 +343,7 @@
scope.newEntryItem = function (item, event) {
if (typeof options.onNewItem === "function") {
options.onNewItem(scope.node, getPropertyPath(idProperty));
options.onNewItem(item, item.path);
}
};
......@@ -368,7 +373,7 @@
// User clicked the yes button
if (typeof options.onDeleteItem === "function") {
options.onDeleteItem(item, getPropertyPath(idProperty, item));
options.onDeleteItem(item, item.path);
}
}, function () {
......@@ -397,7 +402,7 @@
modalInstance.result.then(function (breadcrumbs) {
// User clicked the prime button
var item_path = getPropertyPath(idProperty, item);
var item_path = item.path;
if (typeof options.onMoveItem === "function") {
options.onMoveItem(item_path, breadcrumbs['id_breadcrumbs']);
}
......@@ -414,7 +419,7 @@
* @param event
*/
scope.clickItem = function (item, event) {
controller.clickItem(item, getPropertyPath(idProperty));
controller.clickItem(item, item.path);
};
......
......@@ -197,7 +197,7 @@
var filter_datastore_content = function(content) {
var content_copy = helper.duplicate_object(content);
var filter = ['expanded', 'expanded_temporary', 'is_expanded', 'filter', 'hidden', 'share_rights', 'parent_share_id', 'parent_datastore_id'];
var filter = ['expanded', 'expanded_temporary', 'is_expanded', 'filter', 'hidden', 'share_rights', 'path', 'parent_share_id', 'parent_datastore_id'];