mumuki-domain 7.7.1 → 7.7.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: f1efee52b12a7be242fdb13883331838d1ee17e0a396d5b0df95b54c3d209bdb
4
- data.tar.gz: a6e75dfa224cd6a3642c77d23d1190906d427506b0fb90905b1f636f2c9ecd72
3
+ metadata.gz: f58b3302ee7ffdf0a503a9a4dc816e00a9f11c62d2b6792512834c9289e190a9
4
+ data.tar.gz: fd9b0bdcecb5dd0cc3a56234af7718e6b6a4440b3117f620786f5fd5aa981295
5
5
  SHA512:
6
- metadata.gz: f66e5cb6acf1f40de30d9a1da7056626eeb513db95822a75b4b59fae0fbe0718795fd5ad33c38fd2df1e5a277d3a1b5390c78b87558c4976b4cc72921912f86f
7
- data.tar.gz: 6f2e61ba1908513448c72c448cb1e0f92582e502304d6756bdb82f4ca4d0a9dfe783fc12669613ea4bf99cd3e1bf2b8397ac6142e28cad8517dd0123175dbfcb
6
+ metadata.gz: 85ec2a5cc695671fdc09471348b62bf88456ea5ad95c40225c1e66dfd45851dcfaff45d0b5e834e119834ab09dfb83e6579955c68d0fbc6e2fdf7c2b87b7687b
7
+ data.tar.gz: e011c6f5cef571718d98980a58b51ecad15d8efcdecd253892889eb64ae7ca1b3521e30068454e67ff519204f77110d96b90d6cdee91fe5beb195bdaace31959
@@ -20,6 +20,8 @@ class Assignment < Progress
20
20
  delegate :language, :name, :navigable_parent, :settings,
21
21
  :limited?, :input_kids?, :choice?, :results_hidden?, to: :exercise
22
22
 
23
+ delegate :completed?, :solved?, to: :submission_status
24
+
23
25
  alias_attribute :status, :submission_status
24
26
  alias_attribute :attempts_count, :attemps_count
25
27
 
@@ -8,8 +8,6 @@ class Book < Content
8
8
  has_many :complements, dependent: :destroy
9
9
 
10
10
  has_many :exercises, through: :chapters
11
- has_many :discussions, through: :exercises
12
- organic_on :discussions
13
11
 
14
12
  delegate :first_lesson, to: :first_chapter
15
13
 
@@ -19,6 +17,10 @@ class Book < Content
19
17
  slug
20
18
  end
21
19
 
20
+ def discussions_in_organization(organization = Organization.current)
21
+ Discussion.where(organization: organization).includes(exercise: [:language, :guide])
22
+ end
23
+
22
24
  def first_chapter
23
25
  chapters.first
24
26
  end
@@ -25,7 +25,7 @@ module Contextualization
25
25
 
26
26
  delegate :visible_success_output?, to: :exercise
27
27
  delegate :output_content_type, to: :language
28
- delegate :should_retry?, :to_submission_status, :completed?, :solved?, *Mumuki::Domain::Status::Submission.test_selectors, to: :submission_status
28
+ delegate :should_retry?, :to_submission_status, *Mumuki::Domain::Status::Submission.test_selectors, to: :submission_status
29
29
  delegate :inspection_keywords, to: :exercise
30
30
  end
31
31
 
@@ -1,7 +1,7 @@
1
1
  module Solvable
2
2
  def submit_solution!(user, submission_attributes={})
3
3
  assignment, _ = find_assignment_and_submit! user, solution_for(submission_attributes)
4
- try_solve_discussions(user) if assignment.solved?
4
+ try_solve_discussions!(user) if assignment.solved?
5
5
  assignment
6
6
  end
7
7
 
@@ -14,7 +14,7 @@ module WithDiscussions
14
14
  nil
15
15
  end
16
16
 
17
- def try_solve_discussions(user)
17
+ def try_solve_discussions!(user)
18
18
  discussions.where(initiator: user).map(&:try_solve!)
19
19
  end
20
20
 
@@ -105,10 +105,6 @@ class Discussion < ApplicationRecord
105
105
  reachable_statuses_for(user).include? status
106
106
  end
107
107
 
108
- def allowed_statuses_for(user)
109
- status.allowed_statuses_for(user, self)
110
- end
111
-
112
108
  def update_status!(status, user)
113
109
  update!(status: status) if reachable_status_for?(user, status)
114
110
  end
@@ -125,6 +121,10 @@ class Discussion < ApplicationRecord
125
121
  responses_count > 0
126
122
  end
127
123
 
124
+ def has_validated_responses?
125
+ validated_messages_count > 0
126
+ end
127
+
128
128
  def subscribe_initiator!
129
129
  initiator.subscribe_to! self
130
130
  end
@@ -138,10 +138,10 @@ class Discussion < ApplicationRecord
138
138
  def update_counters!
139
139
  messages_query = messages_by_updated_at
140
140
  validated_messages = messages_query.select &:validated?
141
- requires_moderator_response = messages_query.find { |it| it.validated? || it.question? }&.from_initiator?
141
+ has_moderator_response = messages_query.find { |it| it.validated? || it.question? }&.validated?
142
142
  update! messages_count: messages_query.count,
143
143
  validated_messages_count: validated_messages.count,
144
- requires_moderator_response: requires_moderator_response
144
+ requires_moderator_response: !has_moderator_response
145
145
  end
146
146
 
147
147
  def update_last_moderator_access!(user)
@@ -105,17 +105,8 @@ class Organization < ApplicationRecord
105
105
  # ask for help in this organization
106
106
  #
107
107
  # Warning: this method does not strictly check user's permission
108
- def ask_for_help_enabled?(user = nil)
109
- report_issue_enabled? || community_link.present? || can_create_discussions?(user)
110
- end
111
-
112
- # Tells if the given user can
113
- # create discussion in this organization
114
- #
115
- # This is true only when this organization has a forum and the user
116
- # has the discusser pseudo-permission
117
- def can_create_discussions?(user = nil)
118
- forum_enabled? && (!user || user.discusser_of?(self))
108
+ def ask_for_help_enabled?(user)
109
+ report_issue_enabled? || community_link.present? || user.can_discuss_in?(self)
119
110
  end
120
111
 
121
112
  def import_from_resource_h!(resource_h)
@@ -169,6 +169,22 @@ class User < ApplicationRecord
169
169
  sequence[0..count + lookahead - 1]
170
170
  end
171
171
 
172
+ # Tells if the given user can discuss in an organization
173
+ #
174
+ # This is true only when this organization has the forum enabled and the user
175
+ # has the discusser pseudo-permission and the discusser is trusted
176
+ def can_discuss_in?(organization)
177
+ organization.forum_enabled? && discusser_of?(organization) && trusted_as_discusser_in?(organization)
178
+ end
179
+
180
+ def trusted_as_discusser_in?(organization)
181
+ trusted_for_forum? || !organization.forum_only_for_trusted?
182
+ end
183
+
184
+ def can_discuss_here?
185
+ can_discuss_in? Organization.current
186
+ end
187
+
172
188
  def name_initials
173
189
  name.split.map(&:first).map(&:capitalize).join(' ')
174
190
  end
@@ -0,0 +1,5 @@
1
+ class AddTrustedForForumToUser < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_column :users, :trusted_for_forum, :boolean
4
+ end
5
+ end
@@ -1,7 +1,7 @@
1
1
  FactoryBot.define do
2
2
  factory :discussion do
3
- title { 'A discussion' }
4
- description { 'A discussion description' }
3
+ title { Faker::Lorem.sentence(word_count: 2) }
4
+ description { Faker::Lorem.sentence(word_count: 5) }
5
5
  initiator { create(:user) }
6
6
  item { create(:exercise) }
7
7
  organization { Organization.current rescue nil }
@@ -1,11 +1,6 @@
1
1
  FactoryBot.define do
2
2
 
3
3
  factory :message do
4
- exercise_id { Faker::Internet.number(2) }
5
- assignment
6
- submission_id { assignment.id }
7
- sender { Faker::Internet.email }
8
- type { 'success' }
9
- content { Faker::Lorem.sentence(3) }
4
+ content { Faker::Lorem.sentence(word_count: 3) }
10
5
  end
11
6
  end
@@ -1,20 +1,21 @@
1
1
  class Mumuki::Domain::Organization::Settings < Mumukit::Platform::Model
2
2
  include Mumukit::Login::LoginSettingsHelpers
3
3
 
4
- model_attr_accessor :login_methods,
5
- :login_provider,
6
- :login_provider_settings,
7
- :forum_discussions_minimal_role,
8
- :raise_hand_enabled?,
9
- :feedback_suggestions_enabled?,
10
- :public?,
4
+ model_attr_accessor :disabled_from,
11
5
  :embeddable?,
12
- :immersive?,
6
+ :feedback_suggestions_enabled?,
7
+ :forum_discussions_minimal_role,
13
8
  :forum_enabled?,
14
- :report_issue_enabled?,
15
- :disabled_from,
9
+ :forum_only_for_trusted?,
10
+ :gamification_enabled?,
11
+ :immersive?,
16
12
  :in_preparation_until,
17
- :gamification_enabled?
13
+ :login_methods,
14
+ :login_provider,
15
+ :login_provider_settings,
16
+ :public?,
17
+ :raise_hand_enabled?,
18
+ :report_issue_enabled?
18
19
 
19
20
  def private?
20
21
  !public?
@@ -14,10 +14,6 @@ module Mumuki::Domain::Status::Discussion
14
14
  define_method(selector) { false }
15
15
  end
16
16
 
17
- def allowed_for?(*)
18
- true
19
- end
20
-
21
17
  def reachable_statuses_for_moderator(*)
22
18
  []
23
19
  end
@@ -38,10 +34,6 @@ module Mumuki::Domain::Status::Discussion
38
34
  end
39
35
  end
40
36
 
41
- def allowed_statuses_for(user, discussion)
42
- STATUSES.select { |it| it.allowed_for?(user, discussion) }
43
- end
44
-
45
37
  def as_json(_options={})
46
38
  to_s
47
39
  end
@@ -5,6 +5,14 @@ module Mumuki::Domain::Status::Discussion::Opened
5
5
  true
6
6
  end
7
7
 
8
+ def self.reachable_statuses_for_initiator(discussion)
9
+ if discussion.has_responses?
10
+ [Mumuki::Domain::Status::Discussion::PendingReview]
11
+ else
12
+ [Mumuki::Domain::Status::Discussion::Closed]
13
+ end
14
+ end
15
+
8
16
  def self.reachable_statuses_for_moderator(discussion)
9
17
  if discussion.has_responses?
10
18
  [Mumuki::Domain::Status::Discussion::Closed, Mumuki::Domain::Status::Discussion::Solved]
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '7.7.1'
3
+ VERSION = '7.7.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.7.1
4
+ version: 7.7.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-07-31 00:00:00.000000000 Z
11
+ date: 2020-08-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -611,6 +611,7 @@ files:
611
611
  - db/migrate/20200702165503_add_messages_count_to_discussion.rb
612
612
  - db/migrate/20200728162727_add_not_actually_a_question_field_to_messages.rb
613
613
  - db/migrate/20200728163038_add_requires_moderator_response_to_discussions.rb
614
+ - db/migrate/20200730221001_add_trusted_for_forum_to_user.rb
614
615
  - db/migrate/20200731081757_add_last_moderator_access_fields_to_discussion.rb
615
616
  - lib/mumuki/domain.rb
616
617
  - lib/mumuki/domain/area.rb