mumuki-domain 7.11.1 → 7.12.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: f0741bd4448950db1d082d665156e2c44f6dffbdf5446b2bcdb292645b541e7f
4
- data.tar.gz: b1fc47e3b26d394b05a74b3e79956c2f76374604f4cdce281c72590f3d11190c
3
+ metadata.gz: 14e176a8030ca77ad3bfe8319f3cbad4eccef1f66b5f18ed293261a2b64bde1b
4
+ data.tar.gz: 6cedd7c76389861d2bbf2f850d4a3f1f66b57f2277ecd6ebe3fb1dcd12b1cf84
5
5
  SHA512:
6
- metadata.gz: 4d3162dfff77952888d226889a51a88a12058634253dfd2a64154701c3be0322a0d374e050a94ccfca6ef614062c8f9ebc97817e75b5e19eeea14ef6d8aa5f82
7
- data.tar.gz: 7361c7ed82288dcc41ec41294811130cfc4f9cd8ba38761087589001ed2d3ea13b0b64d4e1906918442b7f63aad2c13dada768a2a59fba5121285c9d6f10090d
6
+ metadata.gz: 3bf0726d9a3b8b0fb2e3a869a6db125e98a67934285780566e903994a16c0693c7fb879fd044a94807cce5ea03102955a9b69096fb78d6599aa39842153c2866
7
+ data.tar.gz: aed09dedbfe35d98c18f3d6c290b96650e95973f549990402a2e02af831fb29b7d040c1ad8d79d6dff0343d81006c686694cc4330bd4a7e6992b8894e0d11139
@@ -0,0 +1,57 @@
1
+ module WithTermsAcceptance
2
+ def has_forum_terms_to_accept?
3
+ !has_accepted_all?(forum_terms)
4
+ end
5
+
6
+ def has_profile_terms_to_accept?
7
+ !has_accepted_all?(profile_terms)
8
+ end
9
+
10
+ def forum_terms
11
+ @forum_terms ||= Term.forum_related_terms
12
+ end
13
+
14
+ def profile_terms
15
+ @profile_terms ||= Term.profile_terms_for(self)
16
+ end
17
+
18
+ def accept_profile_terms!
19
+ accept_terms! profile_terms
20
+ end
21
+
22
+ def accept_forum_terms!
23
+ accept_terms! forum_terms
24
+ end
25
+
26
+ def has_accepted?(term)
27
+ term_accepted_at_for(term.scope).try { |it| it > term.updated_at }.present?
28
+ end
29
+
30
+ private
31
+
32
+ def unaccepted_terms_in(terms)
33
+ terms.reject { |term| has_accepted? term}
34
+ end
35
+
36
+ def unaccepted_terms_scopes_in(terms)
37
+ unaccepted_terms_in(terms).map(&:scope)
38
+ end
39
+
40
+ def has_accepted_all?(terms)
41
+ unaccepted_terms_in(terms).blank?
42
+ end
43
+
44
+ def term_accepted_at_for(role)
45
+ send term_acceptance_field_for(role)
46
+ end
47
+
48
+ def term_acceptance_field_for(role)
49
+ "#{role}_terms_accepted_at"
50
+ end
51
+
52
+ def accept_terms!(terms)
53
+ update! unaccepted_terms_scopes_in(terms).to_h { |scope| [term_acceptance_field_for(scope), Time.now] }
54
+ end
55
+
56
+ end
57
+
@@ -0,0 +1,40 @@
1
+ class Term < ApplicationRecord
2
+ attribute :locale, :string, default: 'es'
3
+ markdown_on :content
4
+
5
+ GENERAL = %w(legal privacy student)
6
+ ROLE_SPECIFIC = %w(headmaster janitor teacher moderator)
7
+ FORUM_RELATED = %w(forum)
8
+
9
+ validates :locale, uniqueness: { scope: :scope }
10
+ validates :content, :scope, :header, presence: true
11
+
12
+ def self.terms_for(scope, locale)
13
+ where(scope: scope, locale: locale)
14
+ end
15
+
16
+ def self.profile_terms_for(user, locale = I18n.locale)
17
+ general_terms(locale) + role_specific_terms_for(user, locale)
18
+ end
19
+
20
+ def self.role_specific_terms_for(user, locale = I18n.locale)
21
+ terms_for(current_role_terms_for(user), locale)
22
+ end
23
+
24
+ def self.general_terms(locale = I18n.locale)
25
+ terms_for(GENERAL, locale)
26
+ end
27
+
28
+ def self.forum_related_terms(locale = I18n.locale)
29
+ terms_for(FORUM_RELATED, locale)
30
+ end
31
+
32
+ def self.current_role_terms_for(user)
33
+ return [] unless user.present?
34
+ (user.any_granted_roles & ROLE_SPECIFIC).to_a
35
+ end
36
+
37
+ def accepted_by?(user)
38
+ user.term_accepted_at_for(scope).try { |it| it > updated_at }.present?
39
+ end
40
+ end
@@ -6,12 +6,13 @@ class User < ApplicationRecord
6
6
  WithDiscussionCreation,
7
7
  Awardee,
8
8
  Disabling,
9
+ WithTermsAcceptance,
9
10
  Mumuki::Domain::Helpers::User
10
11
 
11
12
  serialize :permissions, Mumukit::Auth::Permissions
12
13
 
13
- has_many :assignments, foreign_key: :submitter_id
14
14
 
15
+ has_many :assignments, foreign_key: :submitter_id
15
16
  has_many :messages, -> { order(created_at: :desc) }, through: :assignments
16
17
 
17
18
  has_many :submitted_exercises, through: :assignments, class_name: 'Exercise', source: :exercise
@@ -37,6 +38,7 @@ class User < ApplicationRecord
37
38
  before_validation :set_uid!
38
39
  validates :uid, presence: true
39
40
 
41
+ validates :terms_of_service, acceptance: true
40
42
  after_save :welcome_to_new_organizations!, if: :gained_access_to_new_orga?
41
43
  after_initialize :init
42
44
  PLACEHOLDER_IMAGE_URL = 'user_shape.png'.freeze
@@ -0,0 +1,14 @@
1
+ class AddTermsForUser < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :users, :headmaster_terms_accepted_at, :datetime
4
+ add_column :users, :janitor_terms_accepted_at, :datetime
5
+ add_column :users, :moderator_terms_accepted_at, :datetime
6
+ add_column :users, :student_terms_accepted_at, :datetime
7
+ add_column :users, :teacher_terms_accepted_at, :datetime
8
+
9
+ add_column :users, :privacy_terms_accepted_at, :datetime
10
+ add_column :users, :legal_terms_accepted_at, :datetime
11
+
12
+ add_column :users, :forum_terms_accepted_at, :datetime
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class CreateTerms < ActiveRecord::Migration[5.1]
2
+ def change
3
+ create_table :terms do |t|
4
+ t.string :locale
5
+ t.string :scope
6
+ t.text :content
7
+ t.text :header
8
+
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -15,6 +15,7 @@ require_relative './factories/login_settings_factory'
15
15
  require_relative './factories/medal_factory'
16
16
  require_relative './factories/message_factory'
17
17
  require_relative './factories/organization_factory'
18
+ require_relative './factories/term_factory'
18
19
  require_relative './factories/topic_factory'
19
20
  require_relative './factories/usage_factory'
20
21
  require_relative './factories/user_factory'
@@ -0,0 +1,7 @@
1
+ FactoryBot.define do
2
+ factory :term do
3
+ content { Faker::Lorem.sentence(word_count: 2000) }
4
+ header { Faker::Lorem.sentence(word_count: 5) }
5
+ end
6
+ end
7
+
@@ -15,6 +15,7 @@ module Mumuki::Domain::Helpers::User
15
15
  :protect_permissions_assignment!,
16
16
  :student_granted_organizations,
17
17
  :any_granted_organizations,
18
+ :any_granted_roles,
18
19
  to: :permissions
19
20
 
20
21
  def platform_class_name
@@ -56,6 +56,26 @@ module Mumuki::Domain
56
56
  []
57
57
  end
58
58
 
59
+ def any_granted_roles
60
+ []
61
+ end
62
+
63
+ # ========
64
+ # Terms
65
+ # ========
66
+
67
+ def accepted_profile_terms?
68
+ true
69
+ end
70
+
71
+ def accepted_forum_terms?
72
+ true
73
+ end
74
+
75
+ def has_accepted?(term)
76
+ false
77
+ end
78
+
59
79
  # ========
60
80
  # Visiting
61
81
  # ========
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '7.11.1'
3
+ VERSION = '7.12.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: 7.11.1
4
+ version: 7.12.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-11-03 00:00:00.000000000 Z
11
+ date: 2020-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '7.8'
33
+ version: '7.9'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '7.8'
40
+ version: '7.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: mumukit-assistant
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -86,14 +86,14 @@ dependencies:
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '1.13'
89
+ version: '1.18'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '1.13'
96
+ version: '1.18'
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: mumukit-directives
99
99
  requirement: !ruby/object:Gem::Requirement
@@ -296,6 +296,7 @@ files:
296
296
  - app/models/concerns/with_scoped_queries/sort.rb
297
297
  - app/models/concerns/with_slug.rb
298
298
  - app/models/concerns/with_target_audience.rb
299
+ - app/models/concerns/with_terms_acceptance.rb
299
300
  - app/models/concerns/with_usages.rb
300
301
  - app/models/concerns/with_user_navigation.rb
301
302
  - app/models/content.rb
@@ -323,6 +324,7 @@ files:
323
324
  - app/models/progress.rb
324
325
  - app/models/stats.rb
325
326
  - app/models/subscription.rb
327
+ - app/models/term.rb
326
328
  - app/models/topic.rb
327
329
  - app/models/upvote.rb
328
330
  - app/models/usage.rb
@@ -627,11 +629,13 @@ files:
627
629
  - db/migrate/20200828162829_add_medal_to_content.rb
628
630
  - db/migrate/20200915123020_add_polymorphic_avatars_to_users.rb
629
631
  - db/migrate/20200915131621_add_once_completed_to_indicators.rb
632
+ - db/migrate/20201007143455_add_terms_for_user.rb
630
633
  - db/migrate/20201009193949_add_status_updated_fields_to_discussion.rb
631
634
  - db/migrate/20201019191036_add_misplaced_flag_to_submission.rb
632
635
  - db/migrate/20201026222942_add_display_name_and_description_to_organizations.rb
633
636
  - db/migrate/20201026225312_add_organization_wins_page_flag.rb
634
637
  - db/migrate/20201027134205_add_immersible_to_organization.rb
638
+ - db/migrate/20201027152806_create_terms.rb
635
639
  - lib/mumuki/domain.rb
636
640
  - lib/mumuki/domain/area.rb
637
641
  - lib/mumuki/domain/engine.rb
@@ -671,6 +675,7 @@ files:
671
675
  - lib/mumuki/domain/factories/medal_factory.rb
672
676
  - lib/mumuki/domain/factories/message_factory.rb
673
677
  - lib/mumuki/domain/factories/organization_factory.rb
678
+ - lib/mumuki/domain/factories/term_factory.rb
674
679
  - lib/mumuki/domain/factories/topic_factory.rb
675
680
  - lib/mumuki/domain/factories/usage_factory.rb
676
681
  - lib/mumuki/domain/factories/user_factory.rb