Class: MOCO::User

Inherits:
BaseEntity show all
Defined in:
lib/moco/entities.rb,
lib/moco/entities/user.rb

Overview

Represents a MOCO user (staff member)

Required attributes for create:

firstname - String, first name
lastname  - String, last name
email     - String, email address (used for login)
unit_id   - Integer, team/unit ID

Optional attributes:

password     - String, initial password (if not set, user gets welcome email)
role_id      - Integer, permission role ID
active       - Boolean, whether user is active
external     - Boolean, true for contractors/external staff
language     - String, one of: "de", "de-AT", "de-CH", "en", "it", "fr"
mobile_phone - String, mobile phone number
work_phone   - String, work phone number
home_address - String, home address (use \n for line breaks)
bday         - String, birthday "YYYY-MM-DD"
iban         - String, bank account IBAN
tags         - Array of Strings, e.g., ["Developer", "Remote"]
custom_properties - Hash, e.g., {"Start Date": "2024-01-01"}
info         - String, additional notes
welcome_email - Boolean, send welcome email (default: true if no password)
avatar       - Hash, { filename: "photo.jpg", base64: "..." }

Read-only attributes:

id, avatar_url, unit (Hash), role (Hash), created_at, updated_at

Example:

moco.users.create(
  firstname: "John",
  lastname: "Doe",
  email: "[email protected]",
  unit_id: 123,
  language: "en",
  tags: ["Developer"]
)

Instance Attribute Summary collapse

Attributes inherited from BaseEntity

#attributes, #client

Instance Method Summary collapse

Methods inherited from BaseEntity

#==, #association, #destroy, #eql?, #has_many, #hash, #initialize, #inspect, #reload, #save, #to_h, #to_json, #update

Constructor Details

This class inherits a constructor from MOCO::BaseEntity

Instance Attribute Details

#firstnameObject

Returns the value of attribute firstname.



91
92
93
# File 'lib/moco/entities.rb', line 91

def firstname
  @firstname
end

#idObject

Returns the value of attribute id.



91
92
93
# File 'lib/moco/entities.rb', line 91

def id
  @id
end

#lastnameObject

Returns the value of attribute lastname.



91
92
93
# File 'lib/moco/entities.rb', line 91

def lastname
  @lastname
end

Instance Method Details

#activitiesObject

Associations



49
50
51
# File 'lib/moco/entities/user.rb', line 49

def activities
  has_many(:activities)
end

#employmentsObject



61
62
63
# File 'lib/moco/entities/user.rb', line 61

def employments
  has_many(:employments)
end

#full_nameObject



73
74
75
# File 'lib/moco/entities/user.rb', line 73

def full_name
  "#{firstname} #{lastname}"
end

#holidaysObject



57
58
59
# File 'lib/moco/entities/user.rb', line 57

def holidays
  has_many(:holidays)
end

#performance_reportObject

Instance methods for user-specific operations



44
45
46
# File 'lib/moco/entities/user.rb', line 44

def performance_report
  client.get("users/#{id}/performance_report")
end

#presencesObject



53
54
55
# File 'lib/moco/entities/user.rb', line 53

def presences
  has_many(:presences)
end

#to_sObject



77
78
79
# File 'lib/moco/entities/user.rb', line 77

def to_s
  full_name
end

#unitObject



69
70
71
# File 'lib/moco/entities/user.rb', line 69

def unit
  association(:unit)
end

#work_time_adjustmentsObject



65
66
67
# File 'lib/moco/entities/user.rb', line 65

def work_time_adjustments
  has_many(:work_time_adjustments)
end