mumuki-domain 9.15.0 → 9.19.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/assignment.rb +4 -0
- data/app/models/concerns/organization/status/in_preparation.rb +1 -1
- data/app/models/exam.rb +5 -1
- data/app/models/exam_registration/authorization_criterion.rb +12 -0
- data/app/models/exam_registration.rb +43 -1
- data/app/models/organization.rb +1 -1
- data/app/models/organization_access_mode/base.rb +2 -1
- data/app/models/organization_access_mode/read_only.rb +1 -1
- data/app/models/user.rb +2 -5
- data/db/migrate/20210929223144_add_authorization_requests_limit_to_exam_registration.rb +5 -0
- data/lib/mumuki/domain/factories/exam_authorization_factory.rb +5 -0
- data/lib/mumuki/domain/factories.rb +1 -0
- data/lib/mumuki/domain/version.rb +1 -1
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bcb85dd95292fca604bdfd6f77560b37650766ede8bfbf1b7afe9caf4a105efd
|
4
|
+
data.tar.gz: ed1292935f907bde74fe777fd48de3d61ef87c5f62e6db4c3c7c0ae50c5ce3de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcc442e31b9f5b510c8a5a99d78bcbd98b8a0f36b828badeb64e25e8eaeecb3d910c7348da4b263047f52e5c6bd9ad6ee8412cfcfdf932cee5418a2ee48cfb7c
|
7
|
+
data.tar.gz: 6f888100f4dc2b1f9c332c3f8b9ebc257c1eb3aa2534c7db85bd0b4f4328f9fc2cd24f8da23ecbd04bb1dab8edd56ad236dac2dd6505ea8451ee5c5b6212c570
|
data/app/models/assignment.rb
CHANGED
@@ -9,7 +9,7 @@ class Organization::Status::InPreparation < Organization::Status::Base
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def ex_student_access_mode(user)
|
12
|
-
OrganizationAccessMode::
|
12
|
+
OrganizationAccessMode::ReadOnly.new user, organization, :faqs, :profile
|
13
13
|
end
|
14
14
|
|
15
15
|
def outsider_access_mode(user)
|
data/app/models/exam.rb
CHANGED
@@ -49,7 +49,7 @@ class Exam < ApplicationRecord
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def accessible_for?(user)
|
52
|
-
authorized?(user) && enabled_for?(user)
|
52
|
+
(authorized?(user) && enabled_for?(user)) || user&.teacher_of?(course)
|
53
53
|
end
|
54
54
|
|
55
55
|
def timed?
|
@@ -96,6 +96,10 @@ class Exam < ApplicationRecord
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
+
def time_left(user)
|
100
|
+
(real_end_time(user) - Time.current).round
|
101
|
+
end
|
102
|
+
|
99
103
|
def started_at(user)
|
100
104
|
authorization_for(user).started_at
|
101
105
|
end
|
@@ -38,6 +38,10 @@ class ExamRegistration::AuthorizationCriterion
|
|
38
38
|
def meets_authorization_criteria?(authorization_request)
|
39
39
|
meets_criterion? authorization_request.user, authorization_request.organization
|
40
40
|
end
|
41
|
+
|
42
|
+
def authorization_criteria_matcher
|
43
|
+
criterion_matcher
|
44
|
+
end
|
41
45
|
end
|
42
46
|
|
43
47
|
class ExamRegistration::AuthorizationCriterion::None < ExamRegistration::AuthorizationCriterion
|
@@ -52,6 +56,10 @@ class ExamRegistration::AuthorizationCriterion::None < ExamRegistration::Authori
|
|
52
56
|
def meets_criterion?(_user, _organization)
|
53
57
|
true
|
54
58
|
end
|
59
|
+
|
60
|
+
def criterion_matcher
|
61
|
+
{}
|
62
|
+
end
|
55
63
|
end
|
56
64
|
|
57
65
|
class ExamRegistration::AuthorizationCriterion::PassedExercises < ExamRegistration::AuthorizationCriterion
|
@@ -62,4 +70,8 @@ class ExamRegistration::AuthorizationCriterion::PassedExercises < ExamRegistrati
|
|
62
70
|
def meets_criterion?(user, organization)
|
63
71
|
user.passed_submissions_count_in(organization) >= value
|
64
72
|
end
|
73
|
+
|
74
|
+
def criterion_matcher
|
75
|
+
{ 'stats.passed': { '$gte': value.to_f } }
|
76
|
+
end
|
65
77
|
end
|
@@ -12,7 +12,7 @@ class ExamRegistration < ApplicationRecord
|
|
12
12
|
|
13
13
|
before_save :ensure_valid_authorization_criterion!
|
14
14
|
|
15
|
-
delegate :meets_authorization_criteria?, :process_request!, to: :authorization_criterion
|
15
|
+
delegate :meets_authorization_criteria?, :process_request!, :authorization_criteria_matcher, to: :authorization_criterion
|
16
16
|
|
17
17
|
alias_attribute :name, :description
|
18
18
|
|
@@ -76,6 +76,18 @@ class ExamRegistration < ApplicationRecord
|
|
76
76
|
authorization_criterion.meets_criterion?(user, organization)
|
77
77
|
end
|
78
78
|
|
79
|
+
def available_exams
|
80
|
+
return exams unless limited_authorization_requests?
|
81
|
+
counts = authorization_request_ids_counts
|
82
|
+
exams.select do |it|
|
83
|
+
counts[it.id].to_i < authorization_requests_limit
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def limited_authorization_requests?
|
88
|
+
authorization_requests_limit.present?
|
89
|
+
end
|
90
|
+
|
79
91
|
def multiple_options?
|
80
92
|
exams.count > 1
|
81
93
|
end
|
@@ -84,9 +96,39 @@ class ExamRegistration < ApplicationRecord
|
|
84
96
|
end_time.past?
|
85
97
|
end
|
86
98
|
|
99
|
+
def request_authorization!(user, exam)
|
100
|
+
with_available_exam exam do
|
101
|
+
authorization_requests.find_or_create_by! user: user do |it|
|
102
|
+
it.assign_attributes organization: organization, exam: exam
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def update_authorization_request_by_id!(request_id, exam)
|
108
|
+
with_available_exam exam do
|
109
|
+
authorization_requests.update request_id, exam: exam
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def authorization_request_ids_counts
|
114
|
+
authorization_requests.group(:exam_id).count
|
115
|
+
end
|
116
|
+
|
117
|
+
def exam_available?(exam)
|
118
|
+
available_exams.include? exam
|
119
|
+
end
|
120
|
+
|
121
|
+
def with_available_exam(exam, &block)
|
122
|
+
transaction do
|
123
|
+
raise Mumuki::Domain::GoneError unless exam_available?(exam)
|
124
|
+
block.call
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
87
128
|
private
|
88
129
|
|
89
130
|
def notify_registree!(registree)
|
90
131
|
Notification.create_and_notify_via_email! organization: organization, user: registree, subject: :exam_registration, target: self
|
91
132
|
end
|
133
|
+
|
92
134
|
end
|
data/app/models/organization.rb
CHANGED
@@ -23,7 +23,8 @@ class OrganizationAccessMode::Base
|
|
23
23
|
|
24
24
|
def discuss_here?
|
25
25
|
organization.forum_enabled? && user.discusser_of?(organization) &&
|
26
|
-
user.trusted_as_discusser_in?(organization) && !user.banned_from_forum?
|
26
|
+
user.trusted_as_discusser_in?(organization) && !user.banned_from_forum? &&
|
27
|
+
!user.currently_in_exam?
|
27
28
|
end
|
28
29
|
|
29
30
|
def show_discussion_element?
|
@@ -17,7 +17,7 @@ class OrganizationAccessMode::ReadOnly < OrganizationAccessMode::Base
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def validate_discuss_here!(discussion)
|
20
|
-
super(discussion) unless discussion&.initiator == user
|
20
|
+
super(discussion) unless discuss_here? && discussion&.initiator == user
|
21
21
|
end
|
22
22
|
|
23
23
|
def show_content?(content)
|
data/app/models/user.rb
CHANGED
@@ -157,7 +157,8 @@ class User < ApplicationRecord
|
|
157
157
|
save_and_notify!
|
158
158
|
end
|
159
159
|
|
160
|
-
def detach!(role, course)
|
160
|
+
def detach!(role, course, deep: false)
|
161
|
+
make_ex_student_of! course.slug if !deep && student_of?(course.slug) && solved_any_exercises?(course.organization)
|
161
162
|
remove_permission! role, course.slug
|
162
163
|
save_and_notify!
|
163
164
|
end
|
@@ -202,10 +203,6 @@ class User < ApplicationRecord
|
|
202
203
|
sequence[0..count + lookahead - 1]
|
203
204
|
end
|
204
205
|
|
205
|
-
# Tells if the given user can discuss in an organization
|
206
|
-
#
|
207
|
-
# This is true only when this organization has the forum enabled and the user
|
208
|
-
# has the discusser pseudo-permission and the discusser is trusted
|
209
206
|
def can_discuss_in?(organization)
|
210
207
|
organization.access_mode(self).discuss_here?
|
211
208
|
end
|
@@ -9,6 +9,7 @@ require_relative './factories/complement_factory'
|
|
9
9
|
require_relative './factories/course_factory'
|
10
10
|
require_relative './factories/discussion_factory'
|
11
11
|
require_relative './factories/exam_factory'
|
12
|
+
require_relative './factories/exam_authorization_factory'
|
12
13
|
require_relative './factories/exam_authorization_request_factory'
|
13
14
|
require_relative './factories/exam_registration_factory'
|
14
15
|
require_relative './factories/exercise_factory'
|
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.
|
4
|
+
version: 9.19.0
|
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-
|
11
|
+
date: 2021-10-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -114,14 +114,14 @@ dependencies:
|
|
114
114
|
requirements:
|
115
115
|
- - "~>"
|
116
116
|
- !ruby/object:Gem::Version
|
117
|
-
version: '1.
|
117
|
+
version: '1.2'
|
118
118
|
type: :runtime
|
119
119
|
prerelease: false
|
120
120
|
version_requirements: !ruby/object:Gem::Requirement
|
121
121
|
requirements:
|
122
122
|
- - "~>"
|
123
123
|
- !ruby/object:Gem::Version
|
124
|
-
version: '1.
|
124
|
+
version: '1.2'
|
125
125
|
- !ruby/object:Gem::Dependency
|
126
126
|
name: mumukit-platform
|
127
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -686,6 +686,7 @@ files:
|
|
686
686
|
- db/migrate/20210707143002_add_assignment_id_to_message.rb
|
687
687
|
- db/migrate/20210719145706_add_new_fields_to_notifications.rb
|
688
688
|
- db/migrate/20210803175124_add_ignored_notifications_to_users.rb
|
689
|
+
- db/migrate/20210929223144_add_authorization_requests_limit_to_exam_registration.rb
|
689
690
|
- lib/mumuki/domain.rb
|
690
691
|
- lib/mumuki/domain/area.rb
|
691
692
|
- lib/mumuki/domain/engine.rb
|
@@ -721,6 +722,7 @@ files:
|
|
721
722
|
- lib/mumuki/domain/factories/complement_factory.rb
|
722
723
|
- lib/mumuki/domain/factories/course_factory.rb
|
723
724
|
- lib/mumuki/domain/factories/discussion_factory.rb
|
725
|
+
- lib/mumuki/domain/factories/exam_authorization_factory.rb
|
724
726
|
- lib/mumuki/domain/factories/exam_authorization_request_factory.rb
|
725
727
|
- lib/mumuki/domain/factories/exam_factory.rb
|
726
728
|
- lib/mumuki/domain/factories/exam_registration_factory.rb
|