Class: User

Inherits:
Object
  • Object
show all
Includes:
GDS::SSO::User, Mongoid::Document, Mongoid::Timestamps
Defined in:
app/models/user.rb

Constant Summary collapse

GOVSPEAK_FIELDS =
[]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.collection_nameObject

Let an app configure the collection name to use, e.g. set a constant in an initializer



13
14
15
# File 'app/models/user.rb', line 13

def self.collection_name
  defined?(USER_COLLECTION_NAME) ? USER_COLLECTION_NAME : "users"
end

Instance Method Details

#assign(edition, recipient) ⇒ Object



78
79
80
# File 'app/models/user.rb', line 78

def assign(edition, recipient)
  GovukContentModels::ActionProcessors::AssignProcessor.new(self, edition, { recipient_id: recipient.id }).processed_edition
end

#create_edition(format, attributes = {}) ⇒ Object



70
71
72
# File 'app/models/user.rb', line 70

def create_edition(format, attributes = {})
  GovukContentModels::ActionProcessors::CreateEditionProcessor.new(self, nil, {}, { format: format, edition_attributes: attributes }).processed_edition
end

#gravatar_url(opts = {}) ⇒ Object



45
46
47
48
49
50
51
52
# File 'app/models/user.rb', line 45

def gravatar_url(opts = {})
  opts.symbolize_keys!
  "%s.gravatar.com/avatar/%s%s" % [
    opts[:ssl] ? "https://secure" : "http://www",
    Digest::MD5.hexdigest(email.downcase),
    opts[:s] ? "?s=#{CGI.escape(opts[:s])}" : ""
  ]
end

#new_version(edition, convert_to = nil) ⇒ Object



74
75
76
# File 'app/models/user.rb', line 74

def new_version(edition, convert_to = nil)
  GovukContentModels::ActionProcessors::NewVersionProcessor.new(self, edition, {}, { convert_to: convert_to }).processed_edition
end

#progress(edition, action_attributes) ⇒ Object



54
55
56
57
58
59
60
# File 'app/models/user.rb', line 54

def progress(edition, action_attributes)
  request_type = action_attributes.delete(:request_type)

  processor = GovukContentModels::ActionProcessors::REQUEST_TYPE_TO_PROCESSOR[request_type.to_sym]
  edition = GovukContentModels::ActionProcessors::const_get(processor).new(self, edition, action_attributes, {}).processed_edition
  edition.save if edition
end

#record_note(edition, comment, type = Action::NOTE) ⇒ Object



62
63
64
# File 'app/models/user.rb', line 62

def record_note(edition, comment, type = Action::NOTE)
  edition.new_action(self, type, comment: comment)
end

#resolve_important_note(edition) ⇒ Object



66
67
68
# File 'app/models/user.rb', line 66

def resolve_important_note(edition)
  record_note(edition, nil, Action::IMPORTANT_NOTE_RESOLVED)
end

#to_sObject



41
42
43
# File 'app/models/user.rb', line 41

def to_s
  name || email || ""
end

#unassign(edition) ⇒ Object



82
83
84
# File 'app/models/user.rb', line 82

def unassign(edition)
  GovukContentModels::ActionProcessors::AssignProcessor.new(self, edition).processed_edition
end