Class: User

Inherits:
ApplicationRecord show all
Includes:
Mumukit::Platform::User::Helpers, WithProfile, WithReminders, WithUserNavigation
Defined in:
app/models/user.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from WithUserNavigation

#navigable_name, #navigation_end?

Methods included from WithReminders

#build_reminder, #cycles_since, #remider_due?, #remind!, #send_reminder!, #should_send_reminder?

Methods inherited from ApplicationRecord

aggregate_of, all_except, defaults, name_model_as, numbered, #save, #save_and_notify!, #save_and_notify_changes!, #update_and_notify!, update_or_create!

Class Method Details

.import_from_json!(json) ⇒ Object



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

def self.import_from_json!(json)
  json = Mumukit::Platform::User::Helpers.slice_platform_json json
  User.where(uid: json[:uid]).update_or_create!(json)
end

.unsubscription_verifierObject



98
99
100
# File 'app/models/user.rb', line 98

def self.unsubscription_verifier
  Rails.application.message_verifier(:unsubscribe)
end

Instance Method Details

#clear_progress!Object



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

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

#last_lessonObject



30
31
32
# File 'app/models/user.rb', line 30

def last_lesson
  last_guide.try(:lesson)
end

#never_submitted?Boolean

Returns:

  • (Boolean)


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

def 
  last_submission_date.nil?
end

#passed_assignmentsObject



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

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

#passed_submissions_countObject



38
39
40
# File 'app/models/user.rb', line 38

def passed_submissions_count
  passed_assignments.count
end

#solved_exercises_countObject



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

def solved_exercises_count
  solved_exercises.count
end

#submissions_countObject



34
35
36
# File 'app/models/user.rb', line 34

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

#submitted_exercises_countObject



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

def 
  .count
end

#to_sObject



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

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

#transfer_progress_to!(another) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
# File 'app/models/user.rb', line 77

def transfer_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

#unread_messagesObject



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

def unread_messages
  messages.where read: false
end

#unsubscribe_from_reminders!Object



94
95
96
# File 'app/models/user.rb', line 94

def unsubscribe_from_reminders!
  update! accepts_reminders: false
end

#visit!(organization) ⇒ Object



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

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