Class: User

Instance Method Summary collapse

Methods included from WithUserNavigation

#navigable_name, #navigation_end?

Methods included from WithReminders

#build_reminder, #remind!, #should_remind?, #try_remind_with_lock!

Methods included from Mumuki::Domain::Helpers::User

#discusser_of?, #full_name, #has_immersive_main_organization?, #has_main_organization?, #has_role?, #has_student_granted_organizations?, #main_organization, #merge_permissions!, #platform_class_name, #profile_completed?, #student_granted_organizations, #to_param

Methods included from Mumuki::Domain::Syncable

#platform_class_name, #sync_key

Methods inherited from ApplicationRecord

aggregate_of, all_except, defaults, #delete, #destroy!, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, #update_and_notify!, update_or_create!, whitelist_attributes

Instance Method Details

#accept_invitation!(invitation) ⇒ Object



88
89
90
# File 'app/models/user.rb', line 88

def accept_invitation!(invitation)
  make_student_of! invitation.course_slug
end

#attach!(role, course) ⇒ Object



113
114
115
116
# File 'app/models/user.rb', line 113

def attach!(role, course)
  add_permission! role, course.slug
  save_and_notify!
end

#clear_progress!Object



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

def clear_progress!
  transaction do
    update! last_submission_date: nil, last_exercise: nil
    assignments.destroy_all
  end
end

#copy_progress_to!(another) ⇒ Object



92
93
94
95
96
97
98
99
100
101
102
# File 'app/models/user.rb', line 92

def copy_progress_to!(another)
  transaction do
    assignments.update_all(submitter_id: another.id)
    if another. || last_submission_date.try { |it| it > another.last_submission_date }
      another.update! last_submission_date: last_submission_date,
                      last_exercise: last_exercise,
                      last_organization: last_organization
    end
  end
  reload
end

#currently_in_exam?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'app/models/user.rb', line 137

def currently_in_exam?
  exams.any? { |e| e.in_progress_for? self }
end

#detach!(role, course) ⇒ Object



118
119
120
121
# File 'app/models/user.rb', line 118

def detach!(role, course)
  remove_permission! role, course.slug
  save_and_notify!
end

#import_from_resource_h!(json) ⇒ Object



104
105
106
# File 'app/models/user.rb', line 104

def import_from_resource_h!(json)
  update! self.class.slice_resource_h json
end

#interpolationsObject



123
124
125
126
127
128
129
# File 'app/models/user.rb', line 123

def interpolations
  {
    'user_email' => email,
    'user_first_name' => first_name,
    'user_last_name' => last_name
  }
end

#last_lessonObject



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

def last_lesson
  last_guide.try(:lesson)
end

#never_submitted?Boolean

Returns:

  • (Boolean)


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

def 
  last_submission_date.nil?
end

#passed_assignmentsObject



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

def passed_assignments
  assignments.where(status: Mumuki::Domain::Status::Submission::Passed.to_i)
end

#passed_submissions_countObject



49
50
51
# File 'app/models/user.rb', line 49

def passed_submissions_count
  passed_assignments.count
end

#resubmit!(organization = nil) ⇒ Object



131
132
133
134
135
# File 'app/models/user.rb', line 131

def resubmit!(organization = nil)
  organization = Organization.find_by_name(organization) || main_organization
  organization.switch!
  assignments.each { |it| it.notify! rescue nil }
end

#solved_exercises_countObject



57
58
59
# File 'app/models/user.rb', line 57

def solved_exercises_count
  solved_exercises.count
end

#submissions_countObject



45
46
47
# File 'app/models/user.rb', line 45

def submissions_count
  assignments.pluck(:submissions_count).sum
end

#submitted_exercises_countObject



53
54
55
# File 'app/models/user.rb', line 53

def 
  .count
end

#to_sObject



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

def to_s
  "#{id}:#{name}:#{uid}"
end

#unread_messagesObject



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

def unread_messages
  messages.where read: false
end

#unsubscribe_from_reminders!Object



108
109
110
# File 'app/models/user.rb', line 108

def unsubscribe_from_reminders!
  update! accepts_reminders: false
end

#visit!(organization) ⇒ Object



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

def visit!(organization)
  update!(last_organization: organization) if organization != last_organization
end