diff --git a/seahub/templates/js/templates.html b/seahub/templates/js/templates.html index b538470cc4..c9495ef65f 100644 --- a/seahub/templates/js/templates.html +++ b/seahub/templates/js/templates.html @@ -257,14 +257,15 @@ <%- name %> <% if (app.pageOptions.is_pro) { %> - <% if (parent_group_id == 0) { %> + <% if (!is_group_owned_repo) { %> <% if (is_repo_owner || is_admin) { %> <% } %> <% if (is_staff || is_repo_owner || is_admin) { %> <% } %> - <% } else { %> {# It is an address book group #} + + <% } else { %> {# for group owned repo #} <% if (is_staff) { %> <% if (owner == group_id + '@seafile_group') { %> {# this repo belongs to the current group #} @@ -284,6 +285,7 @@ <% } %> <% } %> <% } %> + <% } else { %> <% if (is_repo_owner) { %> @@ -315,7 +317,7 @@ <% if (app.pageOptions.is_pro) { %> - <% if (parent_group_id == 0) { %> + <% if (!is_group_owned_repo) { %>
<% } else { %> - +
+ + +
<% } %> <% } %> <% } %> diff --git a/seahub/views/ajax.py b/seahub/views/ajax.py index 945c60fbcc..0db5e4c319 100644 --- a/seahub/views/ajax.py +++ b/seahub/views/ajax.py @@ -328,6 +328,7 @@ def list_lib_dir(request, repo_id): else: repo_owner = seafile_api.get_repo_owner(repo.id) + result["repo_owner"] = repo_owner result["is_repo_owner"] = False result["has_been_shared_out"] = False result["is_admin"] = is_repo_admin(username, repo_id) diff --git a/static/scripts/app/collections/dirents.js b/static/scripts/app/collections/dirents.js index 0b356b97b3..51991457ab 100644 --- a/static/scripts/app/collections/dirents.js +++ b/static/scripts/app/collections/dirents.js @@ -22,6 +22,7 @@ define([ this.user_perm = data.user_perm; this.no_quota = data.no_quota; this.encrypted = data.encrypted; + this.repo_owner = data.repo_owner; this.is_repo_owner = data.is_repo_owner; this.is_virtual = data.is_virtual; this.has_been_shared_out = data.has_been_shared_out; diff --git a/static/scripts/app/views/dir.js b/static/scripts/app/views/dir.js index 1b6f3b9978..18c430a21d 100644 --- a/static/scripts/app/views/dir.js +++ b/static/scripts/app/views/dir.js @@ -455,9 +455,12 @@ define([ } _this.dir.user_can_set_folder_perm = false; - _this.is_address_book_group_admin = false; + _this.is_address_book_group_admin = false; // department admin + _this.is_group_owned_repo = false; if (_this.contextOptions && - _this.contextOptions.group_id) { // the repo is in a group + _this.contextOptions.group_id && // the repo is in a group + dir.repo_owner.indexOf('@seafile_group') != -1) { // It's a group owned repo + _this.is_group_owned_repo = true; _this.getGroupInfo(); } else { _this.reset(); @@ -483,22 +486,24 @@ define([ }); }, + // get department(group) info getGroupInfo: function() { var _this = this; + + var repo_owner = this.dir.repo_owner; // e.g: 4@seafile_group + var group_id = repo_owner.substring(0, repo_owner.indexOf('@')); $.ajax({ url: Common.getUrl({ 'name': 'group', - 'group_id': this.contextOptions.group_id + 'group_id': group_id }), cache: false, dataType: 'json', success: function(data) { - if (data.parent_group_id != 0 && // address book group - $.inArray(app.pageOptions.username, data.admins) != -1) { // user is group admin + if ($.inArray(app.pageOptions.username, data.admins) != -1) { // user is group admin _this.dir.user_can_set_folder_perm = true; _this.is_address_book_group_admin = true; - _this.parent_group_id = data.parent_group_id; } _this.reset(); }, @@ -868,7 +873,7 @@ define([ if (this.is_address_book_group_admin) { $.extend(options, { is_address_book_group_admin: true, - parent_group_id: this.parent_group_id + is_group_owned_repo: this.is_group_owned_repo }); } } diff --git a/static/scripts/app/views/dirent-grid.js b/static/scripts/app/views/dirent-grid.js index 1a8eb9e9c1..697ea3bfd9 100644 --- a/static/scripts/app/views/dirent-grid.js +++ b/static/scripts/app/views/dirent-grid.js @@ -219,7 +219,7 @@ define([ if (this.dirView.is_address_book_group_admin) { $.extend(options, { is_address_book_group_admin: true, - parent_group_id: this.dirView.parent_group_id + is_group_owned_repo: this.dirView.is_group_owned_repo }); } } diff --git a/static/scripts/app/views/dirent.js b/static/scripts/app/views/dirent.js index d14dde62e9..9d40b262a5 100644 --- a/static/scripts/app/views/dirent.js +++ b/static/scripts/app/views/dirent.js @@ -388,7 +388,7 @@ define([ if (this.dirView.is_address_book_group_admin) { $.extend(options, { is_address_book_group_admin: true, - parent_group_id: this.dirView.parent_group_id + is_group_owned_repo: this.dirView.is_group_owned_repo }); } } diff --git a/static/scripts/app/views/folder-share-item.js b/static/scripts/app/views/folder-share-item.js index b9a1596ca8..a7af550946 100644 --- a/static/scripts/app/views/folder-share-item.js +++ b/static/scripts/app/views/folder-share-item.js @@ -24,7 +24,7 @@ define([ this.show_admin = false; if (app.pageOptions.is_pro && this.path == '/' && - !this.item_data.parent_group_id) { // not for group owned repo + !this.item_data.is_group_owned_repo) { // not for group owned repo this.show_admin = true; } @@ -65,7 +65,7 @@ define([ var perm = $(e.currentTarget).val(); var item_data = this.item_data; var url, method, data; - if (item_data.parent_group_id) { // group owned repo + if (item_data.is_group_owned_repo) { // group owned repo if (item_data.for_user) { url = Common.getUrl({ name: 'group_owned_repo_user_share', @@ -140,7 +140,7 @@ define([ var item_data = this.item_data; var url, data = {}; - if (item_data.parent_group_id) { // group owned repo + if (item_data.is_group_owned_repo) { // group owned repo if (item_data.for_user) { url = Common.getUrl({ name: 'group_owned_repo_user_share', diff --git a/static/scripts/app/views/group-item.js b/static/scripts/app/views/group-item.js index 25991b2e23..66ebb4b7a8 100644 --- a/static/scripts/app/views/group-item.js +++ b/static/scripts/app/views/group-item.js @@ -35,7 +35,6 @@ define([ return Common.compareTwoWord(a.name, b.name); }); var group_id = this.model.get('id'), - parent_group_id = this.model.get('parent_group_id'), is_staff = $.inArray(app.pageOptions.username, this.model.get('admins')) != -1 ? true : false, repoDetailsView = this.repoDetailsView, $listContainer = this.$('tbody'); @@ -45,7 +44,6 @@ define([ var view = new GroupRepoView({ model: new GroupRepo(item, {collection: groupRepos}), group_id: group_id, - parent_group_id: parent_group_id, is_staff: is_staff, repoDetailsView: repoDetailsView, show_repo_owner: false // don't show 'Owner' diff --git a/static/scripts/app/views/group-repo.js b/static/scripts/app/views/group-repo.js index 5a1ae298ca..cd0e5109e9 100644 --- a/static/scripts/app/views/group-repo.js +++ b/static/scripts/app/views/group-repo.js @@ -35,7 +35,6 @@ define([ HLItemView.prototype.initialize.call(this); this.group_id = options.group_id; - this.parent_group_id = options.parent_group_id; this.is_staff = options.is_staff; this.show_repo_owner = options.show_repo_owner; this.repoDetailsView = options.repoDetailsView; @@ -204,7 +203,7 @@ define([ clickItem: function(e) { var target = e.target || event.srcElement; - if (this.parent_group_id != 0 && // only for address book group repo + if (this.model.get('owner') == this.group_id + '@seafile_group' && this.$('td').is(target) && this.repoDetailsView.$el.is(':visible')) { this.viewDetails(); @@ -216,19 +215,21 @@ define([ var icon_size = Common.isHiDPI() ? 48 : 24; var icon_url = this.model.getIconUrl(icon_size); var tmpl = $(window).width() >= 768 ? this.template : this.mobileTemplate; - var owner_name; + var owner_name, + is_group_owned_repo = false; if (obj.owner.indexOf('@seafile_group') == -1) { // 'owner_nickname' for '#group/id/' // 'owner_name' for '#groups' - owner_name = this.model.get('owner_nickname') || this.model.get('owner_name'); + owner_name = this.model.get('owner_nickname') || this.model.get('owner_name'); } else { // owner: "18@seafile_group" // It's a group owned repo owner_name = obj.group_name; + is_group_owned_repo = true; } $.extend(obj, { group_id: this.group_id, - parent_group_id: this.parent_group_id, + is_group_owned_repo: is_group_owned_repo, is_staff: this.is_staff, // for '#groups' (no 'share_from_me') is_repo_owner: app.pageOptions.username == this.model.get('owner'), @@ -265,11 +266,12 @@ define([ if (app.pageOptions.is_pro) { options.is_admin = this.model.get('is_admin'); // 'is_admin': repo is shared to the group with 'admin' perm - // private share group owned repo - if (this.parent_group_id && this.is_staff) { + // private share group owned repo (which belongs to this group) + if (this.is_staff && + this.model.get('owner') == this.group_id + '@seafile_group') { $.extend(options, { 'is_address_book_group_admin': true, - 'parent_group_id': this.parent_group_id + 'is_group_owned_repo': true }); } } diff --git a/static/scripts/app/views/group.js b/static/scripts/app/views/group.js index a6a29bf559..ce3de8bf60 100644 --- a/static/scripts/app/views/group.js +++ b/static/scripts/app/views/group.js @@ -67,7 +67,6 @@ define([ var view = new GroupRepoView({ model: repo, group_id: this.group_id, - parent_group_id: this.group.parent_group_id, show_repo_owner: true, repoDetailsView: this.repoDetailsView, is_staff: this.repos.is_staff diff --git a/static/scripts/app/views/share.js b/static/scripts/app/views/share.js index f63c09c7d4..64c0c4de5b 100644 --- a/static/scripts/app/views/share.js +++ b/static/scripts/app/views/share.js @@ -21,7 +21,7 @@ define([ // for group owned repo this.is_address_book_group_admin = options.is_address_book_group_admin; - this.parent_group_id = options.parent_group_id; + this.is_group_owned_repo = options.is_group_owned_repo; this.is_virtual = options.is_virtual; this.user_perm = options.user_perm; @@ -82,7 +82,7 @@ define([ var show_admin_perm_option = false; if (app.pageOptions.is_pro && this.dirent_path == '/' && // only for repo - !this.parent_group_id) { // not for group owned repo + !this.is_group_owned_repo) { show_admin_perm_option = true; } @@ -575,13 +575,13 @@ define([ var item_data = { 'for_user': true }; - if (this.parent_group_id) { // group owned repo + if (this.is_group_owned_repo) { // [{permission: "rw", user_name: "llj", user_email: "llj@1.com", user_contact_email: "llj@1.com"}] $.extend(item_data, { "user_email": item.user_email, "user_name": item.user_name, "permission": item.permission, - 'parent_group_id': this.parent_group_id + 'is_group_owned_repo': this.is_group_owned_repo }); } else { $.extend(item_data, { @@ -606,7 +606,7 @@ define([ var repo_id = this.repo_id, path = this.dirent_path; var url, data; - if (this.parent_group_id) { + if (this.is_group_owned_repo) { url = Common.getUrl({ name: 'group_owned_repo_user_share', repo_id: repo_id @@ -658,12 +658,12 @@ define([ var item_data = { 'for_user': false }; - if (this.parent_group_id) { // address book group + if (this.is_group_owned_repo) { $.extend(item_data, { "group_id": item.group_id, "group_name": item.group_name, "permission": item.permission, - "parent_group_id": this.parent_group_id + "is_group_owned_repo": this.is_group_owned_repo }); } else { $.extend(item_data, { @@ -749,7 +749,7 @@ define([ var repo_id = this.repo_id, path = this.dirent_path; - if (this.parent_group_id) { // group owned repo + if (this.is_group_owned_repo) { url = Common.getUrl({ name: 'group_owned_repo_group_share', repo_id: repo_id @@ -796,7 +796,7 @@ define([ }); $table.removeClass('hide'); }; - if (_this.parent_group_id) { // group owned repo + if (_this.is_group_owned_repo) { _this.prepareAvailableGroupsForGroupOwnedRepo({'callback': prepareGroupsSelector}); } else { _this.prepareAvailableGroups({'callback': prepareGroupsSelector}); @@ -837,7 +837,7 @@ define([ var $submitBtn = $('[type="submit"]', $form); var url, method, data; - if (this.parent_group_id) { // group owned repo + if (this.is_group_owned_repo) { url = Common.getUrl({ name: 'group_owned_repo_user_share', repo_id: repo_id @@ -925,7 +925,7 @@ define([ var $submitBtn = $('[type="submit"]', $form); var url, method, data; - if (this.parent_group_id) { + if (this.is_group_owned_repo) { url = Common.getUrl({ name: 'group_owned_repo_group_share', repo_id: repo_id