Class: AnonymousShadowCreator

Inherits:
Object
  • Object
show all
Defined in:
app/services/anonymous_shadow_creator.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user) ⇒ AnonymousShadowCreator

Returns a new instance of AnonymousShadowCreator.



14
15
16
# File 'app/services/anonymous_shadow_creator.rb', line 14

def initialize(user)
  @user = user
end

Instance Attribute Details

#userObject (readonly)

Returns the value of attribute user.



4
5
6
# File 'app/services/anonymous_shadow_creator.rb', line 4

def user
  @user
end

Class Method Details

.get(user) ⇒ Object



10
11
12
# File 'app/services/anonymous_shadow_creator.rb', line 10

def self.get(user)
  new(user).get
end

.get_master(user) ⇒ Object



6
7
8
# File 'app/services/anonymous_shadow_creator.rb', line 6

def self.get_master(user)
  new(user).get_master
end

Instance Method Details

#getObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'app/services/anonymous_shadow_creator.rb', line 25

def get
  return unless user
  return unless SiteSetting.allow_anonymous_posting
  return if user.trust_level < SiteSetting.anonymous_posting_min_trust_level
  return if SiteSetting.must_approve_users? && !user.approved?

  shadow = user.shadow_user

  if shadow && (shadow.post_count + shadow.topic_count) > 0 && shadow.last_posted_at &&
       shadow.last_posted_at < SiteSetting..minutes.ago
    shadow = nil
  end

  shadow || create_shadow!
end

#get_masterObject



18
19
20
21
22
23
# File 'app/services/anonymous_shadow_creator.rb', line 18

def get_master
  return unless user
  return unless SiteSetting.allow_anonymous_posting

  user.master_user
end