Skip to content
Permalink
Browse files

chg: refactored deletion of accounts and sites

  • Loading branch information...
p3k committed May 21, 2018
1 parent a978ad7 commit c36302a83f9f6b347b06d0a13405c784b6a523f6
@@ -207,7 +207,7 @@
</div>
<div>
<% gettext '{0} sites sorted by {1} in {2} order.'
<% admin.dropdown name="display" <% markgettext all %> <% markgettext blocked %> <% markgettext trusted %> <% markgettext open %> <% markgettext restricted %> <% markgettext public %> <% markgettext closed %> <% markgettext deleted %> %>
<% admin.dropdown name="display" <% markgettext all %> <% markgettext deleted %> <% markgettext blocked %> <% markgettext trusted %> <% markgettext open %> <% markgettext restricted %> <% markgettext public %> <% markgettext closed %> %>
<% admin.dropdown name="sorting" <% markgettext modified %> <% markgettext created %> <% markgettext name %> %>
<% admin.dropdown name="order" <% markgettext descending %> <% markgettext ascending %> %>
%>
@@ -411,7 +411,7 @@
<div class='uk-badge uk-badge-success'><% gettext Trusted %></div>

<% #deletedSite %>
<i class='uk-icon-ban'></i>
<div class='uk-badge'><% gettext Deleted %></div>

<% #closedSite %>
<i class='uk-icon-lock'></i>
@@ -423,7 +423,7 @@
<i class='uk-icon-globe'></i>

<% #deletedUser %>
<div class='uk-badge'><% gettext Deleted %></div>
<div class='uk-badge uk-badge-warning'><% gettext Deleted %></div>

<% #blockedUser %>
<div class='uk-badge uk-badge-danger'><% gettext Blocked %></div>
@@ -146,10 +146,8 @@ Admin.dequeue = function() {
app.log('Processing queued job ' + (i + 1) + ' of ' + max);
switch (job.method) {
case 'remove':
if (job.target.deleted) {
if (job.target.constructor === Site) Site.remove.call(job.target);
if (job.target.constructor === User) User.remove.call(job.target);
}
if (job.target.constructor === Site) Site.remove.call(job.target);
if (job.target.constructor === User) User.remove.call(job.target);
break;
case 'import':
Importer.run(job.target, job.user);
@@ -179,21 +177,17 @@ Admin.purgeAccounts = function() {
var now = Date.now();

root.admin.deletedUsers.forEach(function() {
if (!this.deleted) return; // already gone
if (now - this.deleted > 0 && !this.job) {
this.job = Admin.queue(this, 'remove', this);
}
if (this.job || this.deleted) return; // already gone
this.job = Admin.queue(this, 'remove', this);
});
};

Admin.purgeSites = function() {
var now = new Date;

root.admin.deletedSites.forEach(function() {
if (!this.deleted) return;
if (now > this.deleted > 0 && !this.job) {
this.job = Admin.queue(this, 'remove', this.modifier);
}
if (this.job) return;
this.job = Admin.queue(this, 'remove', this.modifier);
});

var notificationPeriod = root.phaseOutNotificationPeriod * Date.ONEDAY;
@@ -217,7 +211,7 @@ Admin.purgeSites = function() {
});
this.notified = now;
} else if (now - this.notified > gracePeriod) {
this.mode = Site.DELETED;
this.status = Site.DELETED;
this.deleted = now;
this.notified = null;
}
@@ -639,12 +633,12 @@ Admin.prototype.filterSites = function(data) {

var displays = {
1: "status = 'blocked'",
2: "status = 'trusted'",
3: "mode = 'open'",
4: "mode = 'restricted'",
5: "mode = 'public'",
6: "mode = 'closed'",
7: "mode = 'deleted'"
2: "status = 'deleted'",
3: "status = 'trusted'",
4: "mode = 'open'",
5: "mode = 'restricted'",
6: "mode = 'public'",
7: "mode = 'closed'"
};

var sortings = {
@@ -812,7 +806,7 @@ Admin.prototype.renderActivity = function (item, skin) {
case User:
return item.status !== User.BLOCKED && item.status !== User.DELETED && item.created - item.modified < 1;
case Site:
return item.mode !== Site.DELETED && item.created - item.modified < 1;
return item.status !== Site.DELETED && item.created - item.modified < 1;
}
return false;
}
@@ -905,15 +899,15 @@ Admin.prototype.link_macro = function (param, action, text, target) {
switch (action) {
case 'block':
var user = target.creator || target;
if (user.status !== User.PRIVILEGED && user.status !== User.BLOCKED && (user.status !== User.DELETED || user.deleted)) {
if (user.status !== User.PRIVILEGED && user.status !== User.BLOCKED && user.status !== User.DELETED) {
var url = user.href('block');
return renderLink.call(global, param, url, text || String.EMPTY, this);
}
break;

case 'delete':
var site = target.constructor === Site ? target : target.site;
if (site && site.getPermission(action) && site.mode !== Site.DELETED) {
if (site && site.getPermission(action) && site.status !== Site.DELETED) {
var url = site.href('delete') + '?safemode';
return renderLink.call(global, param, url, text || String.EMPTY, this);
}
@@ -28,7 +28,7 @@ restrictedSites = collection(Site)
restrictedSites.filter = mode = 'restricted' and status <> 'blocked'

deletedSites = collection(Site)
deletedSites.filter = mode = 'deleted'
deletedSites.filter = status = 'deleted'
deletedSites.order = modified desc

users = collection(User)
@@ -235,7 +235,7 @@ Comment.prototype.getConfirmText = function() {
if (this.status === Comment.DELETED && size > 1) {
return gettext('You are about to delete a comment thread consisting of {0} postings.', size);
}
return gettext('You are about to delete a comment by user {0}.', this.creator.name);
return gettext('You are about to delete a comment by {0}.', this.creator.name);
};

Comment.prototype.getConfirmExtra = function () {
@@ -36,7 +36,7 @@
<div class="uk-width-1-1 av-upload-controls">
<input class='uk-width-1-2' type="text" value="<% param.value %>">
<button class='uk-button' id="<% param.name %>_control" name="<% param.name %>_control" type="button">
<% gettext "Browse" suffix=… %>
<% gettext "Select" suffix=… %>
</button>
</div>
</div>
@@ -109,7 +109,7 @@ HopObject.prototype.onRequest = function() {
res.handlers.membership = User.getMembership();

// Logout persisting session if account has been deleted
if (User.getCurrentStatus() === User.DELETED && !session.user.deleted) {
if (User.getCurrentStatus() === User.DELETED) {
User.logout();
}

@@ -124,7 +124,7 @@ HopObject.prototype.onRequest = function() {

if (!User.require(User.PRIVILEGED)) {
// Simulate 404 for sites which are due for deletion by cronjob
if (res.handlers.site.mode === Site.DELETED) {
if (res.handlers.site.status === Site.DELETED) {
res.handlers.site = root;
root.notfound_action();
res.stop();
@@ -143,7 +143,6 @@ HopObject.prototype.onRequest = function() {
HopObject.confirmConstructor(Layout);
res.handlers.layout = res.handlers.site.layout || new Layout;
res.skinpath = res.handlers.layout.getSkinPath();
//res.skinpath = [app.dir];

if (!this.getPermission(req.action)) {
if (!session.user) {
@@ -177,6 +176,7 @@ markgettext('Image');
markgettext('Membership');
markgettext('Poll');
markgettext('Story');
markgettext('User');

HopObject.prototype.delete_action = function() {
if (req.postParams.proceed) {
@@ -118,11 +118,11 @@ Members.prototype.reset_action = function() {
if (req.postParams.reset) {
try {
if (!req.postParams.name || !req.postParams.email) {
throw Error(gettext('Please enter a user name and e-mail address.'));
throw Error(gettext('Please enter a username and e-mail address.'));
}
var user = User.getByName(req.postParams.name);
if (!user || user.email !== req.postParams.email) {
throw Error(gettext('User name and e-mail address do not match.'))
throw Error(gettext('Username and e-mail address do not match.'))
}
var token = User.getSalt();
user.setMetadata('resetToken', token);
@@ -409,7 +409,7 @@ Members.prototype.search = function(searchString, limit) {
Members.prototype.addMembership = function(data) {
var user = root.users.get(data.name);
if (!user) {
throw Error(gettext('Sorry, your input did not match any registered user.'));
throw Error(gettext('Sorry, your input did not match any registered account.'));
/*} else if (this.get(data.name)) {
throw Error(gettext('This user is already a member of this site.'));*/
}
@@ -194,8 +194,8 @@ Membership.prototype.contact_action = function() {
}
Recaptcha.verify(req.postParams);
this.notify(req.action, this.creator.email, session.user ?
gettext('[{0}] Message from user {1}', root.title, session.user.name) :
gettext('[{0}] Message from anonymous user', root.title));
gettext('[{0}] Message from {1}', root.title, session.user.name) :
gettext('[{0}] Message from anonymous', root.title));
res.message = gettext('Your message was sent successfully.');
res.redirect(this._parent.getPermission() ?
this._parent.href() : this.site.href());
@@ -274,7 +274,7 @@ Membership.prototype.notify = function(action, recipient, subject) {
* @returns {String}
*/
Membership.prototype.getConfirmText = function() {
return gettext('You are about to delete the membership of user {0}.',
return gettext('You are about to delete the membership of {0}.',
this.creator.name);
}

@@ -1185,15 +1185,6 @@ a.gs-title:hover {
</td>
</tr>

<% #deleted %>
<h1><% gettext 'Deleted Site' %></h1>
<p>
<% gettext "This site is scheduled for deletion." %>
</p>
<div class='uk-alert'>
<% gettext 'You still can revert the request for deletion in the {0}site settings{1}.' <% site.href edit prefix='<a href="' suffix='">' %> '</a>' %>
</div>

<% #export %>
<h1><% gettext "Export Site Data" %></h1>
<p>
@@ -29,7 +29,6 @@ this.handleMetadata('callbackUrl');
this.handleMetadata('closed');
this.handleMetadata('commentMode');
this.handleMetadata('configured');
this.handleMetadata('deleted');
this.handleMetadata('export');
this.handleMetadata('imageDimensionLimits');
this.handleMetadata('import_id');
@@ -51,23 +50,21 @@ this.handleMetadata('trollFilter');
* @returns {String[]}
* @see defineConstants
*/
Site.getStatus = defineConstants(Site, markgettext('Blocked'),
Site.getStatus = defineConstants(Site, markgettext('Deleted'), markgettext('Blocked'),
markgettext('Regular'), markgettext('Trusted'));
/**
* @function
* @returns {String[]}
* @see defineConstants
*/
Site.getModes = defineConstants(Site, markgettext('Deleted'),
markgettext('Closed'), markgettext('Restricted'),
Site.getModes = defineConstants(Site, markgettext('Closed'), markgettext('Restricted'),
markgettext('Public'), markgettext('Open'));
/**
* @function
* @returns {String[]}
* @see defineConstants
*/
Site.getPageModes = defineConstants(Site, markgettext('days') /* ,
markgettext('stories') */ );
Site.getPageModes = defineConstants(Site, markgettext('days')/*, markgettext('stories') */ );
/**
* @function
* @returns {String[]}
@@ -98,13 +95,6 @@ Site.getNotificationModes = defineConstants(Site, markgettext('Nobody'),
Site.getCallbackModes = defineConstants(Site, markgettext('disabled'),
markgettext('enabled'));

/**
*
*/
Site.getDeletionDate = function() {
return new Date(Date.now() + Date.ONEDAY * 0);
};

/**
* @param {String} name A unique identifier also used in the URL of a site
* @param {String} title An arbitrary string branding a site
@@ -225,7 +215,6 @@ Site.require = function(mode) {
* @property {String} commentMode The way comments of a site are displayed
* @property {Date} created The date and time of site creation
* @property {User} creator A reference to a user who created a site
* @property {Date} deleted
* @property {String} export
* @property {Files} files
* @property {Tags} galleries
@@ -292,7 +281,7 @@ Site.prototype.getPermission = function(action) {
User.require(User.PRIVILEGED);

case 'delete':
return this !== root && this.getPermission('edit');
return this !== root && this.status !== Site.DELETED && this.getPermission('edit');

case 'edit':
case 'export':
@@ -321,7 +310,7 @@ Site.prototype.main_action = function() {
schema: 'http://schema.org/WebSite',
title: this.getTitle(),
description: this.tagline || String.EMPTY,
body: this.renderSkinAsString(this.mode === Site.DELETED ? '$Site#deleted' : 'Site#main'),
body: this.renderSkinAsString('Site#main'),
images: [(this.layout.images.get('favicon') || Images.Default['favicon.png']).getUrl()],
links: this.renderSkinAsString('$Site#links')
});
@@ -355,16 +344,15 @@ Site.prototype.delete_action = function () {
HopObject.prototype.delete_action.call(this);
} else {
// Otherwise, queue for deletion
this.deleted = Site.getDeletionDate();
this.mode = Site.DELETED;
res.message = gettext('The site {0} is queued for deletion.', this.name);
this.status = Site.DELETED;
res.message = gettext('The site {0} is being deleted.', this.name);
}
this.log(root, 'Deleted site ' + this.name);
res.redirect(this.href());
res.redirect(root.href());
} else {
HopObject.prototype.delete_action.call(this);
}
}
};

/**
*
@@ -428,8 +416,10 @@ Site.prototype.getConfirmExtra = function () {
* @param {Object} data
*/
Site.prototype.update = function(data) {
if (this.mode !== data.mode) {
this.deleted = data.mode === Site.DELETED ? new Date() : null;
// Remove the corresponding job if site deletion is cancelled
if (this.job && this.status === Site.DELETED && this.status !== data.status) {
let job = new Admin.Job(this.job);
if (job.method === 'remove') job.remove();
}

data.maxImageWidth = Math.abs(data.maxImageWidth) || Infinity;
@@ -788,6 +788,6 @@ Story.prototype.markdown_filter = function (value, param) {
* @returns {String}
*/
Story.prototype.getConfirmText = function() {
return gettext("You are about to delete a story by user {0}.",
return gettext("You are about to delete a story by {0}.",
this.creator ? this.creator.name : 'null');
}
@@ -45,7 +45,7 @@
<% #edit %>
<h1><% response.title %></h1>
<div class='uk-article-meta'>
<% if <% user.status %> is 'deleted' then <% user.skin $User#deleted %> else <% user.skin $User#meta %> %>
<% if <% user.status %> is deleted then <% user.skin $User#deleted %> else <% user.skin $User#meta %> %>
</div>
<div class='uk-margin-top uk-margin-bottom'>
<% context.link timeline <% gettext Timeline %> %> |
@@ -75,7 +75,7 @@
<div class='uk-form-row'>
<label class='uk-form-label' for='url'>
<% gettext "Personal URL" %>
<i class='uk-icon-info-circle uk-text-muted' title='<% gettext "If you enter a URL here your user name will appear as link next to your posted items." %>' data-uk-tooltip="{pos: 'right'}"></i>
<i class='uk-icon-info-circle uk-text-muted' title='<% gettext "If you enter a URL here your username will appear as link next to your posted items." %>' data-uk-tooltip="{pos: 'right'}"></i>
</label>
<div class='uk-form-controls'>
<% user.input url type=url class='uk-form uk-width-2-3' %>
@@ -199,11 +199,9 @@

<% #deleted %>
<% if <% user.deleted %> is null then
<% gettext 'Deleted on {0}' <% user.created short %> %>
<% gettext 'Account is being deleted' %>
else
<% gettext 'Scheduled for deletion {0}' <% user.deleted | format expiry %>
suffix=<% context.link 'edit?undelete=1' <% gettext "Click to cancel deletion" prefix="<i class='uk-icon-times-circle uk-margin-small-left' data-uk-tooltip=\"{pos: 'right'}\" title='" suffix="'></i>" %> %>
%>
<% gettext 'Deleted on {0}' <% user.created short %> %>
%>

<% #notify_reset %>

0 comments on commit c36302a

Please sign in to comment.
You can’t perform that action at this time.