mumuki-domain 9.14.0 → 9.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 91e234afff822bf8ff746f174c941942d6a5d90d2b285e1613f4a739f13e7df6
4
- data.tar.gz: d14adec7ec240db3d6aeff97d2ea7c05cf6dd72134a0118a5a2141c8d97e8215
3
+ metadata.gz: 6ddb5479d7f8ddd0c1c452f6a27f67ed5423a3d0aadca123e9aebddfed06d062
4
+ data.tar.gz: e135a47bc3062fd705d316fd2eb7922dc45bec56620c35ac0ada0c77eac2ebd0
5
5
  SHA512:
6
- metadata.gz: 916afc62518c9ad05a8bd182f56f13b926584652bdc45ee11d267114cf1207b35bd267cccab98d3dffe0df8da200f44937732d8173677869794fb0ea3fa7aaf4
7
- data.tar.gz: a0c2e513345ace615a0532c0f9443cc236f33ec1a17aa5177212162a1b1387353d5167f48641ecd2051e5e1f71b651bd454125976615882127a2ba6dd876d4bf
6
+ metadata.gz: 4a1061815ce251506c410550ee976f552e5266da914845f2ae197a89a11d0f7713a4cbcc5e8ee8fcbef92668860bfda60de3d9fb14245c378d5a74096f849e5b
7
+ data.tar.gz: d20d53b94de4eda7c28b90bbb0ff095f005c60ee0631a15eb1970d8b853010e4e7f3762662c127b3c674cca0aa1f939c5c9808dfa4ce946cbdd8b973e0419e86
@@ -43,20 +43,6 @@ class Assignment < Progress
43
43
  after_initialize :set_default_top_submission_status
44
44
  before_save :award_experience_points!, :update_top_submission!, if: :submission_status_changed?
45
45
  after_save :dirty_parent_by_submission!, if: :completion_changed?
46
- before_validation :set_current_organization!, unless: :organization
47
-
48
- # TODO: Momentary as some assignments may not have an associated organization
49
- def set_current_organization!
50
- self.organization = Organization.current
51
- end
52
-
53
- def recontextualize!(new_organization = Organization.current)
54
- if organization != new_organization
55
- dirty_parent_by_submission! if organization.present? && exercise.used_in?(organization)
56
- self.organization = new_organization
57
- self.parent_id = nil
58
- end
59
- end
60
46
 
61
47
  def set_default_top_submission_status
62
48
  self.top_submission_status ||= 0
@@ -123,7 +109,7 @@ class Assignment < Progress
123
109
  end
124
110
 
125
111
  def content=(content)
126
- if content.present? && exercise.solvable?
112
+ if exercise.solvable?
127
113
  self.solution = exercise.single_choice? ? exercise.choice_index_for(content) : content
128
114
  end
129
115
  end
@@ -19,4 +19,8 @@ class Organization::Status::Base
19
19
  outsider_access_mode(user)
20
20
  end
21
21
  end
22
+
23
+ def validate!(user = nil)
24
+ validate_enabled! unless user
25
+ end
22
26
  end
@@ -20,9 +20,8 @@ class Organization::Status::Disabled < Organization::Status::Base
20
20
  end
21
21
  end
22
22
 
23
- def validate!(user = nil)
24
- raise Mumuki::Domain::DisabledOrganizationError unless user
23
+ def validate_enabled!
24
+ raise Mumuki::Domain::DisabledOrganizationError
25
25
  end
26
-
27
26
  end
28
27
 
@@ -20,7 +20,6 @@ class Organization::Status::Enabled < Organization::Status::Base
20
20
  end
21
21
  end
22
22
 
23
- def validate!(_user = nil)
23
+ def validate_enabled!
24
24
  end
25
-
26
25
  end
@@ -20,8 +20,7 @@ class Organization::Status::InPreparation < Organization::Status::Base
20
20
  end
21
21
  end
22
22
 
23
- def validate!(user = nil)
24
- raise Mumuki::Domain::UnpreparedOrganizationError unless user
23
+ def validate_enabled!
24
+ raise Mumuki::Domain::UnpreparedOrganizationError
25
25
  end
26
-
27
26
  end
@@ -1,13 +1,11 @@
1
1
  module WithOrganizationStatus
2
2
 
3
+ delegate :validate_enabled!, :access_mode, to: :status
4
+
3
5
  def status
4
6
  @status ||= _status
5
7
  end
6
8
 
7
- def access_mode(user)
8
- status.access_mode(user)
9
- end
10
-
11
9
  def validate_active!
12
10
  status.validate!
13
11
  end
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_here?
53
53
  end
54
54
 
55
55
  def timed?
@@ -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
 
@@ -21,7 +21,7 @@ class Organization < ApplicationRecord
21
21
 
22
22
  belongs_to :book
23
23
  has_many :usages
24
-
24
+ has_many :exam_registrations
25
25
  has_many :certificate_programs
26
26
 
27
27
  validates_presence_of :contact_email, :locale, :time_zone
@@ -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?
data/app/models/user.rb CHANGED
@@ -158,6 +158,7 @@ class User < ApplicationRecord
158
158
  end
159
159
 
160
160
  def detach!(role, course)
161
+ make_ex_student_of! course.slug if 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
@@ -0,0 +1,5 @@
1
+ FactoryBot.define do
2
+ factory :exam_authorization do
3
+ exam { create(:exam) }
4
+ end
5
+ 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'
@@ -52,8 +52,6 @@ class Mumuki::Domain::Submission::Base
52
52
  private
53
53
 
54
54
  def save_submission!(assignment)
55
- assignment.content = content
56
- assignment.recontextualize!
57
55
  assignment.save!
58
56
  end
59
57
 
@@ -1,5 +1,6 @@
1
1
  class Mumuki::Domain::Submission::PersistentSubmission < Mumuki::Domain::Submission::Base
2
2
  def save_submission!(assignment)
3
+ assignment.content = content
3
4
  assignment.running!
4
5
  super
5
6
  assignment.save_submission! self
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '9.14.0'
3
+ VERSION = '9.17.0'
4
4
  end
5
5
  end
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.14.0
4
+ version: 9.17.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-09-02 00:00:00.000000000 Z
11
+ date: 2021-09-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -721,6 +721,7 @@ files:
721
721
  - lib/mumuki/domain/factories/complement_factory.rb
722
722
  - lib/mumuki/domain/factories/course_factory.rb
723
723
  - lib/mumuki/domain/factories/discussion_factory.rb
724
+ - lib/mumuki/domain/factories/exam_authorization_factory.rb
724
725
  - lib/mumuki/domain/factories/exam_authorization_request_factory.rb
725
726
  - lib/mumuki/domain/factories/exam_factory.rb
726
727
  - lib/mumuki/domain/factories/exam_registration_factory.rb