mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 17:06:31 -06:00
Add ability for admins and mods to send another activation email to a user, to activate an account, and deactivate an account
This commit is contained in:
parent
6b536dcde5
commit
f35a44aeae
@ -127,6 +127,39 @@ Discourse.AdminUser = Discourse.User.extend({
|
||||
});
|
||||
},
|
||||
|
||||
activate: function() {
|
||||
Discourse.ajax('/admin/users/' + this.id + '/activate', {type: 'PUT'}).then(function() {
|
||||
// succeeded
|
||||
window.location.reload();
|
||||
}, function(e) {
|
||||
// failed
|
||||
var error = Em.String.i18n('admin.user.activate_failed', { error: "http: " + e.status + " - " + e.body });
|
||||
bootbox.alert(error);
|
||||
});
|
||||
},
|
||||
|
||||
deactivate: function() {
|
||||
Discourse.ajax('/admin/users/' + this.id + '/deactivate', {type: 'PUT'}).then(function() {
|
||||
// succeeded
|
||||
window.location.reload();
|
||||
}, function(e) {
|
||||
// failed
|
||||
var error = Em.String.i18n('admin.user.deactivate_failed', { error: "http: " + e.status + " - " + e.body });
|
||||
bootbox.alert(error);
|
||||
});
|
||||
},
|
||||
|
||||
sendActivationEmail: function() {
|
||||
Discourse.ajax('/users/' + this.get('username') + '/send_activation_email').then(function() {
|
||||
// succeeded
|
||||
bootbox.alert( Em.String.i18n('admin.user.activation_email_sent') );
|
||||
}, function(e) {
|
||||
// failed
|
||||
var error = Em.String.i18n('admin.user.send_activation_email_failed', { error: "http: " + e.status + " - " + e.body });
|
||||
bootbox.alert(error);
|
||||
});
|
||||
},
|
||||
|
||||
deleteForbidden: function() {
|
||||
return (this.get('post_count') > 0);
|
||||
}.property('post_count'),
|
||||
|
@ -68,6 +68,37 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='display-row'>
|
||||
<div class='field'>{{i18n admin.users.active}}</div>
|
||||
<div class='value'>
|
||||
{{#if content.active}}
|
||||
{{i18n yes_value}}
|
||||
{{else}}
|
||||
{{i18n no_value}}
|
||||
{{/if}}
|
||||
</div>
|
||||
<div class='controls'>
|
||||
{{#if content.active}}
|
||||
{{#if content.can_deactivate}}
|
||||
<button class='btn' {{action deactivate target="content"}}>{{i18n admin.user.deactivate_account}}</button>
|
||||
{{/if}}
|
||||
{{else}}
|
||||
{{#if content.can_send_activation_email}}
|
||||
<button class='btn' {{action sendActivationEmail target="content"}}>
|
||||
<i class='icon icon-envelope-alt'></i>
|
||||
{{i18n admin.user.send_activation_email}}
|
||||
</button>
|
||||
{{/if}}
|
||||
{{#if content.can_activate}}
|
||||
<button class='btn' {{action activate target="content"}}>
|
||||
<i class='icon icon-ok'></i>
|
||||
{{i18n admin.user.activate}}
|
||||
</button>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class='display-row'>
|
||||
<div class='field'>{{i18n admin.user.admin}}</div>
|
||||
<div class='value'>{{content.admin}}</div>
|
||||
|
@ -102,6 +102,20 @@ class Admin::UsersController < Admin::AdminController
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
def activate
|
||||
@user = User.where(id: params[:user_id]).first
|
||||
guardian.ensure_can_activate!(@user)
|
||||
@user.activate
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
def deactivate
|
||||
@user = User.where(id: params[:user_id]).first
|
||||
guardian.ensure_can_deactivate!(@user)
|
||||
@user.deactivate
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
def destroy
|
||||
user = User.where(id: params[:id]).first
|
||||
guardian.ensure_can_delete_user!(user)
|
||||
|
@ -491,6 +491,21 @@ class User < ActiveRecord::Base
|
||||
email_tokens.where(email: email, confirmed: true).present? || email_tokens.empty?
|
||||
end
|
||||
|
||||
def activate
|
||||
email_token = self.email_tokens.active.first
|
||||
if email_token
|
||||
EmailToken.confirm(email_token.token)
|
||||
else
|
||||
self.active = true
|
||||
save
|
||||
end
|
||||
end
|
||||
|
||||
def deactivate
|
||||
self.active = false
|
||||
save
|
||||
end
|
||||
|
||||
def treat_as_new_topic_start_date
|
||||
duration = new_topic_duration_minutes || SiteSetting.new_topic_duration_minutes
|
||||
case duration
|
||||
|
@ -21,7 +21,10 @@ class AdminUserSerializer < BasicUserSerializer
|
||||
:banned_at,
|
||||
:banned_till,
|
||||
:is_banned,
|
||||
:ip_address
|
||||
:ip_address,
|
||||
:can_send_activation_email,
|
||||
:can_activate,
|
||||
:can_deactivate
|
||||
|
||||
def is_banned
|
||||
object.is_banned?
|
||||
@ -62,4 +65,16 @@ class AdminUserSerializer < BasicUserSerializer
|
||||
SiteSetting.must_approve_users
|
||||
end
|
||||
|
||||
def can_send_activation_email
|
||||
scope.can_send_activation_email?(object)
|
||||
end
|
||||
|
||||
def can_activate
|
||||
scope.can_activate?(object)
|
||||
end
|
||||
|
||||
def can_deactivate
|
||||
scope.can_deactivate?(object)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -995,6 +995,13 @@ en:
|
||||
delete_confirm: "Are you SURE you want to permanently delete this user from the site? This action is permanent!"
|
||||
deleted: "The user was deleted."
|
||||
delete_failed: "There was an error deleting that user. Make sure all posts are deleted before trying to delete the user."
|
||||
send_activation_email: "Send Activation Email"
|
||||
activation_email_sent: "An activation email has been sent."
|
||||
send_activation_email_failed: "There was a problem sending another activation email."
|
||||
activate: "Activate Account"
|
||||
activate_failed: "There was a problem activating the user."
|
||||
deactivate_account: "Deactivate Account"
|
||||
deactivate_failed: "There was a problem deactivating the user."
|
||||
|
||||
site_content:
|
||||
none: "Choose a type of content to begin editing."
|
||||
|
@ -50,6 +50,8 @@ Discourse::Application.routes.draw do
|
||||
put 'grant_moderation', constraints: AdminConstraint.new
|
||||
put 'approve'
|
||||
post 'refresh_browsers', constraints: AdminConstraint.new
|
||||
put 'activate'
|
||||
put 'deactivate'
|
||||
end
|
||||
|
||||
resources :impersonate, constraints: AdminConstraint.new
|
||||
|
@ -58,6 +58,7 @@ class Guardian
|
||||
end
|
||||
alias :can_move_posts? :can_moderate?
|
||||
alias :can_see_flags? :can_moderate?
|
||||
alias :can_send_activation_email? :can_moderate?
|
||||
|
||||
# Can the user create a topic in the forum
|
||||
def can_create?(klass, parent=nil)
|
||||
@ -105,6 +106,7 @@ class Guardian
|
||||
return false if target.approved?
|
||||
@user.staff?
|
||||
end
|
||||
alias :can_activate? :can_approve?
|
||||
|
||||
def can_ban?(user)
|
||||
return false if user.blank?
|
||||
@ -112,6 +114,7 @@ class Guardian
|
||||
return false if user.admin?
|
||||
true
|
||||
end
|
||||
alias :can_deactivate? :can_ban?
|
||||
|
||||
def can_clear_flags?(post)
|
||||
return false if @user.blank?
|
||||
|
Loading…
Reference in New Issue
Block a user