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

ROLE_GUY =
:guy
ROLE_MANAGER =
:manager
ROLE_ADMIN =
:admin
ROLES =
[ :guy, :manager, :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



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# File 'lib/ish/user_profile.rb', line 115

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



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

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

.list_lgObject



80
81
82
83
# File 'lib/ish/user_profile.rb', line 80

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

Instance Method Details

#customer_idObject



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ish/user_profile.rb', line 98

def customer_id
  if !self[:customer_id]
    # return nil if !email
    existing = Stripe::Customer.search({ query: "email: '#{email}'" })
    # puts! existing, 'existing'
    if existing.data.present?
      update_attributes( customer_id: existing.data[0][:id] )
    else
      customer = Stripe::Customer.create({ email: email })
      # puts! customer, 'customer'
      update_attributes( customer_id: customer[:id] )
    end
  end
  self[:customer_id]
end

#export_fieldsObject



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

def export_fields
  %w|
    email
    role_name
  |
end

#has_premium_purchase(item) ⇒ Object



90
91
92
# File 'lib/ish/user_profile.rb', line 90

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

#next_serverhostObject

def leadset

::Leadset.find( leadset_id )

end @TODO: change vp 2023-08-21



45
46
47
# File 'lib/ish/user_profile.rb', line 45

def next_serverhost
  Wco::Serverhost.where({ leadset_id: leadset_id }).first
end

#organization_nameObject



37
38
39
40
# File 'lib/ish/user_profile.rb', line 37

def organization_name
  'Some Org'
  # ::Leadset.find( leadset_id )&.name || 'Some Org'
end

#sudoer?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'lib/ish/user_profile.rb', line 72

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