mumuki-domain 9.0.4 → 9.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/application_record.rb +20 -0
- data/app/models/message.rb +22 -2
- data/app/models/user.rb +1 -0
- data/db/migrate/20210308145910_add_approved_by_and_at_to_message.rb +6 -0
- data/db/migrate/20210310195602_add_delete_account_token_to_user.rb +6 -0
- data/lib/mumuki/domain/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 46425c74cf597dd17603273a455f7a5956c2f0b80926f81e739f45de0bd4e17e
|
4
|
+
data.tar.gz: 9241fe5525d3c387e726fda5037044c96564d77c802ec4af9e01de086648018e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7ff8c266a27514fac9fe776572efa0ec5d742627bda381b42218364853d75bd51c22aa7aae86be0fb0c8692e9b9b43209e96bc8ac6015cebacce0f3cdb869e7
|
7
|
+
data.tar.gz: 4ba53f6362fcbbbb38e9be6fc19e8a90561cfb02e6a0cc2ba82e597ca5cae8fc06d768f2e0ec7ef8255366d241f5558b1a0f2409b34bedc074466792d78f27fa
|
@@ -87,6 +87,22 @@ class ApplicationRecord < ActiveRecord::Base
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
+
def self.with_temporary_token(field_name, duration = 2.hours)
|
91
|
+
class_eval do
|
92
|
+
token_attribute = field_name
|
93
|
+
token_date_attribute = "#{field_name}_expiration_date"
|
94
|
+
|
95
|
+
define_method("generate_#{field_name}!") do
|
96
|
+
update!(token_attribute => self.class.generate_secure_token, token_date_attribute => duration.from_now)
|
97
|
+
end
|
98
|
+
|
99
|
+
define_method("#{field_name}_matches?") do |token|
|
100
|
+
actual_token = attribute(token_attribute)
|
101
|
+
actual_token.present? && token == actual_token && attribute(token_date_attribute)&.future?
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
90
106
|
def self.numbered(*associations)
|
91
107
|
class_eval do
|
92
108
|
associations.each do |it|
|
@@ -140,4 +156,8 @@ class ApplicationRecord < ActiveRecord::Base
|
|
140
156
|
def raise_foreign_key_error!
|
141
157
|
raise ActiveRecord::InvalidForeignKey.new "#{model_name} is still referenced"
|
142
158
|
end
|
159
|
+
|
160
|
+
def self.generate_secure_token
|
161
|
+
SecureRandom.base58(24)
|
162
|
+
end
|
143
163
|
end
|
data/app/models/message.rb
CHANGED
@@ -2,6 +2,8 @@ class Message < ApplicationRecord
|
|
2
2
|
|
3
3
|
belongs_to :discussion, optional: true
|
4
4
|
belongs_to :assignment, foreign_key: :submission_id, primary_key: :submission_id, optional: true
|
5
|
+
belongs_to :approved_by, class_name: 'User', optional: true
|
6
|
+
|
5
7
|
has_one :exercise, through: :assignment
|
6
8
|
|
7
9
|
validates_presence_of :content, :sender
|
@@ -50,14 +52,22 @@ class Message < ApplicationRecord
|
|
50
52
|
update! read: true
|
51
53
|
end
|
52
54
|
|
53
|
-
def toggle_approved!
|
54
|
-
|
55
|
+
def toggle_approved!(user)
|
56
|
+
if approved?
|
57
|
+
disapprove!
|
58
|
+
else
|
59
|
+
approve!(user)
|
60
|
+
end
|
55
61
|
end
|
56
62
|
|
57
63
|
def toggle_not_actually_a_question!
|
58
64
|
toggle! :not_actually_a_question
|
59
65
|
end
|
60
66
|
|
67
|
+
def approved?
|
68
|
+
approved_at?
|
69
|
+
end
|
70
|
+
|
61
71
|
def validated?
|
62
72
|
approved? || from_moderator?
|
63
73
|
end
|
@@ -93,4 +103,14 @@ class Message < ApplicationRecord
|
|
93
103
|
Assignment.find_by(submission_id: message_data.delete('submission_id'))&.receive_answer! message_data
|
94
104
|
end
|
95
105
|
end
|
106
|
+
|
107
|
+
private
|
108
|
+
|
109
|
+
def approve!(user)
|
110
|
+
update! approved: true, approved_at: Time.now, approved_by: user
|
111
|
+
end
|
112
|
+
|
113
|
+
def disapprove!
|
114
|
+
update! approved: false, approved_at: nil, approved_by: nil
|
115
|
+
end
|
96
116
|
end
|
data/app/models/user.rb
CHANGED
@@ -49,6 +49,7 @@ class User < ApplicationRecord
|
|
49
49
|
PLACEHOLDER_IMAGE_URL = 'user_shape.png'.freeze
|
50
50
|
|
51
51
|
resource_fields :uid, :social_id, :email, :permissions, :verified_first_name, :verified_last_name, *profile_fields
|
52
|
+
with_temporary_token :delete_account_token
|
52
53
|
|
53
54
|
def last_lesson
|
54
55
|
last_guide.try(:lesson)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumuki-domain
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.0.
|
4
|
+
version: 9.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-03-
|
11
|
+
date: 2021-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -659,6 +659,8 @@ files:
|
|
659
659
|
- db/migrate/20210119190204_create_exam_registration_exam_join_table.rb
|
660
660
|
- db/migrate/20210301210530_add_period_start_and_end_to_course.rb
|
661
661
|
- db/migrate/20210302181654_add_faqs_to_organizations.rb
|
662
|
+
- db/migrate/20210308145910_add_approved_by_and_at_to_message.rb
|
663
|
+
- db/migrate/20210310195602_add_delete_account_token_to_user.rb
|
662
664
|
- lib/mumuki/domain.rb
|
663
665
|
- lib/mumuki/domain/area.rb
|
664
666
|
- lib/mumuki/domain/engine.rb
|