mumuki-domain 7.12.2 → 8.1.3

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: c03b11014fe958aaa9ab0e980a40f5f68b3adafd4ccc593bc0fcf04771a68f5b
4
- data.tar.gz: d2ac0f573097e57a62e4e13f2d2dc4116ecb8ab5dfca033fd5ac69d0c9afd33a
3
+ metadata.gz: 9495d00fe4f85bdc27f5cf67b94e5f09de465a31a795e9e3d56b3f4cd91433e1
4
+ data.tar.gz: 209256d417ff7c98c309b517cd7076a9743ea00de79124b6bec3e735a49a5238
5
5
  SHA512:
6
- metadata.gz: 998b1c0f0ee18cc59a8173c1d2ebbbeb930e877bddf1fdcb6e3dc3edc31509f63e16f0db48cb506ba35e4e35ac363f9ee625c58f6cd0da95d82461f6dd586102
7
- data.tar.gz: da140f00d91f6408e176453bf36b33108c9e73552e8c7ce3666f31d11145cf87bdcd5afc40e3edb8fac066073bb4ff49e0db4e435cfb862f295b2e05836a16ad
6
+ metadata.gz: 88ccf91cbccb01f15ec513e232d48832e69a0ec9f5153992e91eab56c44183f10a10dc2a4bcd894509708ab97461b4698ecb73485da8d7dfa8826196837e0c3d
7
+ data.tar.gz: 80b0c3ec21c9444dedb05c1c1060035cdd0d5f0f731635ae79e4738c0a0d23c6fbf4ac67d48c6bb0ea70a76ee7e825a05a2afaaad95e8d2be54096636e0e2af0
@@ -70,9 +70,8 @@ class ApplicationRecord < ActiveRecord::Base
70
70
  end
71
71
 
72
72
  def update_and_notify!(data)
73
- update! data
74
- notify!
75
- self
73
+ assign_attributes data
74
+ save_and_notify!
76
75
  end
77
76
 
78
77
  def self.aggregate_of(association)
@@ -105,7 +104,7 @@ class ApplicationRecord < ActiveRecord::Base
105
104
  obj
106
105
  end
107
106
 
108
- def self.whitelist_attributes(a_hash, options={})
107
+ def self.whitelist_attributes(a_hash, options = {})
109
108
  attributes = attribute_names
110
109
  attributes += reflections.keys if options[:relations]
111
110
  a_hash.with_indifferent_access.slice(*attributes).except(*options[:except])
@@ -52,10 +52,10 @@ class Assignment < Progress
52
52
  self.organization = Organization.current
53
53
  end
54
54
 
55
- def recontextualize!
56
- if organization != Organization.current
55
+ def recontextualize!(new_organization = Organization.current)
56
+ if organization != new_organization
57
57
  dirty_parent_by_submission! if organization.present? && exercise.used_in?(organization)
58
- self.organization = Organization.current
58
+ self.organization = new_organization
59
59
  self.parent_id = nil
60
60
  end
61
61
  end
@@ -126,7 +126,7 @@ class Assignment < Progress
126
126
  end
127
127
 
128
128
  def content=(content)
129
- if content.present?
129
+ if exercise.solvable?
130
130
  self.solution = exercise.single_choice? ? exercise.choice_index_for(content) : content
131
131
  end
132
132
  end
@@ -20,6 +20,14 @@ module Container
20
20
  content.progress_for(user, organization)
21
21
  end
22
22
 
23
+ def navigable_content_in(organization = Organization.current)
24
+ content.usage_in_organization(organization)
25
+ end
26
+
27
+ def content_used_in?(organization)
28
+ navigable_content_in(organization).present?
29
+ end
30
+
23
31
  private
24
32
 
25
33
  # Generally we are calling progress_for for each sibling. That method needs the
@@ -18,16 +18,12 @@ module WithExpectations
18
18
  self[:expectations] = expectations.map(&:stringify_keys)
19
19
  end
20
20
 
21
- def own_expectations
21
+ def raw_expectations
22
22
  self[:expectations]
23
23
  end
24
24
 
25
- def own_custom_expectations
26
- self[:custom_expectations]
27
- end
28
-
29
25
  def ensure_expectations_format
30
- errors.add :own_expectations,
31
- :invalid_format unless own_expectations.to_a.all? { |it| Mulang::Expectation.valid? it }
26
+ errors.add :raw_expectations,
27
+ :invalid_format unless raw_expectations.to_a.all? { |it| Mulang::Expectation.valid? it }
32
28
  end
33
29
  end
@@ -35,8 +35,7 @@ module WithRandomizations
35
35
 
36
36
  def randomize_field(selector)
37
37
  define_method(selector) do |*args|
38
- return unless super(*args)
39
- randomizer.randomize!(super(*args), seed)
38
+ super(*args).randomize_with randomizer, seed
40
39
  end
41
40
  end
42
41
  end
@@ -16,6 +16,18 @@ module WithUsages
16
16
  item.is_a?(type) ? item : nil
17
17
  end
18
18
 
19
+ def navigable_content_in(organization = Organization.current)
20
+ self if used_in?(organization)
21
+ end
22
+
23
+ def content_used_in?(organization)
24
+ navigable_content_in(organization).present?
25
+ end
26
+
27
+ def used_in?(organization)
28
+ usage_in_organization(organization).present?
29
+ end
30
+
19
31
  class_methods do
20
32
  def aggregate_of(association)
21
33
  super
@@ -44,6 +44,10 @@ class Discussion < ApplicationRecord
44
44
  end
45
45
  end
46
46
 
47
+ def navigable_content_in(_)
48
+ nil
49
+ end
50
+
47
51
  def used_in?(organization)
48
52
  organization == self.organization
49
53
  end
@@ -5,7 +5,7 @@ class Exam < ApplicationRecord
5
5
  include TerminalNavigation
6
6
 
7
7
  belongs_to :organization
8
- belongs_to :course, optional: true
8
+ belongs_to :course
9
9
 
10
10
  has_many :authorizations, class_name: 'ExamAuthorization', dependent: :destroy
11
11
  has_many :users, through: :authorizations
@@ -186,8 +186,6 @@ class Exam < ApplicationRecord
186
186
  exam[:start_time] = exam[:start_time].to_time
187
187
  exam[:end_time] = exam[:end_time].to_time
188
188
  exam[:classroom_id] = exam[:eid] if exam[:eid].present?
189
- exam[:passing_criterion_type] = exam.dig(:passing_criterion, :type)
190
- exam[:passing_criterion_value] = exam.dig(:passing_criterion, :value)
191
189
  end
192
190
 
193
191
  def self.remove_previous_version(eid, guide_id)
@@ -1,5 +1,5 @@
1
1
  class Exercise < ApplicationRecord
2
- RANDOMIZED_FIELDS = [:default_content, :description, :extra, :hint, :test]
2
+ RANDOMIZED_FIELDS = [:default_content, :description, :extra, :hint, :test, :expectations, :custom_expectations]
3
3
  BASIC_RESOURCE_FIELDS = %i(
4
4
  name layout editor corollary teacher_info manual_evaluation locale
5
5
  choices assistance_rules randomizations tag_list extra_visible goal
@@ -47,6 +47,14 @@ class Exercise < ApplicationRecord
47
47
  guide.usage_in_organization(organization).present?
48
48
  end
49
49
 
50
+ def navigable_content_in(organization = Organization.current)
51
+ self if used_in?(organization)
52
+ end
53
+
54
+ def content_used_in?(organization)
55
+ navigable_content_in(organization).present?
56
+ end
57
+
50
58
  def structural_parent
51
59
  guide
52
60
  end
@@ -127,8 +135,6 @@ class Exercise < ApplicationRecord
127
135
  language_resource_h = language.to_embedded_resource_h if language != guide.language
128
136
  as_json(only: BASIC_RESOURCE_FIELDS)
129
137
  .merge(id: bibliotheca_id, language: language_resource_h, type: type.underscore)
130
- .merge(expectations: self[:expectations])
131
- .merge(custom_expectations: self[:custom_expectations])
132
138
  .merge(settings: self[:settings])
133
139
  .merge(RANDOMIZED_FIELDS.map { |it| [it, self[it]] }.to_h)
134
140
  .symbolize_keys
@@ -231,6 +237,10 @@ class Exercise < ApplicationRecord
231
237
  guide.pending_exercises(user)
232
238
  end
233
239
 
240
+ def solvable?
241
+ is_a? ::Problem
242
+ end
243
+
234
244
  private
235
245
 
236
246
  def evaluation_class
@@ -8,8 +8,10 @@ class Challenge < Exercise
8
8
  self.layout = self.class.default_layout
9
9
  end
10
10
 
11
- def extra(*)
12
- [guide.extra, super]
11
+ alias_method :own_extra, :extra
12
+
13
+ def extra
14
+ [guide.extra, own_extra]
13
15
  .compact
14
16
  .join("\n")
15
17
  .strip
@@ -21,20 +21,15 @@ class Problem < QueriableChallenge
21
21
  self.expectations = []
22
22
  end
23
23
 
24
+ alias_method :own_expectations, :expectations
25
+ alias_method :own_custom_expectations, :custom_expectations
26
+
24
27
  def expectations
25
- own_expectations + guide_expectations
28
+ own_expectations + guide.expectations
26
29
  end
27
30
 
28
31
  def custom_expectations
29
- "#{own_custom_expectations}\n#{guide_custom_expectations}"
30
- end
31
-
32
- def guide_expectations
33
- guide.expectations
34
- end
35
-
36
- def guide_custom_expectations
37
- guide.custom_expectations
32
+ "#{own_custom_expectations}\n#{guide.custom_expectations}"
38
33
  end
39
34
 
40
35
  def evaluation_criteria?
@@ -139,9 +139,9 @@ class User < ApplicationRecord
139
139
 
140
140
  def interpolations
141
141
  {
142
- 'user_email' => email,
143
- 'user_first_name' => first_name,
144
- 'user_last_name' => last_name
142
+ 'user_email' => email,
143
+ 'user_first_name' => first_name,
144
+ 'user_last_name' => last_name
145
145
  }
146
146
  end
147
147
 
@@ -182,7 +182,7 @@ class User < ApplicationRecord
182
182
  # This is true only when this organization has the forum enabled and the user
183
183
  # has the discusser pseudo-permission and the discusser is trusted
184
184
  def can_discuss_in?(organization)
185
- organization.forum_enabled? && discusser_of?(organization) && trusted_as_discusser_in?(organization)
185
+ organization.forum_enabled? && discusser_of?(organization) && trusted_as_discusser_in?(organization) && !banned_from_forum?
186
186
  end
187
187
 
188
188
  def trusted_as_discusser_in?(organization)
@@ -243,14 +243,35 @@ class User < ApplicationRecord
243
243
  Organization.current? ? Organization.current : main_organization
244
244
  end
245
245
 
246
- def current_immersive_context_at(exercise)
246
+ def current_immersive_context_at(path_item)
247
247
  if Organization.current?
248
- immersive_organization_at(exercise) || Organization.current
248
+ immersive_organization_at(path_item) || Organization.current
249
249
  else
250
250
  main_organization
251
251
  end
252
252
  end
253
253
 
254
+ def notify_permissions_changed!
255
+ return if permissions_before_last_save == permissions
256
+ Mumukit::Nuntius.notify! 'user-permissions-changed', user: {
257
+ uid: uid,
258
+ old_permissions: permissions_before_last_save.as_json,
259
+ new_permissions: permissions.as_json
260
+ }
261
+ end
262
+
263
+ def save_and_notify!
264
+ save!
265
+ notify_permissions_changed!
266
+ self
267
+ end
268
+
269
+ def current_immersive_context_and_content_at(path_item)
270
+ immersive_organization_with_content_at(path_item).tap do |orga, _|
271
+ return [Organization.current, path_item] unless orga.present?
272
+ end
273
+ end
274
+
254
275
  private
255
276
 
256
277
  def welcome_to_new_organizations!
@@ -0,0 +1,5 @@
1
+ class AddBannedFromForumToUsers < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :users, :banned_from_forum, :boolean
4
+ end
5
+ end
@@ -1,5 +1,7 @@
1
1
  require_relative './extensions/string'
2
+ require_relative './extensions/symbol'
2
3
  require_relative './extensions/array'
3
4
  require_relative './extensions/module'
4
5
  require_relative './extensions/hash'
6
+ require_relative './extensions/nil'
5
7
  require_relative './extensions/time'
@@ -15,10 +15,12 @@ class Array
15
15
  def single?
16
16
  size == 1
17
17
  end
18
- end
19
18
 
20
- class NilClass
21
- def insert_last(element)
22
- [element]
19
+ def multiple?
20
+ size > 1
21
+ end
22
+
23
+ def randomize_with(randomizer, seed)
24
+ map { |it| it.randomize_with randomizer, seed }
23
25
  end
24
26
  end
@@ -11,4 +11,8 @@ class Hash
11
11
  def markdownified(*keys, **options)
12
12
  map { |k, v| key.in?(keys) ? v.markdownified(options) : v }.to_h
13
13
  end
14
+
15
+ def randomize_with(randomizer, seed)
16
+ transform_values { |v| v.randomize_with randomizer, seed }
17
+ end
14
18
  end
@@ -0,0 +1,17 @@
1
+ class NilClass
2
+ def affable
3
+ end
4
+
5
+ def markdownified(**options)
6
+ end
7
+
8
+ def sanitized
9
+ end
10
+
11
+ def randomize_with(randomizer, seed)
12
+ end
13
+
14
+ def insert_last(element)
15
+ [element]
16
+ end
17
+ end
@@ -59,15 +59,8 @@ class String
59
59
  def sanitized
60
60
  Mumukit::ContentType::Sanitizer.sanitize self
61
61
  end
62
- end
63
-
64
- class NilClass
65
- def affable
66
- end
67
62
 
68
- def markdownified(**options)
69
- end
70
-
71
- def sanitized
63
+ def randomize_with(randomizer, seed)
64
+ randomizer.randomize!(self, seed)
72
65
  end
73
66
  end
@@ -0,0 +1,5 @@
1
+ class Symbol
2
+ def randomize_with(randomizer, seed)
3
+ self.to_s.randomize_with(randomizer, seed).to_sym
4
+ end
5
+ end
@@ -1,6 +1,6 @@
1
1
  FactoryBot.define do
2
2
  factory :term do
3
- content { Faker::Lorem.sentence(word_count: 2000) }
3
+ content { Faker::Lorem.sentence(word_count: 100) }
4
4
  header { Faker::Lorem.sentence(word_count: 5) }
5
5
  end
6
6
  end
@@ -29,7 +29,7 @@ module Mumuki::Domain::Helpers::Organization
29
29
  end
30
30
 
31
31
  def immersed_in?(other)
32
- immersible? && other.immersive? && target_audience == other.target_audience
32
+ immersible? && other.immersive? && !other.disabled? && target_audience == other.target_audience
33
33
  end
34
34
 
35
35
  def switch!
@@ -41,7 +41,7 @@ module Mumuki::Domain::Helpers::Organization
41
41
  end
42
42
 
43
43
  def url_for(path)
44
- Mumukit::Platform.application.organic_url_for(name, path)
44
+ Mumukit::Platform.laboratory.organic_url_for(name, path)
45
45
  end
46
46
 
47
47
  def url
@@ -8,6 +8,7 @@ module Mumuki::Domain::Helpers::User
8
8
  delegate :has_role?,
9
9
  :add_permission!,
10
10
  :remove_permission!,
11
+ :update_permission!,
11
12
  :has_permission?,
12
13
  :has_permission_delegation?,
13
14
  :protect!,
@@ -100,12 +101,21 @@ module Mumuki::Domain::Helpers::User
100
101
  end
101
102
 
102
103
  def immersive_organizations_at(path_item, current = Organization.current)
103
- return [] unless current.immersible?
104
-
105
104
  usage_filter = path_item ? lambda { |it| path_item.used_in?(it) } : lambda { |_| true }
106
- student_granted_organizations
107
- .select { |it| current.immersed_in?(it) }
108
- .select(&usage_filter)
105
+ immersive_organizations_for(current).select(&usage_filter)
106
+ end
107
+
108
+ def immersive_organization_with_content_at(path_item, current = Organization.current)
109
+ orga = immersive_organizations_with_content_at(path_item, current).single
110
+ [orga, path_item&.navigable_content_in(orga)]
111
+ end
112
+
113
+ def immersive_organizations_with_content_at(path_item, current = Organization.current)
114
+ immersive_without_usage = immersive_organizations_for(current)
115
+ return immersive_without_usage unless path_item.present?
116
+
117
+ immersive_with_usage = immersive_without_usage.select { |it| path_item.content_used_in? it }
118
+ immersive_with_usage.empty? ? immersive_without_usage : immersive_with_usage
109
119
  end
110
120
 
111
121
  ## API Exposure
@@ -119,4 +129,12 @@ module Mumuki::Domain::Helpers::User
119
129
  [:first_name, :last_name, :gender, :birthdate]
120
130
  end
121
131
  end
132
+
133
+ private
134
+
135
+ def immersive_organizations_for(organization)
136
+ return [] unless organization.immersible?
137
+
138
+ student_granted_organizations.select { |it| organization.immersed_in?(it) }
139
+ end
122
140
  end
@@ -52,7 +52,15 @@ module Mumuki::Domain
52
52
  nil
53
53
  end
54
54
 
55
- def immersive_organizations_at(_)
55
+ def current_immersive_context_and_content_at(_)
56
+ [nil, nil]
57
+ end
58
+
59
+ def immersive_organizations_with_content_at(_, _ = nil)
60
+ []
61
+ end
62
+
63
+ def immersive_organizations_at(_, _ = nil)
56
64
  []
57
65
  end
58
66
 
@@ -15,7 +15,7 @@ en:
15
15
  attributes:
16
16
  randomizations:
17
17
  invalid_format: 'format is invalid'
18
- own_expectations:
18
+ raw_expectations:
19
19
  invalid_format: 'format is invalid'
20
20
  assistance_rules:
21
21
  invalid_format: 'format is invalid'
@@ -32,7 +32,7 @@ es-CL:
32
32
  attributes:
33
33
  randomizations:
34
34
  invalid_format: 'formato inválido'
35
- own_expectations:
35
+ raw_expectations:
36
36
  invalid_format: 'formato inválido'
37
37
  assistance_rules:
38
38
  invalid_format: 'formato inválido'
@@ -32,7 +32,7 @@ es:
32
32
  attributes:
33
33
  randomizations:
34
34
  invalid_format: 'formato inválido'
35
- own_expectations:
35
+ raw_expectations:
36
36
  invalid_format: 'formato inválido'
37
37
  assistance_rules:
38
38
  invalid_format: 'formato inválido'
@@ -15,7 +15,7 @@ pt:
15
15
  attributes:
16
16
  randomizations:
17
17
  invalid_format: 'o formato é inválido'
18
- own_expectations:
18
+ raw_expectations:
19
19
  invalid_format: 'o formato é inválido'
20
20
  assistance_rules:
21
21
  invalid_format: 'o formato é inválido'
@@ -36,6 +36,6 @@ class Mumuki::Domain::Organization::Profile < Mumukit::Platform::Model
36
36
  end
37
37
 
38
38
  def open_graph_image_url
39
- @open_graph_image_url ||= Mumukit::Platform.application.url_for("logo-alt.png") # Best image size: 256x256
39
+ @open_graph_image_url ||= Mumukit::Platform.laboratory.url_for("logo-alt.png") # Best image size: 256x256
40
40
  end
41
41
  end
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '7.12.2'
3
+ VERSION = '8.1.3'
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: 7.12.2
4
+ version: 8.1.3
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: 2020-11-17 00:00:00.000000000 Z
11
+ date: 2020-12-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -128,14 +128,14 @@ dependencies:
128
128
  requirements:
129
129
  - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '5.2'
131
+ version: '6.1'
132
132
  type: :runtime
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '5.2'
138
+ version: '6.1'
139
139
  - !ruby/object:Gem::Dependency
140
140
  name: mumukit-sync
141
141
  requirement: !ruby/object:Gem::Requirement
@@ -636,6 +636,7 @@ files:
636
636
  - db/migrate/20201026225312_add_organization_wins_page_flag.rb
637
637
  - db/migrate/20201027134205_add_immersible_to_organization.rb
638
638
  - db/migrate/20201027152806_create_terms.rb
639
+ - db/migrate/20201130163114_add_banned_from_forum_to_users.rb
639
640
  - lib/mumuki/domain.rb
640
641
  - lib/mumuki/domain/area.rb
641
642
  - lib/mumuki/domain/engine.rb
@@ -655,7 +656,9 @@ files:
655
656
  - lib/mumuki/domain/extensions/array.rb
656
657
  - lib/mumuki/domain/extensions/hash.rb
657
658
  - lib/mumuki/domain/extensions/module.rb
659
+ - lib/mumuki/domain/extensions/nil.rb
658
660
  - lib/mumuki/domain/extensions/string.rb
661
+ - lib/mumuki/domain/extensions/symbol.rb
659
662
  - lib/mumuki/domain/extensions/time.rb
660
663
  - lib/mumuki/domain/factories.rb
661
664
  - lib/mumuki/domain/factories/api_client_factory.rb
@@ -756,7 +759,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
756
759
  - !ruby/object:Gem::Version
757
760
  version: '0'
758
761
  requirements: []
759
- rubygems_version: 3.0.8
762
+ rubygems_version: 3.0.3
760
763
  signing_key:
761
764
  specification_version: 4
762
765
  summary: Mumuki Platform's Domain Model