mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-01 23:38:37 +00:00
[user panel] added 'group owned library' function
This commit is contained in:
parent
b87f0312d7
commit
1b6a8479da
@ -34,15 +34,15 @@ def get_group_owned_repo_info(request, repo_id):
|
||||
repo = seafile_api.get_repo(repo_id)
|
||||
|
||||
repo_info = {}
|
||||
repo_info['repo_id'] = repo_id
|
||||
repo_info['repo_name'] = repo.name
|
||||
repo_info['id'] = repo_id
|
||||
repo_info['name'] = repo.name
|
||||
|
||||
repo_info['mtime'] = timestamp_to_isoformat_timestr(repo.last_modified)
|
||||
repo_info['size'] = repo.size
|
||||
repo_info['encrypted'] = repo.encrypted
|
||||
|
||||
repo_owner = get_repo_owner(request, repo_id)
|
||||
repo_info['owner_email'] = repo_owner
|
||||
repo_info['owner'] = repo_owner
|
||||
|
||||
return repo_info
|
||||
|
||||
@ -61,13 +61,13 @@ class GroupOwnedLibraries(APIView):
|
||||
"""
|
||||
|
||||
# argument check
|
||||
repo_name = request.data.get("repo_name", None)
|
||||
repo_name = request.data.get("name", None)
|
||||
if not repo_name or \
|
||||
not is_valid_dirent_name(repo_name):
|
||||
error_msg = "repo_name invalid."
|
||||
error_msg = "name invalid."
|
||||
return api_error(status.HTTP_400_BAD_REQUEST, error_msg)
|
||||
|
||||
password = request.data.get("password", None)
|
||||
password = request.data.get("passwd", None)
|
||||
if password and not config.ENABLE_ENCRYPTED_LIBRARY:
|
||||
error_msg = 'NOT allow to create encrypted library.'
|
||||
return api_error(status.HTTP_403_FORBIDDEN, error_msg)
|
||||
|
@ -56,6 +56,7 @@ def get_group_info(request, group_id, avatar_size=GROUP_AVATAR_DEFAULT_SIZE):
|
||||
isoformat_timestr = timestamp_to_isoformat_timestr(group.timestamp)
|
||||
group_info = {
|
||||
"id": group.id,
|
||||
"parent_group_id": group.parent_group_id,
|
||||
"name": group.group_name,
|
||||
"owner": group.creator_name,
|
||||
"created_at": isoformat_timestr,
|
||||
|
@ -243,11 +243,17 @@
|
||||
<td><a href="#group/<%= group_id %>/lib/<%= id %>" class="normal"><%- name %></a></td>
|
||||
<td class="alc">
|
||||
<% if (app.pageOptions.is_pro) { %>
|
||||
<% if (is_repo_owner || is_admin) { %>
|
||||
<a href="#" class="sf2-icon-share sf2-x repo-share-btn op-icon vh" title="{% trans "Share" %}" aria-label="{% trans "Share" %}"></a>
|
||||
<% } %>
|
||||
<% if (is_staff || is_repo_owner || is_admin) { %>
|
||||
<a href="#" class="sf2-icon-delete sf2-x cancel-share op-icon vh" title="{% trans "Unshare" %}" aria-label="{% trans "Unshare" %}"></a>
|
||||
<% if (parent_group_id == 0) { %>
|
||||
<% if (is_repo_owner || is_admin) { %>
|
||||
<a href="#" class="sf2-icon-share sf2-x repo-share-btn op-icon vh" title="{% trans "Share" %}" aria-label="{% trans "Share" %}"></a>
|
||||
<% } %>
|
||||
<% if (is_staff || is_repo_owner || is_admin) { %>
|
||||
<a href="#" class="sf2-icon-delete sf2-x cancel-share op-icon vh" title="{% trans "Unshare" %}" aria-label="{% trans "Unshare" %}"></a>
|
||||
<% } %>
|
||||
<% } else { %>
|
||||
<% if (is_staff) { %>
|
||||
<a href="#" class="sf2-icon-delete sf2-x delete-repo op-icon vh" title="{% trans "Delete" %}" aria-label="{% trans "Delete" %}"></a>
|
||||
<% } %>
|
||||
<% } %>
|
||||
<% } else { %>
|
||||
<% if (is_repo_owner) { %>
|
||||
@ -1771,6 +1777,15 @@
|
||||
<th width="16%">{% trans "Owner" %}</th>
|
||||
</tr>
|
||||
</script>
|
||||
<script type="text/template" id="group-owned-repos-hd-tmpl">
|
||||
<tr>
|
||||
<th width="4%"><span class="sr-only">{% trans "Library Type" %}</span><!--icon--></th>
|
||||
<th width="46%"><a class="table-sort-op by-name" href="#">{% trans "Name" %} <span class="sort-icon icon-caret-down hide"></span></a></th>
|
||||
<th width="10%"><span class="sr-only">{% trans "Actions" %}</span><!--op--></th>
|
||||
<th width="20%">{% trans "Size" %}</th>
|
||||
<th width="20%"><a class="table-sort-op by-time" href="#">{% trans "Last Update" %} <span class="sort-icon icon-caret-up"></span></a></th>
|
||||
</tr>
|
||||
</script>
|
||||
<script type="text/template" id="shared-repos-hd-mobile-tmpl">
|
||||
<tr>
|
||||
<th width="4%"><span class="sr-only">{% trans "Library Type" %}</span><!--icon--></th>
|
||||
|
27
static/scripts/app/collections/group-owned-repos.js
Normal file
27
static/scripts/app/collections/group-owned-repos.js
Normal file
@ -0,0 +1,27 @@
|
||||
define([
|
||||
'underscore',
|
||||
'backbone',
|
||||
'common',
|
||||
'app/models/group-repo'
|
||||
], function(_, Backbone, Common, GroupRepo) {
|
||||
'use strict';
|
||||
|
||||
var GroupRepoCollection = Backbone.Collection.extend({
|
||||
model: GroupRepo,
|
||||
comparator: -'mtime',
|
||||
|
||||
url: function() {
|
||||
return Common.getUrl({name: 'group_owned_repos', group_id: this.group_id});
|
||||
},
|
||||
|
||||
parse: function(data) {
|
||||
//return data.repos;
|
||||
},
|
||||
|
||||
setGroupID: function(group_id) {
|
||||
this.group_id = group_id;
|
||||
}
|
||||
});
|
||||
|
||||
return GroupRepoCollection;
|
||||
});
|
@ -43,15 +43,22 @@ define([
|
||||
|
||||
// Generate the attributes for a new GroupRepo item.
|
||||
newAttributes: function() {
|
||||
return {
|
||||
var data = {
|
||||
name: $.trim($('input[name=repo_name]', this.$el).val()),
|
||||
encrypted: $('#encrypt-switch').prop('checked'),
|
||||
passwd1: $('input[name=passwd]', this.$el).val(),
|
||||
passwd2: $('input[name=passwd_again]', this.$el).val(),
|
||||
passwd: $('input[name=passwd]', this.$el).val(),
|
||||
library_template: $('[name="library_template"]', this.$el).val(),
|
||||
storage_id: $('[name="storage"]', this.$el).val()
|
||||
};
|
||||
|
||||
if (data.encrypted) {
|
||||
$.extend(data, {
|
||||
passwd1: $('input[name=passwd]', this.$el).val(),
|
||||
passwd2: $('input[name=passwd_again]', this.$el).val(),
|
||||
passwd: $('input[name=passwd]', this.$el).val()
|
||||
});
|
||||
}
|
||||
|
||||
return data;
|
||||
},
|
||||
|
||||
// TODO: move to common
|
||||
|
@ -34,6 +34,7 @@ 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,
|
||||
$listContainer = this.$('tbody');
|
||||
var groupRepos = new GroupRepos();
|
||||
@ -42,6 +43,7 @@ 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,
|
||||
show_repo_owner: false // don't show 'Owner'
|
||||
});
|
||||
|
@ -15,6 +15,7 @@ define([
|
||||
mobileTemplate: _.template($('#group-repo-mobile-tmpl').html()),
|
||||
|
||||
events: {
|
||||
'click .delete-repo': 'delRepo', // for group owned repo
|
||||
'click .cancel-share': 'unshare',
|
||||
'click .repo-share-btn': 'share'
|
||||
},
|
||||
@ -23,12 +24,38 @@ 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.listenTo(this.model, 'destroy', this.remove);
|
||||
},
|
||||
|
||||
delRepo: function() {
|
||||
var _this = this;
|
||||
$.ajax({
|
||||
url: Common.getUrl({
|
||||
'name': 'group_owned_repo',
|
||||
'group_id': this.group_id,
|
||||
'repo_id': this.model.get('id')
|
||||
}),
|
||||
type: 'DELETE',
|
||||
cache: false,
|
||||
dataType: 'json',
|
||||
beforeSend: Common.prepareCSRFToken,
|
||||
success: function() {
|
||||
var msg = gettext("Successfully deleted library {placeholder}")
|
||||
.replace('{placeholder}', _this.model.get('name'));
|
||||
_this.remove();
|
||||
Common.feedback(msg, 'success');
|
||||
},
|
||||
error: function(xhr, textStatus, errorThrown) {
|
||||
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
|
||||
}
|
||||
});
|
||||
return false;
|
||||
},
|
||||
|
||||
render: function() {
|
||||
var obj = this.model.toJSON();
|
||||
var icon_size = Common.isHiDPI() ? 48 : 24;
|
||||
@ -36,6 +63,7 @@ define([
|
||||
var tmpl = $(window).width() >= 768 ? this.template : this.mobileTemplate;
|
||||
$.extend(obj, {
|
||||
group_id: this.group_id,
|
||||
parent_group_id: this.parent_group_id,
|
||||
is_staff: this.is_staff,
|
||||
// for '#groups' (no 'share_from_me')
|
||||
is_repo_owner: app.pageOptions.username == this.model.get('owner'),
|
||||
|
@ -4,12 +4,13 @@ define([
|
||||
'backbone',
|
||||
'common',
|
||||
'app/collections/group-repos',
|
||||
'app/collections/group-owned-repos', // for address book group
|
||||
'app/views/group-repo',
|
||||
'app/views/add-group-repo',
|
||||
'app/views/group-members',
|
||||
'app/views/group-discussions',
|
||||
'app/views/group-settings'
|
||||
], function($, _, Backbone, Common, GroupRepos, GroupRepoView,
|
||||
], function($, _, Backbone, Common, GroupRepos, GroupOwnedRepos, GroupRepoView,
|
||||
AddGroupRepoView, GroupMembersView, GroupDiscussionsView, GroupSettingsView) {
|
||||
'use strict';
|
||||
|
||||
@ -21,6 +22,7 @@ define([
|
||||
toolbar2Template: _.template($('#group-toolbar2-tmpl').html()),
|
||||
pathTemplate: _.template($('#group-path-tmpl').html()),
|
||||
theadTemplate: _.template($('#shared-repos-hd-tmpl').html()),
|
||||
ownedReposTheadTemplate: _.template($('#group-owned-repos-hd-tmpl').html()),
|
||||
theadMobileTemplate: _.template($('#shared-repos-hd-mobile-tmpl').html()),
|
||||
|
||||
events: {
|
||||
@ -39,18 +41,33 @@ define([
|
||||
this.listenTo(this.repos, 'add', this.addOne);
|
||||
this.listenTo(this.repos, 'reset', this.reset);
|
||||
|
||||
this.ownedRepos = new GroupOwnedRepos();
|
||||
this.listenTo(this.ownedRepos, 'add', this.addOne);
|
||||
|
||||
this.settingsView = new GroupSettingsView({groupView: this});
|
||||
this.membersView = new GroupMembersView({groupView: this});
|
||||
this.discussionsView = new GroupDiscussionsView({groupView: this});
|
||||
},
|
||||
|
||||
addOne: function(repo, collection, options) {
|
||||
|
||||
// for newly created group owned repo, returned by 'POST' request
|
||||
if (!repo.get('size_formatted') && repo.get('size') == 0
|
||||
&& !repo.get('mtime_relative')) {
|
||||
repo.set({
|
||||
'size_formatted': '0 bytes', // no trans here
|
||||
'mtime_relative': gettext("Just now")
|
||||
});
|
||||
}
|
||||
|
||||
var view = new GroupRepoView({
|
||||
model: repo,
|
||||
group_id: this.group_id,
|
||||
show_repo_owner: true,
|
||||
parent_group_id: this.group.parent_group_id,
|
||||
show_repo_owner: this.group.show_repo_owner,
|
||||
is_staff: this.repos.is_staff
|
||||
});
|
||||
|
||||
if (options.prepend) {
|
||||
this.$tableBody.prepend(view.render().el);
|
||||
} else {
|
||||
@ -59,7 +76,16 @@ define([
|
||||
},
|
||||
|
||||
renderThead: function() {
|
||||
var tmpl = $(window).width() >= 768 ? this.theadTemplate : this.theadMobileTemplate;
|
||||
var tmpl;
|
||||
if ($(window).width() < 768) {
|
||||
tmpl = this.theadMobileTemplate;
|
||||
} else {
|
||||
if (this.group.parent_group_id == 0) {
|
||||
tmpl = this.theadTemplate;
|
||||
} else {
|
||||
tmpl = this.ownedReposTheadTemplate;
|
||||
}
|
||||
}
|
||||
this.$tableHead.html(tmpl());
|
||||
},
|
||||
|
||||
@ -99,7 +125,29 @@ define([
|
||||
dataType: 'json',
|
||||
success: function(data) {
|
||||
_this.group = data;
|
||||
_this.$toolbar.removeClass('hide');
|
||||
|
||||
var user_can_add_repo = false;
|
||||
var user_is_admin = false;
|
||||
if ($.inArray(app.pageOptions.username, data.admins) != -1) {
|
||||
user_is_admin = true;
|
||||
}
|
||||
if (data.parent_group_id == 0) { // common group
|
||||
user_can_add_repo = true;
|
||||
_this.group.show_repo_owner = true; // for repo list
|
||||
_this.group.repos_for_new = _this.repos; // for creating a new library
|
||||
} else { // address book group
|
||||
_this.group.show_repo_owner = false;
|
||||
if (app.pageOptions.is_pro && user_is_admin) {
|
||||
user_can_add_repo = true;
|
||||
_this.group.repos_for_new = _this.ownedRepos; // for creating a new library
|
||||
}
|
||||
}
|
||||
if (user_can_add_repo) {
|
||||
_this.$toolbar.removeClass('hide'); // show 'New Library' button
|
||||
} else {
|
||||
_this.$toolbar.addClass('hide');
|
||||
}
|
||||
|
||||
_this.renderPath({
|
||||
'name': data.name
|
||||
});
|
||||
@ -159,12 +207,14 @@ define([
|
||||
},
|
||||
|
||||
renderToolbar: function() {
|
||||
this.$toolbar = $('<div class="cur-view-toolbar hide" id="group-toolbar"></div>').html(this.toolbarTemplate());
|
||||
this.$toolbar = $('<div class="cur-view-toolbar hide" id="group-toolbar"></div>')
|
||||
.html(this.toolbarTemplate());
|
||||
this.$('.common-toolbar').before(this.$toolbar);
|
||||
},
|
||||
|
||||
renderMainCon: function() {
|
||||
this.$mainCon = $('<div class="main-panel-main main-panel-main-with-side" id="group"></div>').html(this.template());
|
||||
this.$mainCon = $('<div class="main-panel-main main-panel-main-with-side" id="group"></div>')
|
||||
.html(this.template());
|
||||
this.$el.append(this.$mainCon);
|
||||
|
||||
this.$path = $('.group-path', this.$mainCon);
|
||||
@ -206,7 +256,9 @@ define([
|
||||
},
|
||||
|
||||
createRepo: function() {
|
||||
new AddGroupRepoView(this.repos);
|
||||
var repos = this.group.repos_for_new;
|
||||
repos.setGroupID(this.group_id);
|
||||
new AddGroupRepoView(repos);
|
||||
},
|
||||
|
||||
sortByName: function() {
|
||||
|
@ -148,6 +148,8 @@ define([
|
||||
case 'group_member_bulk': return siteRoot + 'api/v2.1/groups/' + options.group_id + '/members/bulk/';
|
||||
case 'group_import_members': return siteRoot + 'ajax/group/' + options.group_id + '/members/import/';
|
||||
case 'group_repos': return siteRoot + 'api2/groups/' + options.group_id + '/repos/';
|
||||
case 'group_owned_repos': return siteRoot + 'api/v2.1/groups/' + options.group_id + '/group-owned-libraries/';
|
||||
case 'group_owned_repo': return siteRoot + 'api/v2.1/groups/' + options.group_id + '/group-owned-libraries/' + options.repo_id + '/';
|
||||
case 'group_discussions': return siteRoot + 'api2/groups/' + options.group_id + '/discussions/';
|
||||
case 'group_discussion': return siteRoot + 'api2/groups/' + options.group_id + '/discussions/' + options.discussion_id + '/';
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user