mirror of
https://github.com/discourse/discourse.git
synced 2025-04-01 09:35:58 +08: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
app
assets/javascripts/admin
controllers/admin
models
serializers
config
lib
@ -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() {
|
deleteForbidden: function() {
|
||||||
return (this.get('post_count') > 0);
|
return (this.get('post_count') > 0);
|
||||||
}.property('post_count'),
|
}.property('post_count'),
|
||||||
|
@ -68,6 +68,37 @@
|
|||||||
</div>
|
</div>
|
||||||
</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='display-row'>
|
||||||
<div class='field'>{{i18n admin.user.admin}}</div>
|
<div class='field'>{{i18n admin.user.admin}}</div>
|
||||||
<div class='value'>{{content.admin}}</div>
|
<div class='value'>{{content.admin}}</div>
|
||||||
|
@ -102,6 +102,20 @@ class Admin::UsersController < Admin::AdminController
|
|||||||
render nothing: true
|
render nothing: true
|
||||||
end
|
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
|
def destroy
|
||||||
user = User.where(id: params[:id]).first
|
user = User.where(id: params[:id]).first
|
||||||
guardian.ensure_can_delete_user!(user)
|
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?
|
email_tokens.where(email: email, confirmed: true).present? || email_tokens.empty?
|
||||||
end
|
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
|
def treat_as_new_topic_start_date
|
||||||
duration = new_topic_duration_minutes || SiteSetting.new_topic_duration_minutes
|
duration = new_topic_duration_minutes || SiteSetting.new_topic_duration_minutes
|
||||||
case duration
|
case duration
|
||||||
|
@ -21,7 +21,10 @@ class AdminUserSerializer < BasicUserSerializer
|
|||||||
:banned_at,
|
:banned_at,
|
||||||
:banned_till,
|
:banned_till,
|
||||||
:is_banned,
|
:is_banned,
|
||||||
:ip_address
|
:ip_address,
|
||||||
|
:can_send_activation_email,
|
||||||
|
:can_activate,
|
||||||
|
:can_deactivate
|
||||||
|
|
||||||
def is_banned
|
def is_banned
|
||||||
object.is_banned?
|
object.is_banned?
|
||||||
@ -62,4 +65,16 @@ class AdminUserSerializer < BasicUserSerializer
|
|||||||
SiteSetting.must_approve_users
|
SiteSetting.must_approve_users
|
||||||
end
|
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
|
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!"
|
delete_confirm: "Are you SURE you want to permanently delete this user from the site? This action is permanent!"
|
||||||
deleted: "The user was deleted."
|
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."
|
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:
|
site_content:
|
||||||
none: "Choose a type of content to begin editing."
|
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 'grant_moderation', constraints: AdminConstraint.new
|
||||||
put 'approve'
|
put 'approve'
|
||||||
post 'refresh_browsers', constraints: AdminConstraint.new
|
post 'refresh_browsers', constraints: AdminConstraint.new
|
||||||
|
put 'activate'
|
||||||
|
put 'deactivate'
|
||||||
end
|
end
|
||||||
|
|
||||||
resources :impersonate, constraints: AdminConstraint.new
|
resources :impersonate, constraints: AdminConstraint.new
|
||||||
|
@ -58,6 +58,7 @@ class Guardian
|
|||||||
end
|
end
|
||||||
alias :can_move_posts? :can_moderate?
|
alias :can_move_posts? :can_moderate?
|
||||||
alias :can_see_flags? :can_moderate?
|
alias :can_see_flags? :can_moderate?
|
||||||
|
alias :can_send_activation_email? :can_moderate?
|
||||||
|
|
||||||
# Can the user create a topic in the forum
|
# Can the user create a topic in the forum
|
||||||
def can_create?(klass, parent=nil)
|
def can_create?(klass, parent=nil)
|
||||||
@ -105,6 +106,7 @@ class Guardian
|
|||||||
return false if target.approved?
|
return false if target.approved?
|
||||||
@user.staff?
|
@user.staff?
|
||||||
end
|
end
|
||||||
|
alias :can_activate? :can_approve?
|
||||||
|
|
||||||
def can_ban?(user)
|
def can_ban?(user)
|
||||||
return false if user.blank?
|
return false if user.blank?
|
||||||
@ -112,6 +114,7 @@ class Guardian
|
|||||||
return false if user.admin?
|
return false if user.admin?
|
||||||
true
|
true
|
||||||
end
|
end
|
||||||
|
alias :can_deactivate? :can_ban?
|
||||||
|
|
||||||
def can_clear_flags?(post)
|
def can_clear_flags?(post)
|
||||||
return false if @user.blank?
|
return false if @user.blank?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user