mumuki-domain 8.1.3 → 8.2.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: 9495d00fe4f85bdc27f5cf67b94e5f09de465a31a795e9e3d56b3f4cd91433e1
4
- data.tar.gz: 209256d417ff7c98c309b517cd7076a9743ea00de79124b6bec3e735a49a5238
3
+ metadata.gz: 5ea9b10953e5031cfcfa680763efb0eac02e63b91219c3dbf71b0d30b5dd3250
4
+ data.tar.gz: 8fda448216e9d80cb4de41a7f43825882e043895705c66c1c6b9b4bc68c5bfec
5
5
  SHA512:
6
- metadata.gz: 88ccf91cbccb01f15ec513e232d48832e69a0ec9f5153992e91eab56c44183f10a10dc2a4bcd894509708ab97461b4698ecb73485da8d7dfa8826196837e0c3d
7
- data.tar.gz: 80b0c3ec21c9444dedb05c1c1060035cdd0d5f0f731635ae79e4738c0a0d23c6fbf4ac67d48c6bb0ea70a76ee7e825a05a2afaaad95e8d2be54096636e0e2af0
6
+ metadata.gz: f2f8f341502367fa4a7ba037eb086f0506c19fede8290aba4921430fb22e33cc338faf01bc85d23d9df89fca006dba97705e377f48c3eae789170291644562e5
7
+ data.tar.gz: e5044aa8475aba10ea9d1140eceefccd9fc36de384cf215007f4f239568aebf9f06583074249af630fff81db9da8d429604fa428db0c509a55c4f9092b25965d
@@ -23,6 +23,8 @@ class Assignment < Progress
23
23
 
24
24
  delegate :completed?, :solved?, to: :submission_status
25
25
 
26
+ delegate :content_available_in?, to: :parent
27
+
26
28
  alias_attribute :status, :submission_status
27
29
  alias_attribute :attempts_count, :attemps_count
28
30
 
@@ -263,6 +265,10 @@ class Assignment < Progress
263
265
 
264
266
  private
265
267
 
268
+ def duplicates_key
269
+ { exercise: exercise, submitter: submitter }
270
+ end
271
+
266
272
  def update_submissions_count!
267
273
  self.class.connection.execute(
268
274
  "update public.exercises
@@ -278,5 +284,4 @@ class Assignment < Progress
278
284
  def update_last_submission!
279
285
  submitter.update!(last_submission_date: DateTime.current, last_exercise: exercise)
280
286
  end
281
-
282
287
  end
@@ -66,8 +66,43 @@ class Indicator < Progress
66
66
  where(content: content, organization: organization).delete_all
67
67
  end
68
68
 
69
+ def _move_to!(organization)
70
+ move_children_to!(organization)
71
+ super
72
+ end
73
+
74
+ def _copy_to!(organization)
75
+ progress_item = super
76
+ children.each { |it| it._copy_to! organization }
77
+ progress_item
78
+ end
79
+
80
+ def move_children_to!(organization)
81
+ children.update_all(organization_id: organization.id)
82
+
83
+ indicators.each { |it| it.move_children_to!(organization) }
84
+ end
85
+
86
+ def cascade_delete_children!
87
+ indicators.each(&:cascade_delete_children!)
88
+ children.delete_all(:delete_all)
89
+ end
90
+
91
+ def content_available_in?(organization)
92
+ content.usage_in_organization(organization).present?
93
+ end
94
+
95
+ def delete_duplicates_in!(organization)
96
+ duplicates_in(organization).each(&:cascade_delete_children!)
97
+ super
98
+ end
99
+
69
100
  private
70
101
 
102
+ def duplicates_key
103
+ { content: content, user: user }
104
+ end
105
+
71
106
  def children
72
107
  indicators.presence || assignments
73
108
  end
@@ -12,4 +12,39 @@ class Progress < ApplicationRecord
12
12
  def dirty_parent_by_submission!
13
13
  parent&.dirty_by_submission!
14
14
  end
15
+
16
+ def _copy_to!(organization)
17
+ dup.transfer_to!(organization)
18
+ end
19
+
20
+ def transfer_to!(organization)
21
+ update! organization: organization, parent: nil
22
+ self
23
+ end
24
+
25
+ alias_method :_move_to!, :transfer_to!
26
+
27
+ %w(copy move).each do |transfer_type|
28
+ define_method "#{transfer_type}_to!" do |organization|
29
+ "Mumuki::Domain::ProgressTransfer::#{transfer_type.camelize}".constantize.new(self, organization).execute!
30
+ end
31
+ end
32
+
33
+ def guide_indicator?
34
+ is_a?(Indicator) && content_type == 'Guide'
35
+ end
36
+
37
+ def has_duplicates_in?(organization)
38
+ duplicates_in(organization).present?
39
+ end
40
+
41
+ def delete_duplicates_in!(organization)
42
+ duplicates_in(organization).delete_all
43
+ end
44
+
45
+ private
46
+
47
+ def duplicates_in(organization)
48
+ self.class.where(duplicates_key.merge(organization: organization)).where.not(id: id)
49
+ end
15
50
  end
@@ -38,6 +38,7 @@ require_relative './domain/workspace'
38
38
  require_relative './domain/helpers'
39
39
  require_relative './domain/syncable'
40
40
  require_relative './domain/store'
41
+ require_relative './domain/progress_transfer'
41
42
 
42
43
  class Mumukit::Assistant
43
44
  def self.valid?(rules)
@@ -0,0 +1,8 @@
1
+ module Mumuki::Domain
2
+ module ProgressTransfer
3
+ end
4
+ end
5
+
6
+ require_relative './progress_transfer/base'
7
+ require_relative './progress_transfer/move'
8
+ require_relative './progress_transfer/copy'
@@ -0,0 +1,44 @@
1
+ class Mumuki::Domain::ProgressTransfer::Base
2
+ attr_reader *%i(source_organization destination_organization progress_item transferred_item)
3
+
4
+ delegate :user, to: :progress_item
5
+
6
+ def initialize(progress_item, destination_organization)
7
+ @progress_item = progress_item
8
+ @destination_organization = destination_organization
9
+ end
10
+
11
+ def execute!
12
+ ActiveRecord::Base.transaction do
13
+ pre_transfer!
14
+ transfer!
15
+ post_transfer!
16
+ end
17
+ end
18
+
19
+ def pre_transfer!
20
+ validate_transferrable!
21
+ @source_organization = progress_item.organization
22
+ progress_item.delete_duplicates_in!(destination_organization)
23
+ end
24
+
25
+ def transfer!
26
+ @transferred_item = do_transfer!
27
+ end
28
+
29
+ def post_transfer!
30
+ transferred_item.dirty_parent_by_submission!
31
+ notify_transfer!
32
+ transferred_item
33
+ end
34
+
35
+ def validate_transferrable!
36
+ raise "Transferred progress' content must be available in destination!" unless progress_item.content_available_in?(destination_organization)
37
+ raise 'User must be student in destination organization' unless user.student_of?(destination_organization)
38
+ raise 'Transfer only supported for guide indicators' unless progress_item.guide_indicator?
39
+ end
40
+
41
+ def notify_transfer!
42
+ Mumukit::Nuntius.notify! 'progress-transfers', { from: source_organization.name, to: destination_organization.name, item_type: transferred_item.class.to_s, item_id: transferred_item.id, transfer_type: transfer_type }
43
+ end
44
+ end
@@ -0,0 +1,9 @@
1
+ class Mumuki::Domain::ProgressTransfer::Copy < Mumuki::Domain::ProgressTransfer::Base
2
+ def transfer_type
3
+ :copy
4
+ end
5
+
6
+ def do_transfer!
7
+ progress_item._copy_to!(destination_organization)
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ class Mumuki::Domain::ProgressTransfer::Move < Mumuki::Domain::ProgressTransfer::Base
2
+ def transfer_type
3
+ :move
4
+ end
5
+
6
+ def pre_transfer!
7
+ super
8
+ progress_item.dirty_parent_by_submission!
9
+ end
10
+
11
+ def do_transfer!
12
+ progress_item._move_to!(destination_organization)
13
+ end
14
+ end
@@ -10,6 +10,6 @@ module Mumuki::Domain::Status::Submission::ManualEvaluationPending
10
10
  end
11
11
 
12
12
  def self.iconize
13
- {class: :info, type: 'clock-o'}
13
+ {class: :info, type: 'clock'}
14
14
  end
15
15
  end
@@ -50,4 +50,8 @@ module Mumuki::Domain::Status::Submission
50
50
  def exp_given
51
51
  0
52
52
  end
53
+
54
+ def dup
55
+ self
56
+ end
53
57
  end
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '8.1.3'
3
+ VERSION = '8.2.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: 8.1.3
4
+ version: 8.2.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: 2020-12-18 00:00:00.000000000 Z
11
+ date: 2021-01-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -704,6 +704,10 @@ files:
704
704
  - lib/mumuki/domain/organization/profile.rb
705
705
  - lib/mumuki/domain/organization/settings.rb
706
706
  - lib/mumuki/domain/organization/theme.rb
707
+ - lib/mumuki/domain/progress_transfer.rb
708
+ - lib/mumuki/domain/progress_transfer/base.rb
709
+ - lib/mumuki/domain/progress_transfer/copy.rb
710
+ - lib/mumuki/domain/progress_transfer/move.rb
707
711
  - lib/mumuki/domain/seed.rb
708
712
  - lib/mumuki/domain/status.rb
709
713
  - lib/mumuki/domain/status/discussion/closed.rb