mumuki-domain 6.4.3 → 6.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bdae8f084b4e432d998e710bb4abac76abbc7ffa0ee7c2c960c3e6ffe1f01616
4
- data.tar.gz: c90a65e6d097193b4d95303892ad725578b5ee8c4c4d62ffdfd0d03471cb9c9b
3
+ metadata.gz: 3b741c1390b0cbdc4c23449c5a9fe3218796032ad1c42dadaac9275d5d39f128
4
+ data.tar.gz: c63ff4139ffb2d3edad703fa1ea9d9db5f0b57ecc4d3a849556b59d8e238a07d
5
5
  SHA512:
6
- metadata.gz: 5e926415ae433e892b3d73961193fdb98c907d270faadefaa2036f9469b4fa62b95f9f845899aa9065cc175f7a6b82304cf35f7ca02138b822057088121a23c5
7
- data.tar.gz: 11397f01df4e1776e68e863341d367863c7e100d75aba8d93b81eb3e5a7b9aa6554ef3e63c1ce19659cc66fb079ac275fa97f4827ba3148a81339006073f76e9
6
+ metadata.gz: 9f24047fb8f927deb09a72bfbf278bce2647e42216bc2766a2be6130f53725f1ad29b0c9a1268fb913be96a8c9e2f7bf8fe943f6176243e0768e83008198bfd6
7
+ data.tar.gz: aacc1f68926c6e1758612c949da65c85287c516e6b9e70a1be81f2389d1c4454dd38b35617eba95566331802f9b673f73bedcb76d5e72abf519e9b13d75dcae4
@@ -38,6 +38,21 @@ class ApplicationRecord < ActiveRecord::Base
38
38
  end
39
39
  end
40
40
 
41
+ def destroy!
42
+ super
43
+ rescue ActiveRecord::RecordNotDestroyed => e
44
+ errors[:base].last.try { |it| raise ActiveRecord::RecordNotDestroyed.new it }
45
+ raise e
46
+ rescue ActiveRecord::InvalidForeignKey => e
47
+ raise_foreign_key_error!
48
+ end
49
+
50
+ def delete
51
+ super
52
+ rescue ActiveRecord::InvalidForeignKey => e
53
+ raise_foreign_key_error!
54
+ end
55
+
41
56
  def save_and_notify!
42
57
  save!
43
58
  notify!
@@ -85,4 +100,10 @@ class ApplicationRecord < ActiveRecord::Base
85
100
  attributes += reflections.keys if options[:relations]
86
101
  a_hash.with_indifferent_access.slice(*attributes).except(*options[:except])
87
102
  end
103
+
104
+ private
105
+
106
+ def raise_foreign_key_error!
107
+ raise ActiveRecord::InvalidForeignKey.new "#{model_name} is still referenced"
108
+ end
88
109
  end
@@ -6,7 +6,11 @@ class Assignment < ApplicationRecord
6
6
 
7
7
  belongs_to :exercise
8
8
  has_one :guide, through: :exercise
9
- has_many :messages, -> { where.not(submission_id: nil).order(date: :desc) }, foreign_key: :submission_id, primary_key: :submission_id, dependent: :delete_all
9
+ has_many :messages,
10
+ -> { where.not(submission_id: nil).order(date: :desc) },
11
+ foreign_key: :submission_id,
12
+ primary_key: :submission_id,
13
+ dependent: :destroy
10
14
 
11
15
  belongs_to :submitter, class_name: 'User'
12
16
 
@@ -53,7 +57,12 @@ class Assignment < ApplicationRecord
53
57
  end
54
58
 
55
59
  def notify_to_accessible_organizations!
56
- submitter.accessible_organizations.each do |organization|
60
+ warn "Don't use notify_to_accessible_organizations!. Use notify_to_granted_organizations! instead"
61
+ notify_to_granted_organizations!
62
+ end
63
+
64
+ def notify_to_granted_organizations!
65
+ submitter.student_granted_organizations.each do |organization|
57
66
  organization.switch!
58
67
  notify!
59
68
  end
data/app/models/book.rb CHANGED
@@ -2,8 +2,8 @@ class Book < Content
2
2
  numbered :chapters
3
3
  aggregate_of :chapters
4
4
 
5
- has_many :chapters, -> { order(number: :asc) }, dependent: :delete_all
6
- has_many :complements, dependent: :delete_all
5
+ has_many :chapters, -> { order(number: :asc) }, dependent: :destroy
6
+ has_many :complements, dependent: :destroy
7
7
 
8
8
  has_many :exercises, through: :chapters
9
9
  has_many :discussions, through: :exercises
@@ -2,7 +2,7 @@ module WithDiscussions
2
2
  extend ActiveSupport::Concern
3
3
 
4
4
  included do
5
- has_many :discussions, as: :item, dependent: :delete_all
5
+ has_many :discussions, as: :item, dependent: :destroy
6
6
  end
7
7
 
8
8
  def discuss!(user, discussion)
@@ -3,6 +3,7 @@ module WithUsages
3
3
 
4
4
  included do
5
5
  has_many :usages, as: :item
6
+ before_destroy :ensure_unused!
6
7
  end
7
8
 
8
9
  def usage_in_organization(organization = Organization.current)
@@ -13,4 +14,13 @@ module WithUsages
13
14
  item = usage_in_organization(organization)
14
15
  item.is_a?(type) ? item : nil
15
16
  end
17
+
18
+ private
19
+
20
+ def ensure_unused!
21
+ if usages.present?
22
+ errors.add :base, :in_use, organization: usages.first.organization.name
23
+ throw :abort
24
+ end
25
+ end
16
26
  end
@@ -2,7 +2,7 @@ class Discussion < ApplicationRecord
2
2
  include WithDiscussionStatus, ParentNavigation, WithScopedQueries, Contextualization
3
3
 
4
4
  belongs_to :item, polymorphic: true
5
- has_many :messages, -> { order(:created_at) }, dependent: :delete_all
5
+ has_many :messages, -> { order(:created_at) }, dependent: :destroy
6
6
  belongs_to :initiator, class_name: 'User'
7
7
  belongs_to :exercise, foreign_type: :exercise, foreign_key: 'item_id'
8
8
  has_many :subscriptions
data/app/models/exam.rb CHANGED
@@ -7,7 +7,7 @@ class Exam < ApplicationRecord
7
7
  belongs_to :guide
8
8
  belongs_to :organization
9
9
 
10
- has_many :authorizations, class_name: 'ExamAuthorization', dependent: :delete_all
10
+ has_many :authorizations, class_name: 'ExamAuthorization', dependent: :destroy
11
11
  has_many :users, through: :authorizations
12
12
 
13
13
  after_destroy { |record| Usage.destroy_usages_for record }
data/app/models/guide.rb CHANGED
@@ -6,7 +6,7 @@ class Guide < Content
6
6
  markdown_on :corollary, :sources, :learn_more, :teacher_info
7
7
 
8
8
  numbered :exercises
9
- has_many :exercises, -> { order(number: :asc) }, dependent: :delete_all
9
+ has_many :exercises, -> { order(number: :asc) }, dependent: :destroy
10
10
 
11
11
  self.inheritance_column = nil
12
12
 
@@ -0,0 +1,9 @@
1
+ class AddContentFk < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_foreign_key :exams, :guides
4
+ add_foreign_key :lessons, :guides
5
+ add_foreign_key :complements, :guides
6
+ add_foreign_key :chapters, :topics
7
+ add_foreign_key :organizations, :books
8
+ end
9
+ end
@@ -5,6 +5,7 @@ FactoryBot.define do
5
5
  description { 'a great org' }
6
6
  locale { 'en' }
7
7
  settings {}
8
+ name { 'an-organization' }
8
9
  book
9
10
  end
10
11
 
@@ -3,6 +3,14 @@ en:
3
3
  activerecord:
4
4
  errors:
5
5
  models:
6
+ guide:
7
+ attributes:
8
+ base:
9
+ in_use: 'Guide is still in use in organization %{organization}'
10
+ topic:
11
+ attributes:
12
+ base:
13
+ in_use: 'Topic is still in use in organization %{organization}'
6
14
  exercise:
7
15
  attributes:
8
16
  randomizations:
@@ -20,6 +20,14 @@ es:
20
20
  content: Contenido
21
21
  errors:
22
22
  models:
23
+ guide:
24
+ attributes:
25
+ base:
26
+ in_use: 'La guía aún están siendo utilizada en la organización %{organization}'
27
+ topic:
28
+ attributes:
29
+ base:
30
+ in_use: 'El tema aún está siendo utilizado en la organización %{organization}'
23
31
  exercise:
24
32
  attributes:
25
33
  randomizations:
@@ -0,0 +1,29 @@
1
+ ---
2
+ pt:
3
+ activerecord:
4
+ errors:
5
+ models:
6
+ guide:
7
+ attributes:
8
+ base:
9
+ in_use: 'O guia ainda está em uso na organização da %{organization}'
10
+ topic:
11
+ attributes:
12
+ base:
13
+ in_use: 'O tópico ainda está em uso na organização da %{organization}'
14
+ exercise:
15
+ attributes:
16
+ randomizations:
17
+ invalid_format: 'o formato é inválido'
18
+ own_expectations:
19
+ invalid_format: 'o formato é inválido'
20
+ assistance_rules:
21
+ invalid_format: 'o formato é inválido'
22
+ name:
23
+ invalid_format: 'must not contain /'
24
+ base:
25
+ evaluation_criteria_required: 'Você precisa fornecer testes e/ou expectativas'
26
+ organization:
27
+ attributes:
28
+ base:
29
+ consistent_public_login: 'Uma organização pública não pode restringir métodos de login'
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '6.4.3'
3
+ VERSION = '6.5.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: 6.4.3
4
+ version: 6.5.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: 2019-02-18 00:00:00.000000000 Z
11
+ date: 2019-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -534,6 +534,7 @@ files:
534
534
  - db/migrate/20181210131824_convert_course_invitation_into_fk.rb
535
535
  - db/migrate/20190123180139_add_sources_section.rb
536
536
  - db/migrate/20190123180147_add_learn_more_section.rb
537
+ - db/migrate/20190312152901_add_content_fk.rb
537
538
  - lib/mumuki/domain.rb
538
539
  - lib/mumuki/domain/engine.rb
539
540
  - lib/mumuki/domain/evaluation.rb
@@ -570,6 +571,7 @@ files:
570
571
  - lib/mumuki/domain/file.rb
571
572
  - lib/mumuki/domain/locales/activerecord.en.yml
572
573
  - lib/mumuki/domain/locales/activerecord.es.yml
574
+ - lib/mumuki/domain/locales/activerecord.pt.yml
573
575
  - lib/mumuki/domain/locales/narrator.en.yml
574
576
  - lib/mumuki/domain/locales/narrator.es.yml
575
577
  - lib/mumuki/domain/locales/narrator.pt.yml
@@ -621,7 +623,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
621
623
  - !ruby/object:Gem::Version
622
624
  version: '0'
623
625
  requirements: []
624
- rubygems_version: 3.0.2
626
+ rubygems_version: 3.0.3
625
627
  signing_key:
626
628
  specification_version: 4
627
629
  summary: Mumuki Platform's Domain Model