mumuki-domain 7.0.5 → 7.0.6

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: 43e248d7eff85d6875aa00ba46a874ec5084305197ab4bd6d3a80d84c2aa15ee
4
- data.tar.gz: b859a8015918f66bf45beda113c132424b6ab569c4047854ae6bcb750a6d4f17
3
+ metadata.gz: c111563c53bbd8b40ee80ea56f0d3dc90f8c8ac666ca1688fb8419745bc63cff
4
+ data.tar.gz: 298300bc4e45eda5c512c637b91e90f10cc13c80b6e7fa9155c485b4bfce56ad
5
5
  SHA512:
6
- metadata.gz: 8c4c355bf7e2fb98b1326b5fd175fd4178ad2c0c8e75d50d539b677a548121b2ed52f787ed34083a6f1a92b67e1d60e4e76e6f3f657fa862c22e4b562cdaa738
7
- data.tar.gz: 68ac57f0292ab290af52b373fdaf32fb927c86666eecaf70981588870867b0a4faa32186e7bf9e45be1f81854e2f301b2a121bec79497b74d3dd0f601b03eedb
6
+ metadata.gz: f452c3d9383b0b59a458a88332e879351e342d63e574e512bb1c70adb9b3b3a11c24019ac86a86425910d72a19a8c9f686ee62bab4924add598c827df1843003
7
+ data.tar.gz: 8afb07a6b0ea3d070311fd70008f008059366889ee78509dff3f17b47a10713b4d30c4db04a5926bc3d439ce5a1183ca846057ddd80b39e620b3b39315b6fc9a
data/app/models/exam.rb CHANGED
@@ -96,13 +96,21 @@ class Exam < ApplicationRecord
96
96
  authorization_for(user).started_at
97
97
  end
98
98
 
99
+ def authorize_users!(users)
100
+ users.each { |user| authorize! user }
101
+ end
102
+
103
+ def unauthorize_users!(users)
104
+ authorizations_for(users).destroy_all
105
+ end
106
+
99
107
  def process_users(users)
100
- users.map { |user| authorize! user }
108
+ authorize_users!(users)
101
109
  clean_authorizations users
102
110
  end
103
111
 
104
- def clean_authorizations(users)
105
- authorizations.all_except(authorizations_for(users)).destroy_all
112
+ def clean_authorizations(authorized_users)
113
+ unauthorize_users!(users.all_except(authorized_users))
106
114
  end
107
115
 
108
116
  def reindex_usages!
@@ -111,7 +119,7 @@ class Exam < ApplicationRecord
111
119
 
112
120
  def self.import_from_resource_h!(json)
113
121
  exam_data = json.with_indifferent_access
114
- organization = Organization.find_by!(name: exam_data[:organization])
122
+ organization = Organization.locate! exam_data[:organization]
115
123
  organization.switch!
116
124
  adapt_json_values exam_data
117
125
  remove_previous_version exam_data[:eid], exam_data[:guide_id]
@@ -120,8 +128,19 @@ class Exam < ApplicationRecord
120
128
  exam
121
129
  end
122
130
 
131
+ def self.upsert_students!(json)
132
+ data = json.with_indifferent_access
133
+ exam = find_by(classroom_id: data[:eid])
134
+
135
+ added_users = User.where(uid: data[:added])
136
+ deleted_users = User.where(uid: data[:deleted])
137
+
138
+ exam.authorize_users! added_users
139
+ exam.unauthorize_users! deleted_users
140
+ end
141
+
123
142
  def self.adapt_json_values(exam)
124
- exam[:guide_id] = Guide.find_by(slug: exam[:slug]).id
143
+ exam[:guide_id] = Guide.locate!(exam[:slug]).id
125
144
  exam[:organization_id] = Organization.current.id
126
145
  exam[:users] = User.where(uid: exam[:uids])
127
146
  [:start_time, :end_time].each { |param| exam[param] = exam[param].to_time }
@@ -1,5 +1,5 @@
1
1
  module Mumuki
2
2
  module Domain
3
- VERSION = '7.0.5'
3
+ VERSION = '7.0.6'
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.0.5
4
+ version: 7.0.6
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-11-29 00:00:00.000000000 Z
11
+ date: 2019-12-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails