Class: Ish::UserProfile

Inherits:
Object
  • Object
show all
Includes:
Utils, Mongoid::Document, Mongoid::Timestamps, Mongoid::Voter
Defined in:
lib/ish/user_profile.rb

Overview

It explicitly doesn’t have a relation to user! Use email as key.

Constant Summary collapse

ROLES =
[ :guy, :manager, :admin ]
ROLE_GUY =
:guy
ROLE_MANAGER =
:manager
ROLE_ADMIN =
:admin

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils

#export

Methods included from Mongoid::Voter

#unvote, #vote, #vote_value, #voted?, #votees

Class Method Details

.generate(delta) ⇒ Object

used in rake tasks



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/ish/user_profile.rb', line 86

def self.generate delta
  email = delta[:email]
  password = delta[:password]
  role_name = delta[:role_name]

  profile = Ish::UserProfile.where( email: email ).first
  if profile
    return
  end

  user = User.where( email: email ).first
  if !user
    user = User.new({ email: email, password: password })
  end
  profile = Ish::UserProfile.new({
    email: email,
    role_name: role_name,
  })
  profile.save

  if profile.persisted?
    ;
  else
    puts! profile.errors.full_messages, "Cannot save profile"
  end
end

.listObject



63
64
65
66
# File 'lib/ish/user_profile.rb', line 63

def self.list
  out = self.all
  [['', nil]] + out.map { |item| [ item.email, item.id ] }
end

.list_lgObject



67
68
69
70
# File 'lib/ish/user_profile.rb', line 67

def self.list_lg
  out = self.all
  [['', nil]] + out.map { |item| [ "#{item.email} :: #{item.name}", item.id ] }
end

Instance Method Details

#export_fieldsObject



23
24
25
26
27
28
# File 'lib/ish/user_profile.rb', line 23

def export_fields
  %w|
    email
    role_name
  |
end

#has_premium_purchase(item) ⇒ Object



76
77
78
# File 'lib/ish/user_profile.rb', line 76

def has_premium_purchase item
  payments.confirmed.where( item: item ).exists?
end

#sudoer?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/ish/user_profile.rb', line 59

def sudoer?
  %w( [email protected] [email protected] ).include?( self.email )
end