From e539df5268be8ca6d217ea310a8fe085a6aaab8f Mon Sep 17 00:00:00 2001 From: ljf Date: Wed, 4 Sep 2019 23:58:53 +0200 Subject: [PATCH 01/42] [wip] Create the permissions view --- src/css/style.less | 32 ++++++++++++++++ src/js/yunohost/controllers/users.js | 56 ++++++++++++++++++++++++++++ src/locales/en.json | 8 ++++ src/views/user/user_list.ms | 3 ++ 4 files changed, 99 insertions(+) diff --git a/src/css/style.less b/src/css/style.less index 201309b9..d3bc578f 100644 --- a/src/css/style.less +++ b/src/css/style.less @@ -101,6 +101,10 @@ button { color: transparent; } +.label { + border-radius: 1px; +} + /* * The top heading of the doc * @@ -659,6 +663,34 @@ input[type='radio'].nice-radio { } +/** Permissions View **/ +#view-permissions { + .panel-body { + h3 { + margin-top:0; + } + .label-removable { + display:inline-block; + font-size:1.3em; + color:#666; + background-color:#ccc; + margin-right:7px; + margin-bottom:7px; + .label-separator { + margin-left:7px; + color:white; + } + > a { + color:white; + text-decoration: none; + } + > a:hover { + color:@label-danger-bg; + } + } + } +} + /** Flash messages **/ #flashMessage { max-height: 120px; diff --git a/src/js/yunohost/controllers/users.js b/src/js/yunohost/controllers/users.js index 92e235ad..3bdfed57 100644 --- a/src/js/yunohost/controllers/users.js +++ b/src/js/yunohost/controllers/users.js @@ -5,6 +5,59 @@ var PASSWORD_MIN_LENGTH = 4; + /** + * Permissions + * + */ + + // List groups and permissions + app.get('#/permissions', function (c) { + c.api('/users/groups', function(data_groups) { + //c.api('/users/permissions', function(data_permissions) { + data = { + 'groups':[ + { + 'name': 'all_users', + 'all_users': "true", + 'users': ['ljf', 'john', 'camille', 'sam', 'eli', 'bob', 'sandra', + 'aaron', 'mike'], + 'permissions': ['Mail', 'XMPP'] + }, + { + 'name': 'members', + 'users': ['ljf', 'john', 'eli', 'bob', 'sandra', + 'aaron', 'mike'], + 'permissions': ['Mail', 'XMPP', 'Wekan', 'Wordpress (editor)'] + }, + { + 'name':'volunters', + 'users':['ljf', 'toto'], + 'permissions': [] + }, + { + 'name':'admins', + 'users':['ljf', 'toto'], + 'permissions': [] + } + ], + 'users_with_specific_permissions':[ + { + 'username': 'ljf', + 'permissions': ['Nextcloud'] + }, + { + 'username': 'toto', + 'permissions': ['Nextcloud'] + } + ], + 'users': ['ljf', 'toto', 'titi', 'tutu', 'tata'], + 'permissions': ['Mail', 'XMPP', 'Wekan', 'nextcloud'] + }; + c.view('user/user_permission', data); + //}); + }); + }); + /** * Users * @@ -234,5 +287,8 @@ }); }); + + + })(); diff --git a/src/locales/en.json b/src/locales/en.json index cd0d4c4b..9e9c5f83 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -158,6 +158,7 @@ "gateway": "Gateway: ", "good_practices_about_admin_password": "You are now about to define a new admin password. The password should be at least 8 characters - though it is good practice to use longer password (i.e. a passphrase) and/or to use various kind of characters (uppercase, lowercase, digits and special characters).", "good_practices_about_user_password": "You are now about to define a new user password. The password should be at least 8 characters - though it is good practice to use longer password (i.e. a passphrase) and/or to use various kind of characters (uppercase, lowercase, digits and special characters).", + "group": "Group", "home": "Home", "hook_adminjs_group_configuration": "System configurations", "hook_conf_cron": "Automatic tasks", @@ -271,6 +272,13 @@ "logs_share_with_yunopaste": "Share with YunoPaste", "logs_more": "Display more lines", "path_url": "Path", + "perm_add_user": "Add a user", + "perm_add_permission": "Add a permission", + "perm_groups_new": "New group", + "perm_manage_permissions": "Manage permissions", + "perm_all_users_group_explanation": "This is a specific group containing all users registered on this instance", + "perm_specific_permissions": "User specific permissions", + "permissions": "Permissions", "port": "Port", "ports": "Ports", "postinstall": "Post-installation", diff --git a/src/views/user/user_list.ms b/src/views/user/user_list.ms index b2aebff6..72148055 100644 --- a/src/views/user/user_list.ms +++ b/src/views/user/user_list.ms @@ -4,6 +4,9 @@
+ + {{t 'manage_permissions'}} + {{t 'users_new'}} From 059bb67ced96fa93aae5008216b974e6a35581d3 Mon Sep 17 00:00:00 2001 From: ljf Date: Thu, 5 Sep 2019 00:02:41 +0200 Subject: [PATCH 02/42] [wip] Add the permissions view --- src/views/user/user_permission.ms | 142 ++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 src/views/user/user_permission.ms diff --git a/src/views/user/user_permission.ms b/src/views/user/user_permission.ms new file mode 100644 index 00000000..431c80a9 --- /dev/null +++ b/src/views/user/user_permission.ms @@ -0,0 +1,142 @@ + + + + +
+ +
+{{#each groups}} +
+ +
+
+
+
+

{{t 'users'}}

+
+
+ {{#if all_users}} + + {{else}} + {{#each users}} + + + {{.}} + + + + {{t 'delete'}} + + + {{/each}} +
+ + +
+ {{/if}} +
+
+
+
+
+

{{t 'permissions'}}

+
+
+ {{#each permissions}} + {{.}} + + + + {{t 'delete'}} + + + {{/each}} +
+ + +
+
+
+
+
+
+{{/each}} +
+ +
+
+ {{#each users_with_specific_permissions}} +
+
+

{{username}}

+
+
+ {{#each permissions}} + {{.}} + + + + {{t 'delete'}} + + + {{/each}} +
+ + +
+
+
+
+ {{/each}} +
+ + +
+
+
+
+
From 97420631e8f566e03d8ec77efc22721f2661709b Mon Sep 17 00:00:00 2001 From: ljf Date: Tue, 15 Oct 2019 19:53:35 +0200 Subject: [PATCH 03/42] [fix] Use the new permissions API --- src/bower.json | 2 +- src/gulpfile.js | 2 +- src/js/yunohost/controllers/users.js | 64 +++++++++++----------------- src/views/user/user_list.ms | 2 +- src/views/user/user_permission.ms | 22 +++++----- 5 files changed, 38 insertions(+), 54 deletions(-) diff --git a/src/bower.json b/src/bower.json index 0d0e89f5..1928e289 100644 --- a/src/bower.json +++ b/src/bower.json @@ -5,7 +5,7 @@ "private": true, "dependencies": { "bootstrap": "3.3.6", - "font-awesome": "4.5.0", + "fork-awesome": "1.1.7", "handlebars-helper-intl": "1.1.2", "handlebars": "4.0.11", "sammy": "0.7.6", diff --git a/src/gulpfile.js b/src/gulpfile.js index 5875faf9..e5f183e8 100644 --- a/src/gulpfile.js +++ b/src/gulpfile.js @@ -71,7 +71,7 @@ gulp.task('js-lint', function() { // Fonts gulp.task('fonts', function() { return gulp.src([ - 'bower_components/font-awesome/fonts/*', + 'bower_components/fork-awesome/fonts/*', 'bower_components/source-code-pro/EOT/*.eot', 'bower_components/source-code-pro/OTF/*.otf', 'bower_components/source-code-pro/TTF/*.ttf', diff --git a/src/js/yunohost/controllers/users.js b/src/js/yunohost/controllers/users.js index 3bdfed57..d4fdce45 100644 --- a/src/js/yunohost/controllers/users.js +++ b/src/js/yunohost/controllers/users.js @@ -12,49 +12,33 @@ // List groups and permissions app.get('#/permissions', function (c) { - c.api('/users/groups', function(data_groups) { - //c.api('/users/permissions', function(data_permissions) { + c.api('/users/groups?full&include_primary_groups', function(data_groups) { + c.api('/users', function(data_users) { + console.log(data_users); + console.log(data_groups); + //var perms = data_permissions.permissions; + var specific_perms = {}; + var all_perms = []; + for (var groupname in data_groups.groups) { + var group = data_groups.groups[groupname]; + if (group.members.length == 1 && groupname == group.members[0]) { + specific_perms[groupname] = group; + } + } + console.log(specific_perms); + for (var primary_group in specific_perms) { + delete data_groups.groups[primary_group]; + } + data_groups.groups['all_users'].special = true; + data_groups.groups['visitors'].special = true; data = { - 'groups':[ - { - 'name': 'all_users', - 'all_users': "true", - 'users': ['ljf', 'john', 'camille', 'sam', 'eli', 'bob', 'sandra', - 'aaron', 'mike'], - 'permissions': ['Mail', 'XMPP'] - }, - { - 'name': 'members', - 'users': ['ljf', 'john', 'eli', 'bob', 'sandra', - 'aaron', 'mike'], - 'permissions': ['Mail', 'XMPP', 'Wekan', 'Wordpress (editor)'] - }, - { - 'name':'volunters', - 'users':['ljf', 'toto'], - 'permissions': [] - }, - { - 'name':'admins', - 'users':['ljf', 'toto'], - 'permissions': [] - } - ], - 'users_with_specific_permissions':[ - { - 'username': 'ljf', - 'permissions': ['Nextcloud'] - }, - { - 'username': 'toto', - 'permissions': ['Nextcloud'] - } - ], - 'users': ['ljf', 'toto', 'titi', 'tutu', 'tata'], - 'permissions': ['Mail', 'XMPP', 'Wekan', 'nextcloud'] + 'groups':data_groups.groups, + 'users_with_specific_permissions': specific_perms, + 'users': Object.keys(data_users.users), + 'permissions': all_perms }; c.view('user/user_permission', data); - //}); + }); }); }); diff --git a/src/views/user/user_list.ms b/src/views/user/user_list.ms index 72148055..bbdbde81 100644 --- a/src/views/user/user_list.ms +++ b/src/views/user/user_list.ms @@ -5,7 +5,7 @@
- {{t 'manage_permissions'}} + {{t 'perm_manage_permissions'}} {{t 'users_new'}} diff --git a/src/views/user/user_permission.ms b/src/views/user/user_permission.ms index 431c80a9..d388312c 100644 --- a/src/views/user/user_permission.ms +++ b/src/views/user/user_permission.ms @@ -15,24 +15,24 @@
{{#each groups}}
-