mumuki-domain 7.12.1 → 8.1.2

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: b5cd387b744651b03da4722b106d3c23584a8a610994bf3127fa03cd814e9a64
4
- data.tar.gz: 73ecd3f88a806ec887ec68e76554db2468f1b3b0dd9d459197b366bdbd3575fd
3
+ metadata.gz: d712b0423cb797044b5a152a3b5bf64e6d81dea496582fb25327e5e991e0b095
4
+ data.tar.gz: 23713d6d62039d41dbc7afa5fc24c539adcca97096f4715fe0b0085a0a05509b
5
5
  SHA512:
6
- metadata.gz: d43c7db4b34a5727005cf7f571d7980075fd27fd394942822759bd9e1800626e6880bd1a2bf3085d7332c443d6bdc9602f000e7ee8f3434099c02411a811d8e4
7
- data.tar.gz: 24fb849fee899e0636448cedc7c03935931a25902edf5144eb952acb2aabe8d051fb6d6ef9b0c684cde9523b633454e6b6c2c0f24b63c5c54e682f14eef55be2
6
+ metadata.gz: a6371b30ee3e79073e4659645960433008657ed84d8e483417985cf4f69ea99a86567e4a7f609aa2717d56a7941f81287bde7c371e2ef578c50cda142fd3a8bf
7
+ data.tar.gz: b3bb549da8ba32b9b870afe4e438d2cc7cfb84f15cca3d7e3ac83be7938f5f7126d68a18fb48ce42f34cbc6e80d70872cae7267c2617af88bc5956765b0e8474
@@ -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,6 +52,14 @@ class Assignment < Progress
52
52
  self.organization = Organization.current
53
53
  end
54
54
 
55
+ def recontextualize!(new_organization = Organization.current)
56
+ if organization != new_organization
57
+ dirty_parent_by_submission! if organization.present? && exercise.used_in?(organization)
58
+ self.organization = new_organization
59
+ self.parent_id = nil
60
+ end
61
+ end
62
+
55
63
  def set_default_top_submission_status
56
64
  self.top_submission_status ||= 0
57
65
  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
@@ -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)
@@ -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
@@ -231,6 +239,10 @@ class Exercise < ApplicationRecord
231
239
  guide.pending_exercises(user)
232
240
  end
233
241
 
242
+ def reading?
243
+ is_a? ::Reading
244
+ end
245
+
234
246
  private
235
247
 
236
248
  def evaluation_class
@@ -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
@@ -15,6 +15,10 @@ class Array
15
15
  def single?
16
16
  size == 1
17
17
  end
18
+
19
+ def multiple?
20
+ size > 1
21
+ end
18
22
  end
19
23
 
20
24
  class NilClass
@@ -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
 
@@ -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
@@ -53,11 +53,7 @@ class Mumuki::Domain::Submission::Base
53
53
 
54
54
  def save_submission!(assignment)
55
55
  assignment.content = content
56
- if assignment.organization != Organization.current
57
- assignment.dirty_parent_by_submission! if assignment.organization
58
- assignment.organization = Organization.current
59
- assignment.parent_id = nil
60
- end
56
+ assignment.recontextualize!
61
57
  assignment.save!
62
58
  end
63
59
 
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '7.12.1'
3
+ VERSION = '8.1.2'
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.1
4
+ version: 8.1.2
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-04 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
@@ -756,7 +757,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
756
757
  - !ruby/object:Gem::Version
757
758
  version: '0'
758
759
  requirements: []
759
- rubygems_version: 3.0.8
760
+ rubygems_version: 3.0.3
760
761
  signing_key:
761
762
  specification_version: 4
762
763
  summary: Mumuki Platform's Domain Model