1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-08-31 14:42:10 +00:00

Illegal report by react (#3415)

* illegal report

1, add illegal report at shared file page
2, list all illegal reports at admin page

* add ENABLE_SHARE_LINK_REPORT_ILLEGAL setting

* UserRateThrottle -> AnonRateThrottle

* use to_python_boolean

* frontend by React

* remove illegal report dialog in shared dir view

* add migrations dir

* add illegal_reports migrations

* rename illegal to abuse in api

* rename illegal to abuse in test

* rename illegal to abuse in share file view

* rename illegal to abuse in react

* rename illegal to abuse in Backbone

* add enableShareLinkReportAbuse in templates

* add ReportAbuse

* update ReportAbuse

* update ReportAbuse urls

* update ReportAbuse api-js

* sysadmin_react_app.html

* sysadmin.py

* fix

* fix

* fix

* can not abuse own file

* Contact Information is required.

* fix review

* remove repo icon
This commit is contained in:
sniper-py
2019-11-05 17:46:06 +08:00
committed by Daniel Pan
parent d95da0bff1
commit 37b743fe3a
31 changed files with 1114 additions and 43 deletions

View File

@@ -195,6 +195,8 @@ define([
case 'admin-library': return siteRoot + 'api/v2.1/admin/libraries/' + options.repo_id + '/';
case 'admin-library-history-limit': return siteRoot + 'api/v2.1/admin/libraries/' + options.repo_id + '/history-limit/';
case 'admin-library-dirents': return siteRoot + 'api/v2.1/admin/libraries/' + options.repo_id + '/dirents/';
case 'admin-abuse-reports': return siteRoot + 'api/v2.1/admin/abuse-reports/';
case 'admin-abuse-report': return siteRoot + 'api/v2.1/admin/abuse-reports/' + options.report_id + '/';
case 'admin-groups': return siteRoot + 'api/v2.1/admin/groups/';
case 'admin-group': return siteRoot + 'api/v2.1/admin/groups/' + options.group_id + '/';
case 'admin-group-libraries': return siteRoot + 'api/v2.1/admin/groups/' + options.group_id + '/libraries/';

View File

@@ -0,0 +1,22 @@
define([
'underscore',
'backbone',
'common',
'sysadmin-app/models/abuse-report'
], function(_, Backbone, Common, AbuseReportModel) {
'use strict';
var AbuseReportCollection = Backbone.Collection.extend({
model: AbuseReportModel,
url: function () {
return Common.getUrl({name: 'admin-abuse-reports'});
},
parse: function(data) {
this.data = data.abuse_report_list;
return data.abuse_report_list;
}
});
return AbuseReportCollection;
});

View File

@@ -0,0 +1,17 @@
define([
'underscore',
'backbone',
'common',
], function(_, Backbone, Common) {
'use strict';
var AbuseReportModel = Backbone.Model.extend({
getIconUrl: function(size) {
return Common.getLibIconUrl(false, false, size);
}
});
return AbuseReportModel;
});

View File

@@ -27,15 +27,15 @@ define([
'sysadmin-app/views/admin-operation-logs',
'sysadmin-app/views/admin-login-logs',
'sysadmin-app/views/device-trusted-ipaddresses',
'sysadmin-app/views/abuse-reports',
'app/views/account'
], function($, Backbone, Common, SideNavView, DashboardView,
DesktopDevicesView, MobileDevicesView, DeviceErrorsView,
ReposView, SearchReposView, SystemReposView, TrashReposView,
SearchTrashReposView, DirView,
AddressBookView, AddressBookGroupView,
SearchTrashReposView, DirView, AddressBookView, AddressBookGroupView,
GroupsView, SearchGroupsView, GroupReposView, GroupMembersView,
AdminOperationLogsview, AdminLoginLogsView, DeviceTrustedIPView,
AccountView) {
AbuseReportsView, AccountView) {
"use strict";
@@ -47,6 +47,7 @@ define([
'mobile-devices/': 'showMobileDevices',
'device-errors/': 'showDeviceErrors',
'device-trusted-ip/': 'showDeviceTrustedIP',
'abuse-reports/': 'showAbuseReports',
'all-libs/': 'showLibraries',
'search-libs/': 'showSearchLibraries',
@@ -86,6 +87,8 @@ define([
this.deviceErrorsView = new DeviceErrorsView();
this.deviceTrustedIPView = new DeviceTrustedIPView();
this.abuseReportsView = new AbuseReportsView();
this.reposView = new ReposView();
this.searchReposView = new SearchReposView();
this.systemReposView = new SystemReposView();
@@ -386,6 +389,12 @@ define([
this.switchCurrentView(this.adminLoginLogsView);
this.sideNavView.setCurTab('admin-logs');
this.adminLoginLogsView.show({'current_page': current_page});
},
showAbuseReports: function() {
this.switchCurrentView(this.abuseReportsView);
this.sideNavView.setCurTab('abuse-reports');
this.abuseReportsView.show();
}
});

View File

@@ -0,0 +1,89 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'moment',
'app/views/widgets/hl-item-view'
], function($, _, Backbone, Common, Moment, HLItemView) {
'use strict';
var AbuseReportView = HLItemView.extend({
tagName: 'tr',
template: _.template($('#abuse-report-item-tmpl').html()),
events: {
'click .abuse-report-handle': 'handleReport'
},
initialize: function() {
HLItemView.prototype.initialize.call(this);
this.listenTo(this.model, "change", this.render);
},
render: function() {
var data = this.model.toJSON(), abuse_type_output,
icon_size = Common.isHiDPI() ? 48 : 24,
icon_url = this.model.getIconUrl(icon_size),
time = Moment(data['time']);
if (data['abuse_type'] == 'copyright') {
abuse_type_output = gettext('Copyright infringement');
} else if (data['abuse_type'] == 'virus') {
abuse_type_output = gettext('Virus');
} else if (data['abuse_type'] == 'abuse_content') {
abuse_type_output = gettext('Abuse content');
} else if (data['abuse_type'] == 'other') {
abuse_type_output = gettext('Other');
}
data['time'] = time.format('LLLL');
data['time_from_now'] = Common.getRelativeTimeStr(time);
data['icon_url'] = icon_url;
data['abuse_type_output'] = abuse_type_output;
this.$el.html(this.template(data));
return this;
},
handleReport: function() {
var _this = this, handled_parameter,
report_id = this.model.get('id'),
handled = this.model.get('handled');
if (handled) {
handled_parameter = false;
} else {
handled_parameter = true;
}
$.ajax({
url: Common.getUrl({
'name':'admin-abuse-report',
'report_id': report_id
}),
type: 'PUT',
cache: false,
beforeSend: Common.prepareCSRFToken,
dataType: 'json',
data: {
'handled': handled_parameter
},
success: function() {
_this.model.set({'handled': handled_parameter});
Common.feedback(gettext("Successfully change the report's status."), 'success');
},
error: function(xhr, textStatus, errorThrown) {
Common.ajaxErrorHandler(xhr, textStatus, errorThrown);
}
});
return false;
}
});
return AbuseReportView;
});

View File

@@ -0,0 +1,87 @@
define([
'jquery',
'underscore',
'backbone',
'common',
'sysadmin-app/views/abuse-report',
'sysadmin-app/collection/abuse-reports'
], function($, _, Backbone, Common, AbuseReportView, AbuseReportsCollection) {
'use strict';
var AbuseReportsView = Backbone.View.extend({
id: 'admin-abuse-reports',
template: _.template($("#abuse-reports-tmpl").html()),
initialize: function() {
this.abuseReportsCollection = new AbuseReportsCollection();
this.listenTo(this.abuseReportsCollection, 'add', this.addOne);
this.listenTo(this.abuseReportsCollection, 'reset', this.reset);
this.render();
},
render: function() {
this.$el.html(this.template());
this.$table = this.$('table');
this.$tableBody = $('tbody', this.$table);
this.$loadingTip = this.$('.loading-tip');
this.$emptyTip = this.$('.empty-tips');
this.$error = this.$('.error');
},
initPage: function() {
this.$loadingTip.show();
this.$table.hide();
this.$tableBody.empty();
this.$emptyTip.hide();
this.$error.hide();
},
hide: function() {
this.$el.detach();
this.attached = false;
},
show: function() {
if (!this.attached) {
this.attached = true;
$("#right-panel").html(this.$el);
}
this.getContent();
},
getContent: function() {
this.initPage();
var _this = this;
this.abuseReportsCollection.fetch({
cache: false,
reset: true,
error: function(collection, response, opts) {
var err_msg = Common.prepareCollectionFetchErrorMsg(collection, response, opts);
_this.$error.html(err_msg).show();
}
})
},
addOne: function(report) {
var view = new AbuseReportView({model: report});
this.$tableBody.append(view.render().el);
},
reset: function() {
this.initPage();
this.$loadingTip.hide();
if (this.abuseReportsCollection.length > 0) {
this.abuseReportsCollection.each(this.addOne, this);
this.$table.show();
} else {
this.$emptyTip.show();
}
}
});
return AbuseReportsView;
});