1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-01 15:09:14 +00:00

Merge branch '6.0'

Conflicts:
	media/js/base.js
	seahub/api2/views.py
	seahub/views/ajax.py
	tests/api/test_repo_user_folder_perm.py
This commit is contained in:
zhengxie
2017-02-17 17:11:33 +08:00
176 changed files with 44016 additions and 40721 deletions

View File

@@ -61,7 +61,9 @@ define([
reset: function() {
this.$loadingTip.hide();
this.$sysinfo.html(this.template(this.sysinfo.toJSON()));
var json_data = this.sysinfo.toJSON();
json_data['formatted_storage'] = Common.quotaSizeFormat(json_data['total_storage'], 1)
this.$sysinfo.html(this.template(json_data));
}
});

View File

@@ -0,0 +1,118 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'app/views/widgets/hl-item-view'
], function($, _, Backbone, Common, HLItemView) {
'use strict';
var GroupMemberView = HLItemView.extend({
tagName: 'tr',
template: _.template($('#group-member-item-tmpl').html()),
events: {
'click .user-role-edit-icon': 'showEdit',
'change .user-role-select': 'editRole',
'click .member-delete-btn': 'deleteGroupMember'
},
initialize: function() {
HLItemView.prototype.initialize.call(this);
this.listenTo(this.model, 'change', this.render);
var _this = this;
$(document).on('click', function(e) {
var target = e.target || event.srcElement;
if (!_this.$('.user-role-edit-icon, .user-role-select').is(target)) {
_this.$('.cur-role, .user-role-edit-icon').show();
_this.$('.user-role-select').hide();
}
});
},
showEdit: function() {
this.$('.cur-role, .user-role-edit-icon').hide();
this.$('.user-role-select').show();
},
editRole: function() {
var _this = this;
// '0': member, '1': admin
var val = this.$('[name="role"]').val();
var is_admin = val == 1 ? true : false;
$.ajax({
url: Common.getUrl({
'name': 'admin-group-member',
'group_id': _this.model.get('group_id'),
'email': _this.model.get('email')
}),
type: 'put',
dataType: 'json',
beforeSend: Common.prepareCSRFToken,
data: {
'is_admin': is_admin
},
success: function(data) {
_this.model.set({
'is_admin': data['is_admin'],
'role': data['role']
});
},
error: function(xhr) {
var err_msg;
if (xhr.responseText) {
err_msg = $.parseJSON(xhr.responseText).error_msg;
} else {
err_msg = gettext("Failed. Please check the network.");
}
Common.feedback(err_msg, 'error');
}
});
},
deleteGroupMember: function() {
var _this = this;
var email = this.model.get('email');
var popupTitle = gettext("Delete Member");
var popupContent = gettext("Are you sure you want to delete %s ?").replace('%s', '<span class="op-target ellipsis ellipsis-op-target" title="' + Common.HTMLescape(email) + '">' + Common.HTMLescape(email) + '</span>');
var yesCallback = function() {
$.ajax({
url: Common.getUrl({
'name': 'admin-group-member',
'group_id': _this.model.get('group_id'),
'email': email
}),
type: 'DELETE',
beforeSend: Common.prepareCSRFToken,
dataType: 'json',
success: function() {
_this.$el.remove();
var msg = gettext("Successfully deleted member {placeholder}").replace('{placeholder}', email);
Common.feedback(msg, 'success');
},
error: function(xhr, textStatus, errorThrown) {
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
},
complete: function() {
$.modal.close();
}
});
};
Common.showConfirm(popupTitle, popupContent, yesCallback);
return false;
},
render: function() {
this.$el.html(this.template(this.model.toJSON()));
return this;
}
});
return GroupMemberView;
});

View File

@@ -0,0 +1,187 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'sysadmin-app/views/group-member',
'sysadmin-app/collection/group-members'
], function($, _, Backbone, Common, GroupMemberView, GroupMemberCollection) {
'use strict';
var GroupMembersView = Backbone.View.extend({
id: 'admin-groups',
tabNavTemplate: _.template($("#groups-tabnav-tmpl").html()),
template: _.template($("#group-members-tmpl").html()),
addMemberFormTemplate: _.template($('#add-group-member-form-tmpl').html()),
initialize: function() {
this.groupMemberCollection = new GroupMemberCollection();
this.listenTo(this.groupMemberCollection, 'add', this.addOne);
this.listenTo(this.groupMemberCollection, 'reset', this.reset);
},
events: {
'click #js-add-group-member': 'addGroupMember'
},
addGroupMember: function () {
var $form = $(this.addMemberFormTemplate()),
_this = this;
$form.modal();
$('#simplemodal-container').css({'height':'auto', 'width':'auto'});
$('[name="email"]', $form).select2($.extend(
Common.contactInputOptionsForSelect2(), {
width: '275px',
containerCss: {'margin-bottom': '5px'},
placeholder: gettext("Search user or enter email and press Enter")
}));
$form.submit(function() {
var group_id = _this.groupMemberCollection.group_id;
var emails = $.trim($('[name="email"]', $form).val());
var $error = $('.error', $form);
var $submitBtn = $('[type="submit"]', $form);
if (!emails) {
$error.html(gettext("Email is required.")).show();
return false;
}
var input_emails = [];
var emails_list = emails.split(',');
for (var i = 0; i < emails_list.length; i++) {
input_emails.push(emails_list[i]);
}
$error.hide();
Common.disableButton($submitBtn);
$.ajax({
url: Common.getUrl({
'name': 'admin-group-members',
'group_id': group_id
}),
type: 'POST',
dataType: 'json',
beforeSend: Common.prepareCSRFToken,
traditional: true,
data: {'email': input_emails},
success: function(data) {
if (data.success.length > 0) {
_this.groupMemberCollection.add(data.success, {prepend: true});
}
var err_str = '';
if (data.failed.length > 0) {
$(data.failed).each(function(index, item) {
err_str += Common.HTMLescape(item.email) + ': ' + Common.HTMLescape(item.error_msg) + '<br />';
});
$error.html(err_str).show();
Common.enableButton($submitBtn);
} else {
Common.closeModal();
}
},
error: function(jqXHR, textStatus, errorThrown){
var err_msg;
if (jqXHR.responseText) {
err_msg = jqXHR.responseJSON.error_msg;
} else {
err_msg = gettext('Please check the network.');
}
$error.html(err_msg).show();
Common.enableButton($submitBtn);
}
});
return false;
});
return false;
},
render: function() {
var group_id = this.groupMemberCollection.group_id;
this.$el.html(this.tabNavTemplate({'cur_tab': 'members', 'group_id': group_id}) + this.template());
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
},
initPage: function() {
this.$table.hide();
this.$tableBody.empty();
this.$loadingTip.show();
this.$emptyTip.hide();
},
hide: function() {
this.$el.detach();
this.attached = false;
},
show: function(group_id) {
if (!this.attached) {
this.attached = true;
$("#right-panel").html(this.$el);
}
// init collection
this.groupMemberCollection.setGroupId(group_id);
this.render();
this.showGroupMembers();
},
showGroupMembers: function() {
this.initPage();
var _this = this;
this.groupMemberCollection.fetch({
cache: false,
reset: true,
error: function(collection, response, opts) {
var err_msg;
if (response.responseText) {
if (response['status'] == 401 || response['status'] == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = $.parseJSON(response.responseText).error_msg;
}
} else {
err_msg = gettext("Failed. Please check the network.");
}
Common.feedback(err_msg, 'error');
}
});
},
reset: function() {
this.$loadingTip.hide();
if (this.groupMemberCollection.length > 0) {
this.groupMemberCollection.each(this.addOne, this);
this.$table.show();
} else {
this.$emptyTip.show();
}
this.$('.path-bar').append(this.groupMemberCollection.group_name);
},
addOne: function(item, collection, options) {
var view = new GroupMemberView({model: item});
if (options.prepend) {
this.$tableBody.prepend(view.render().el);
} else {
this.$tableBody.append(view.render().el);
}
}
});
return GroupMembersView;
});

View File

@@ -0,0 +1,75 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'app/views/widgets/hl-item-view'
], function($, _, Backbone, Common, HLItemView) {
'use strict';
var GroupRepoView = HLItemView.extend({
tagName: 'tr',
template: _.template($('#group-library-item-tmpl').html()),
events: {
'click .repo-unshare-btn': 'unshareGroupLibrary'
},
initialize: function() {
HLItemView.prototype.initialize.call(this);
},
unshareGroupLibrary: function() {
var _this = this;
var repo_name = this.model.get('name');
var popupTitle = gettext("Unshare Library");
var popupContent = gettext("Are you sure you want to unshare %s ?").replace('%s', '<span class="op-target ellipsis ellipsis-op-target" title="' + Common.HTMLescape(repo_name) + '">' + Common.HTMLescape(repo_name) + '</span>');
var yesCallback = function() {
$.ajax({
url: Common.getUrl({
'name': 'admin-group-library',
'group_id': _this.model.get('group_id'),
'repo_id': _this.model.get('repo_id')
}),
type: 'DELETE',
beforeSend: Common.prepareCSRFToken,
dataType: 'json',
success: function() {
_this.$el.remove();
var msg = gettext("Successfully unshared library {placeholder}").replace('{placeholder}', repo_name);
Common.feedback(msg, 'success');
},
error: function(xhr, textStatus, errorThrown) {
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
},
complete: function() {
$.modal.close();
}
});
};
Common.showConfirm(popupTitle, popupContent, yesCallback);
return false;
},
render: function() {
var data = this.model.toJSON(),
icon_size = Common.isHiDPI() ? 96 : 24,
icon_url = this.model.getIconUrl(icon_size);
data['icon_url'] = icon_url;
data['icon_title'] = this.model.getIconTitle();
data['formatted_size'] = Common.fileSizeFormat(data['size'], 1),
data['enable_sys_admin_view_repo'] = app.pageOptions.enable_sys_admin_view_repo;
data['is_pro'] = app.pageOptions.is_pro;
this.$el.html(this.template(data));
return this;
}
});
return GroupRepoView;
});

View File

@@ -0,0 +1,102 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'sysadmin-app/views/group-repo',
'sysadmin-app/collection/group-repos'
], function($, _, Backbone, Common, GroupRepoView, GroupRepoCollection) {
'use strict';
var GroupReposView = Backbone.View.extend({
id: 'admin-groups',
tabNavTemplate: _.template($("#groups-tabnav-tmpl").html()),
template: _.template($("#group-libraries-tmpl").html()),
initialize: function() {
this.groupRepoCollection = new GroupRepoCollection();
this.listenTo(this.groupRepoCollection, 'add', this.addOne);
this.listenTo(this.groupRepoCollection, 'reset', this.reset);
},
render: function() {
var group_id = this.groupRepoCollection.group_id;
this.$el.html(this.tabNavTemplate({'cur_tab': 'libs', 'group_id': group_id}) + this.template());
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
},
initPage: function() {
this.$table.hide();
this.$tableBody.empty();
this.$loadingTip.show();
this.$emptyTip.hide();
},
hide: function() {
this.$el.detach();
this.attached = false;
},
show: function(group_id) {
if (!this.attached) {
this.attached = true;
$("#right-panel").html(this.$el);
}
// init collection
this.groupRepoCollection.setGroupId(group_id);
this.render();
this.showGroupLibraries();
},
showGroupLibraries: function() {
this.initPage();
var _this = this;
this.groupRepoCollection.fetch({
cache: false,
reset: true,
error: function(collection, response, opts) {
var err_msg;
if (response.responseText) {
if (response['status'] == 401 || response['status'] == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = $.parseJSON(response.responseText).error_msg;
}
} else {
err_msg = gettext("Failed. Please check the network.");
}
Common.feedback(err_msg, 'error');
}
});
},
reset: function() {
this.$loadingTip.hide();
if (this.groupRepoCollection.length > 0) {
this.groupRepoCollection.each(this.addOne, this);
this.$table.show();
} else {
this.$emptyTip.show();
}
this.$('.path-bar').append(this.groupRepoCollection.group_name);
},
addOne: function(library) {
var view = new GroupRepoView({model: library});
this.$tableBody.append(view.render().el);
}
});
return GroupReposView;
});

View File

@@ -0,0 +1,119 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'sysadmin-app/views/group',
'sysadmin-app/collection/search-groups'
], function($, _, Backbone, Common, GroupView, GroupCollection) {
'use strict';
var GroupsView = Backbone.View.extend({
id: 'search-groups',
template: _.template($("#search-groups-tmpl").html()),
initialize: function() {
this.groupCollection = new GroupCollection();
this.listenTo(this.groupCollection, 'add', this.addOne);
this.listenTo(this.groupCollection, 'reset', this.reset);
this.render();
},
render: function() {
this.$el.append(this.template());
this.$form = this.$('#search-group-form');
this.$name = $('[name="name"]', this.$form);
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
},
events: {
'submit #search-group-form': 'formSubmit'
},
initPage: function() {
this.$table.hide();
this.$tableBody.empty();
this.$loadingTip.show();
this.$emptyTip.hide();
},
hide: function() {
this.$el.detach();
this.attached = false;
},
show: function(option) {
if (!this.attached) {
this.attached = true;
$("#right-panel").html(this.$el);
}
this.getContent(option);
},
getContent: function(obj) {
this.initPage();
var _this = this;
this.groupCollection.fetch({
data: obj,
cache: false,
reset: true,
error: function(collection, response, opts) {
var err_msg;
if (response.responseText) {
if (response['status'] == 401 || response['status'] == 403) {
err_msg = gettext("Permission error");
} else {
err_msg = $.parseJSON(response.responseText).error_msg;
}
} else {
err_msg = gettext("Failed. Please check the network.");
}
Common.feedback(err_msg, 'error');
},
complete:function() {
_this.$loadingTip.hide();
}
});
},
reset: function() {
var name = this.groupCollection.search_name;
app.router.navigate('#search-groups/?name=' + encodeURIComponent(name));
this.$name.val(name);
this.$loadingTip.hide();
if (this.groupCollection.length > 0) {
this.groupCollection.each(this.addOne, this);
this.$table.show();
} else {
this.$emptyTip.show();
}
},
addOne: function(group) {
var view = new GroupView({model: group});
this.$tableBody.append(view.render().el);
},
formSubmit: function() {
var name = $.trim(this.$name.val());
if (!name) {
return false;
}
this.getContent({'name': name});
return false;
}
});
return GroupsView;
});

View File

@@ -35,13 +35,14 @@ define([
events: {
'submit #libs-search-form': 'searchLibs', // for 'all' libs
'submit #trash-libs-search-form': 'searchTrashLibs'
'submit #trash-libs-search-form': 'searchTrashLibs',
'submit #groups-search-form': 'searchGroups'
},
// search libs by repo_name
searchLibs: function() {
var $form = this.$('#libs-search-form');
var name = $.trim($('[name="name"]', $form).val());
var name = $.trim($('[name="name"]', $form).val());
if (!name) {
return false;
}
@@ -54,7 +55,7 @@ define([
// search trash libs by owner
searchTrashLibs: function() {
var $form = this.$('#trash-libs-search-form');
var owner = $.trim($('[name="name"]', $form).val());
var owner = $.trim($('[name="name"]', $form).val());
if (!owner) {
return false;
}
@@ -62,6 +63,18 @@ define([
var url = $form.attr('action') + '?name=' + encodeURIComponent(owner);
location.href = url;
return false; // necessary
},
searchGroups: function() {
var $form = this.$('#groups-search-form');
var name = $.trim($('[name="name"]', $form).val());
if (!name) {
return false;
}
var url = $form.attr('action') + '?name=' + encodeURIComponent(name);
location.href = url;
return false; // necessary
}
});