mirror of
https://github.com/discourse/discourse.git
synced 2025-03-26 05:25:52 +08:00
human?
helper method on a user
This is cleaner than hard coding `id > 0` in ruby code.
This commit is contained in:
parent
fb18c57372
commit
c719658f9f
app
lib
plugins/discourse-narrative-bot
spec/models
@ -329,7 +329,7 @@ class SessionController < ApplicationController
|
|||||||
RateLimiter.new(nil, "forgot-password-login-min-#{params[:login].to_s[0..100]}", 3, 1.minute).performed!
|
RateLimiter.new(nil, "forgot-password-login-min-#{params[:login].to_s[0..100]}", 3, 1.minute).performed!
|
||||||
|
|
||||||
user = User.find_by_username_or_email(params[:login])
|
user = User.find_by_username_or_email(params[:login])
|
||||||
user_presence = user.present? && user.id > 0 && !user.staged
|
user_presence = user.present? && user.human? && !user.staged
|
||||||
if user_presence
|
if user_presence
|
||||||
email_token = user.email_tokens.create(email: user.email)
|
email_token = user.email_tokens.create(email: user.email)
|
||||||
Jobs.enqueue(:critical_user_email, type: :forgot_password, user_id: user.id, email_token: email_token.token)
|
Jobs.enqueue(:critical_user_email, type: :forgot_password, user_id: user.id, email_token: email_token.token)
|
||||||
|
@ -291,6 +291,10 @@ class User < ActiveRecord::Base
|
|||||||
fields.uniq
|
fields.uniq
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def human?
|
||||||
|
self.id > 0
|
||||||
|
end
|
||||||
|
|
||||||
def effective_locale
|
def effective_locale
|
||||||
if SiteSetting.allow_user_locale && self.locale.present?
|
if SiteSetting.allow_user_locale && self.locale.present?
|
||||||
self.locale
|
self.locale
|
||||||
|
@ -226,7 +226,7 @@ class PostDestroyer
|
|||||||
end
|
end
|
||||||
|
|
||||||
def agree_with_flags
|
def agree_with_flags
|
||||||
if @post.has_active_flag? && @user.id > 0 && @user.staff?
|
if @post.has_active_flag? && @user.human? && @user.staff?
|
||||||
Jobs.enqueue(
|
Jobs.enqueue(
|
||||||
:send_system_message,
|
:send_system_message,
|
||||||
user_id: @post.user_id,
|
user_id: @post.user_id,
|
||||||
|
@ -154,7 +154,7 @@ after_initialize do
|
|||||||
|
|
||||||
self.add_to_class(:user, :enqueue_narrative_bot_job?) do
|
self.add_to_class(:user, :enqueue_narrative_bot_job?) do
|
||||||
SiteSetting.discourse_narrative_bot_enabled &&
|
SiteSetting.discourse_narrative_bot_enabled &&
|
||||||
self.id > 0 &&
|
self.human? &&
|
||||||
!self.anonymous? &&
|
!self.anonymous? &&
|
||||||
!self.staged &&
|
!self.staged &&
|
||||||
!SiteSetting.discourse_narrative_bot_ignored_usernames.split('|'.freeze).include?(self.username)
|
!SiteSetting.discourse_narrative_bot_ignored_usernames.split('|'.freeze).include?(self.username)
|
||||||
|
@ -1989,4 +1989,14 @@ describe User do
|
|||||||
expect(PostAction.with_deleted.where(user_id: user.id).length).to eq(0)
|
expect(PostAction.with_deleted.where(user_id: user.id).length).to eq(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "human?" do
|
||||||
|
it "returns true for a regular user" do
|
||||||
|
expect(Fabricate(:user)).to be_human
|
||||||
|
end
|
||||||
|
|
||||||
|
it "returns false for the system user" do
|
||||||
|
expect(Discourse.system_user).not_to be_human
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user