diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rb
index 6d3df8a18ea..77ea2653a22 100644
--- a/app/controllers/admin/users_controller.rb
+++ b/app/controllers/admin/users_controller.rb
@@ -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)
diff --git a/app/models/user.rb b/app/models/user.rb
index fb9f8916dc9..93b7d21a8bb 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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
diff --git a/app/serializers/admin_user_serializer.rb b/app/serializers/admin_user_serializer.rb
index dc13d502081..b9d23a474c6 100644
--- a/app/serializers/admin_user_serializer.rb
+++ b/app/serializers/admin_user_serializer.rb
@@ -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
diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml
index f7ba5a66e78..32023e52283 100644
--- a/config/locales/client.en.yml
+++ b/config/locales/client.en.yml
@@ -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."
diff --git a/config/routes.rb b/config/routes.rb
index ac02614b0bd..f70bb870cf1 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -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
diff --git a/lib/guardian.rb b/lib/guardian.rb
index 936f4ba3473..bee794c109d 100644
--- a/lib/guardian.rb
+++ b/lib/guardian.rb
@@ -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?