mumukit-platform 4.1.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -1
- data/.travis.yml +2 -2
- data/README.md +16 -1
- data/lib/mumukit/platform.rb +15 -1
- data/lib/mumukit/platform/course.rb +6 -2
- data/lib/mumukit/platform/global.rb +19 -0
- data/lib/mumukit/platform/locale.rb +1 -0
- data/lib/mumukit/platform/organization.rb +16 -17
- data/lib/mumukit/platform/organization_mapping.rb +4 -4
- data/lib/mumukit/platform/user.rb +0 -2
- data/lib/mumukit/platform/version.rb +1 -1
- data/lib/mumukit/platform/web_framework.rb +1 -1
- data/mumukit-platform.gemspec +3 -3
- metadata +16 -15
- data/lib/mumukit/platform/course/helpers.rb +0 -43
- data/lib/mumukit/platform/organization/helpers.rb +0 -112
- data/lib/mumukit/platform/organization/profile.rb +0 -39
- data/lib/mumukit/platform/organization/settings.rb +0 -20
- data/lib/mumukit/platform/organization/theme.rb +0 -4
- data/lib/mumukit/platform/user/helpers.rb +0 -127
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bc124483195c06cf33bf27f455441909cd2b2c125b267a55accc3648a7578719
|
4
|
+
data.tar.gz: 6e8c63c1dd6af7720411e7df5df9e29097c6527ac8a924830873fe87a6ba8686
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ab495d8e8baffff929cdafd9546b1232656a73cec3065ea2d72fdff6966267681b130a7991aafab699be1301c2641ce9278ceea803fdabcb9ceb6ee24ece72dd
|
7
|
+
data.tar.gz: 7eb34685b1ae105e99a625995987605f2481f4251a80942681bf3988bda36f3f1ed1da5e5a0e53ced8d97a28da61565707de27e7944ffc89a3089d8038eccdf5
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.3
|
1
|
+
2.6.3
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -23,6 +23,22 @@ Or install it yourself as:
|
|
23
23
|
|
24
24
|
$ gem install mumukit-platform
|
25
25
|
|
26
|
+
## Requeriments
|
27
|
+
|
28
|
+
In order to properly use this gem, you must declare _organization_, _course_ and _user_ classes, and implement some required methods:
|
29
|
+
|
30
|
+
_organization_:
|
31
|
+
* `#name`
|
32
|
+
* `#locale`
|
33
|
+
* `.find_by_name!`
|
34
|
+
|
35
|
+
_user_:
|
36
|
+
* `.find_by_uid!`
|
37
|
+
|
38
|
+
_course_:
|
39
|
+
* `.find_by_slug!`
|
40
|
+
|
41
|
+
|
26
42
|
## Contributing
|
27
43
|
|
28
44
|
Bug reports and pull requests are welcome on GitHub at https://github.com/mumuki/mumukit-platform. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
@@ -30,4 +46,3 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/mumuki
|
|
30
46
|
## License
|
31
47
|
|
32
48
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
33
|
-
|
data/lib/mumukit/platform.rb
CHANGED
@@ -26,6 +26,19 @@ module Mumukit::Platform
|
|
26
26
|
end
|
27
27
|
|
28
28
|
CORE_MODELS.each do |klass|
|
29
|
+
# Configured classes must implement the following methods:
|
30
|
+
#
|
31
|
+
# _organization_:
|
32
|
+
# * `#name`
|
33
|
+
# * `#locale`
|
34
|
+
# * `.find_by_name!`
|
35
|
+
#
|
36
|
+
# _user_:
|
37
|
+
# * `.find_by_uid!`
|
38
|
+
#
|
39
|
+
# _course_:
|
40
|
+
# * `.find_by_slug!`
|
41
|
+
#
|
29
42
|
define_singleton_method("#{klass}_class") do
|
30
43
|
begin
|
31
44
|
config["#{klass}_class"] ||= config["#{klass}_class_name"].constantize
|
@@ -38,12 +51,13 @@ end
|
|
38
51
|
|
39
52
|
require_relative './platform/notifiable'
|
40
53
|
|
54
|
+
require_relative './platform/global'
|
41
55
|
require_relative './platform/domain'
|
42
56
|
require_relative './platform/model'
|
43
57
|
require_relative './platform/locale'
|
44
58
|
require_relative './platform/course'
|
45
|
-
require_relative './platform/user'
|
46
59
|
require_relative './platform/organization'
|
60
|
+
require_relative './platform/user'
|
47
61
|
require_relative './platform/organization_mapping'
|
48
62
|
require_relative './platform/application'
|
49
63
|
require_relative './platform/web_framework'
|
@@ -1,7 +1,11 @@
|
|
1
1
|
module Mumukit::Platform::Course
|
2
|
+
extend Mumukit::Platform::Global
|
3
|
+
|
2
4
|
def self.find_by_slug!(slug)
|
3
5
|
Mumukit::Platform.course_class.find_by_slug!(slug)
|
4
6
|
end
|
5
|
-
end
|
6
7
|
|
7
|
-
|
8
|
+
def self.__global_thread_variable_key__
|
9
|
+
:course
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mumukit::Platform::Global
|
2
|
+
def switch!(global)
|
3
|
+
raise "#{__global_thread_variable_key__} must not be nil" unless global
|
4
|
+
Thread.current[__global_thread_variable_key__] = global
|
5
|
+
end
|
6
|
+
|
7
|
+
def leave!
|
8
|
+
Thread.current[__global_thread_variable_key__] = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
def current
|
12
|
+
Thread.current[__global_thread_variable_key__] || raise("#{__global_thread_variable_key__} not selected")
|
13
|
+
end
|
14
|
+
|
15
|
+
def current?
|
16
|
+
!!Thread.current[__global_thread_variable_key__]
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
@@ -2,6 +2,7 @@ module Mumukit::Platform::Locale
|
|
2
2
|
SPECS = {
|
3
3
|
en: { facebook_code: :en_US, auth0_code: :en, name: 'English' },
|
4
4
|
es: { facebook_code: :es_LA, auth0_code: :es, name: 'Español' },
|
5
|
+
'es-CL': { facebook_code: :es_LA, auth0_code: :es, name: 'Español chileno' },
|
5
6
|
pt: { facebook_code: :pt_BR, auth0_code: 'pt-br', name: 'Português' }
|
6
7
|
}.with_indifferent_access
|
7
8
|
|
@@ -1,31 +1,30 @@
|
|
1
1
|
module Mumukit::Platform::Organization
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
extend Mumukit::Platform::Global
|
3
|
+
|
4
|
+
def self.current_locale
|
5
|
+
Thread.current[:organization]&.locale || 'en'
|
5
6
|
end
|
6
7
|
|
7
|
-
def self.
|
8
|
-
|
8
|
+
def self.find_by_name!(name)
|
9
|
+
Mumukit::Platform.organization_class.find_by_name!(name)
|
9
10
|
end
|
10
11
|
|
11
|
-
def self.
|
12
|
-
|
12
|
+
def self.__global_thread_variable_key__
|
13
|
+
:organization
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
-
|
16
|
+
## Name validation
|
17
|
+
|
18
|
+
def self.valid_name?(name)
|
19
|
+
!!(name =~ anchored_valid_name_regex)
|
17
20
|
end
|
18
21
|
|
19
|
-
def self.
|
20
|
-
|
22
|
+
def self.anchored_valid_name_regex
|
23
|
+
/\A#{valid_name_regex}\z/
|
21
24
|
end
|
22
25
|
|
23
|
-
def self.
|
24
|
-
|
26
|
+
def self.valid_name_regex
|
27
|
+
/([-a-z0-9_]+(\.[-a-z0-9_]+)*)?/
|
25
28
|
end
|
26
29
|
end
|
27
30
|
|
28
|
-
require_relative './organization/settings'
|
29
|
-
require_relative './organization/profile'
|
30
|
-
require_relative './organization/theme'
|
31
|
-
require_relative './organization/helpers'
|
@@ -9,10 +9,10 @@ module Mumukit::Platform::OrganizationMapping
|
|
9
9
|
|
10
10
|
def self.parse(name)
|
11
11
|
mapping = name.try { |it| it.strip.downcase }
|
12
|
-
if mapping.blank? || mapping == '
|
13
|
-
Subdomain
|
14
|
-
elsif mapping == 'path'
|
12
|
+
if mapping.blank? || mapping == 'path'
|
15
13
|
Path
|
14
|
+
elsif mapping == 'subdomain'
|
15
|
+
Subdomain
|
16
16
|
else
|
17
17
|
raise "Unrecognized organization mapping #{mapping}"
|
18
18
|
end
|
@@ -50,7 +50,7 @@ module Mumukit::Platform::OrganizationMapping
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def self.organization_name(request, _domain)
|
53
|
-
request.
|
53
|
+
request.path_info.split('/')[1]
|
54
54
|
end
|
55
55
|
|
56
56
|
def self.organic_uri(uri, organization)
|
@@ -21,7 +21,7 @@ module Mumukit::Platform::WebFramework
|
|
21
21
|
def self.tenant_scope_options
|
22
22
|
{
|
23
23
|
defaults: { tenant: lazy_string { Mumukit::Platform.current_organization_name } },
|
24
|
-
constraints: { tenant: Mumukit::Platform::Organization
|
24
|
+
constraints: { tenant: Mumukit::Platform::Organization.valid_name_regex }
|
25
25
|
}
|
26
26
|
end
|
27
27
|
end
|
data/mumukit-platform.gemspec
CHANGED
@@ -24,10 +24,10 @@ Gem::Specification.new do |spec|
|
|
24
24
|
spec.add_dependency 'mumukit-nuntius', '~> 6.0'
|
25
25
|
spec.add_dependency 'mumukit-core', '~> 1.2'
|
26
26
|
spec.add_dependency 'mumukit-auth', '~> 7.6'
|
27
|
-
spec.add_dependency 'mumukit-bridge', '
|
27
|
+
spec.add_dependency 'mumukit-bridge', '>= 3.5', '< 5'
|
28
28
|
spec.add_dependency 'activemodel', '>= 4.0'
|
29
29
|
|
30
|
-
spec.add_development_dependency 'bundler', '~>
|
31
|
-
spec.add_development_dependency 'rake', '~>
|
30
|
+
spec.add_development_dependency 'bundler', '~> 2.0'
|
31
|
+
spec.add_development_dependency 'rake', '~> 12.3'
|
32
32
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
33
33
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mumukit-platform
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Franco Leonardo Bulgarelli
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-08-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mumukit-nuntius
|
@@ -56,16 +56,22 @@ dependencies:
|
|
56
56
|
name: mumukit-bridge
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '3.5'
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '5'
|
62
65
|
type: :runtime
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
65
68
|
requirements:
|
66
|
-
- - "
|
69
|
+
- - ">="
|
67
70
|
- !ruby/object:Gem::Version
|
68
71
|
version: '3.5'
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '5'
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: activemodel
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,28 +92,28 @@ dependencies:
|
|
86
92
|
requirements:
|
87
93
|
- - "~>"
|
88
94
|
- !ruby/object:Gem::Version
|
89
|
-
version: '
|
95
|
+
version: '2.0'
|
90
96
|
type: :development
|
91
97
|
prerelease: false
|
92
98
|
version_requirements: !ruby/object:Gem::Requirement
|
93
99
|
requirements:
|
94
100
|
- - "~>"
|
95
101
|
- !ruby/object:Gem::Version
|
96
|
-
version: '
|
102
|
+
version: '2.0'
|
97
103
|
- !ruby/object:Gem::Dependency
|
98
104
|
name: rake
|
99
105
|
requirement: !ruby/object:Gem::Requirement
|
100
106
|
requirements:
|
101
107
|
- - "~>"
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: '
|
109
|
+
version: '12.3'
|
104
110
|
type: :development
|
105
111
|
prerelease: false
|
106
112
|
version_requirements: !ruby/object:Gem::Requirement
|
107
113
|
requirements:
|
108
114
|
- - "~>"
|
109
115
|
- !ruby/object:Gem::Version
|
110
|
-
version: '
|
116
|
+
version: '12.3'
|
111
117
|
- !ruby/object:Gem::Dependency
|
112
118
|
name: rspec
|
113
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -144,20 +150,15 @@ files:
|
|
144
150
|
- lib/mumukit/platform/application.rb
|
145
151
|
- lib/mumukit/platform/bridge.rb
|
146
152
|
- lib/mumukit/platform/course.rb
|
147
|
-
- lib/mumukit/platform/course/helpers.rb
|
148
153
|
- lib/mumukit/platform/domain.rb
|
154
|
+
- lib/mumukit/platform/global.rb
|
149
155
|
- lib/mumukit/platform/locale.rb
|
150
156
|
- lib/mumukit/platform/model.rb
|
151
157
|
- lib/mumukit/platform/notifiable.rb
|
152
158
|
- lib/mumukit/platform/organization.rb
|
153
|
-
- lib/mumukit/platform/organization/helpers.rb
|
154
|
-
- lib/mumukit/platform/organization/profile.rb
|
155
|
-
- lib/mumukit/platform/organization/settings.rb
|
156
|
-
- lib/mumukit/platform/organization/theme.rb
|
157
159
|
- lib/mumukit/platform/organization_mapping.rb
|
158
160
|
- lib/mumukit/platform/uri.rb
|
159
161
|
- lib/mumukit/platform/user.rb
|
160
|
-
- lib/mumukit/platform/user/helpers.rb
|
161
162
|
- lib/mumukit/platform/version.rb
|
162
163
|
- lib/mumukit/platform/web_framework.rb
|
163
164
|
- lib/mumukit/platform/with_applications.rb
|
@@ -184,7 +185,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
184
185
|
- !ruby/object:Gem::Version
|
185
186
|
version: '0'
|
186
187
|
requirements: []
|
187
|
-
rubygems_version: 3.0.
|
188
|
+
rubygems_version: 3.0.8
|
188
189
|
signing_key:
|
189
190
|
specification_version: 4
|
190
191
|
summary: Shared Mumuki Platform Components
|
@@ -1,43 +0,0 @@
|
|
1
|
-
module Mumukit::Platform::Course::Helpers
|
2
|
-
include Mumukit::Platform::Notifiable
|
3
|
-
|
4
|
-
## Implementors must declare the following methods:
|
5
|
-
#
|
6
|
-
# * slug
|
7
|
-
# * shifts
|
8
|
-
# * code
|
9
|
-
# * days
|
10
|
-
# * period
|
11
|
-
# * description
|
12
|
-
|
13
|
-
def platform_class_name
|
14
|
-
:Course
|
15
|
-
end
|
16
|
-
|
17
|
-
## API Exposure
|
18
|
-
|
19
|
-
def to_param
|
20
|
-
slug
|
21
|
-
end
|
22
|
-
|
23
|
-
## Resource Hash
|
24
|
-
|
25
|
-
def self.slice_resource_h(resource_h)
|
26
|
-
resource_h.slice(:slug, :shifts, :code, :days, :period, :description)
|
27
|
-
end
|
28
|
-
|
29
|
-
def to_resource_h
|
30
|
-
{
|
31
|
-
slug: slug,
|
32
|
-
shifts: shifts,
|
33
|
-
code: code,
|
34
|
-
days: days,
|
35
|
-
period: period,
|
36
|
-
description: description
|
37
|
-
}.except(*protected_resource_fields).compact
|
38
|
-
end
|
39
|
-
|
40
|
-
def protected_resource_fields
|
41
|
-
[]
|
42
|
-
end
|
43
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
module Mumukit::Platform::Organization::Helpers
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
include Mumukit::Platform::Notifiable
|
4
|
-
|
5
|
-
## Implementors must declare the following methods:
|
6
|
-
#
|
7
|
-
# * name
|
8
|
-
# * book
|
9
|
-
# * profile
|
10
|
-
# * settings
|
11
|
-
# * theme
|
12
|
-
|
13
|
-
included do
|
14
|
-
delegate *Mumukit::Platform::Organization::Theme.accessors, to: :theme
|
15
|
-
delegate *Mumukit::Platform::Organization::Settings.accessors, :private?, :login_settings, to: :settings
|
16
|
-
delegate *Mumukit::Platform::Organization::Profile.accessors, :locale_json, to: :profile
|
17
|
-
end
|
18
|
-
|
19
|
-
def platform_class_name
|
20
|
-
:Organization
|
21
|
-
end
|
22
|
-
|
23
|
-
def slug
|
24
|
-
Mumukit::Auth::Slug.join_s name
|
25
|
-
end
|
26
|
-
|
27
|
-
def central?
|
28
|
-
name == 'central'
|
29
|
-
end
|
30
|
-
|
31
|
-
def test?
|
32
|
-
name == 'test'
|
33
|
-
end
|
34
|
-
|
35
|
-
def base?
|
36
|
-
name == 'base'
|
37
|
-
end
|
38
|
-
|
39
|
-
def switch!
|
40
|
-
Mumukit::Platform::Organization.switch! self
|
41
|
-
end
|
42
|
-
|
43
|
-
def to_s
|
44
|
-
name
|
45
|
-
end
|
46
|
-
|
47
|
-
def url_for(path)
|
48
|
-
Mumukit::Platform.application.organic_url_for(name, path)
|
49
|
-
end
|
50
|
-
|
51
|
-
def url
|
52
|
-
url_for '/'
|
53
|
-
end
|
54
|
-
|
55
|
-
def domain
|
56
|
-
Mumukit::Platform.application.organic_domain(name)
|
57
|
-
end
|
58
|
-
|
59
|
-
## API Exposure
|
60
|
-
|
61
|
-
def to_param
|
62
|
-
name
|
63
|
-
end
|
64
|
-
|
65
|
-
## Name validation
|
66
|
-
|
67
|
-
def self.valid_name?(name)
|
68
|
-
!!(name =~ anchored_valid_name_regex)
|
69
|
-
end
|
70
|
-
|
71
|
-
def self.anchored_valid_name_regex
|
72
|
-
/\A#{valid_name_regex}\z/
|
73
|
-
end
|
74
|
-
|
75
|
-
def self.valid_name_regex
|
76
|
-
/([-a-z0-9_]+(\.[-a-z0-9_]+)*)?/
|
77
|
-
end
|
78
|
-
|
79
|
-
## Resource Hash
|
80
|
-
|
81
|
-
def self.slice_resource_h(resource_h)
|
82
|
-
resource_h.slice(:name, :book, :profile, :settings, :theme)
|
83
|
-
end
|
84
|
-
|
85
|
-
def to_resource_h
|
86
|
-
{
|
87
|
-
name: name,
|
88
|
-
book: book.slug,
|
89
|
-
profile: profile,
|
90
|
-
settings: settings,
|
91
|
-
theme: theme
|
92
|
-
}.except(*protected_resource_fields).compact
|
93
|
-
end
|
94
|
-
|
95
|
-
def protected_resource_fields
|
96
|
-
[]
|
97
|
-
end
|
98
|
-
|
99
|
-
module ClassMethods
|
100
|
-
def current
|
101
|
-
Mumukit::Platform::Organization.current
|
102
|
-
end
|
103
|
-
|
104
|
-
def parse(json)
|
105
|
-
json
|
106
|
-
.slice(:name)
|
107
|
-
.merge(theme: Mumukit::Platform::Organization::Theme.parse(json[:theme]))
|
108
|
-
.merge(settings: Mumukit::Platform::Organization::Settings.parse(json[:settings]))
|
109
|
-
.merge(profile: Mumukit::Platform::Organization::Profile.parse(json[:profile]))
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,39 +0,0 @@
|
|
1
|
-
class Mumukit::Platform::Organization::Profile < Mumukit::Platform::Model
|
2
|
-
LOCALES = Mumukit::Platform::Locale::SPECS
|
3
|
-
|
4
|
-
model_attr_accessor :logo_url,
|
5
|
-
:banner_url,
|
6
|
-
:favicon_url,
|
7
|
-
:breadcrumb_image_url,
|
8
|
-
:open_graph_image_url,
|
9
|
-
:locale,
|
10
|
-
:description,
|
11
|
-
:contact_email,
|
12
|
-
:terms_of_service,
|
13
|
-
:community_link,
|
14
|
-
:errors_explanations
|
15
|
-
|
16
|
-
def locale_json
|
17
|
-
locale_h.to_json
|
18
|
-
end
|
19
|
-
|
20
|
-
def locale_h
|
21
|
-
Mumukit::Platform::Locale::SPECS[locale]
|
22
|
-
end
|
23
|
-
|
24
|
-
def logo_url
|
25
|
-
@logo_url ||= 'https://mumuki.io/logo-alt-large.png' # Best image size: 350x75
|
26
|
-
end
|
27
|
-
|
28
|
-
def banner_url
|
29
|
-
@banner_url || logo_url # Best image size: 350x75
|
30
|
-
end
|
31
|
-
|
32
|
-
def favicon_url
|
33
|
-
@favicon_url ||= '/favicon.ico' # Best image size: 16x16, 32x32 or 48x48
|
34
|
-
end
|
35
|
-
|
36
|
-
def open_graph_image_url
|
37
|
-
@open_graph_image_url ||= Mumukit::Platform.application.url_for("logo-alt.png") # Best image size: 256x256
|
38
|
-
end
|
39
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
class Mumukit::Platform::Organization::Settings < Mumukit::Platform::Model
|
2
|
-
model_attr_accessor :login_methods,
|
3
|
-
:login_provider,
|
4
|
-
:login_provider_settings,
|
5
|
-
:raise_hand_enabled?,
|
6
|
-
:feedback_suggestions_enabled?,
|
7
|
-
:public?,
|
8
|
-
:embeddable?,
|
9
|
-
:immersive?,
|
10
|
-
:forum_enabled?,
|
11
|
-
:report_issue_enabled?
|
12
|
-
|
13
|
-
def private?
|
14
|
-
!public?
|
15
|
-
end
|
16
|
-
|
17
|
-
def login_methods
|
18
|
-
@login_methods ||= ['user_pass']
|
19
|
-
end
|
20
|
-
end
|
@@ -1,127 +0,0 @@
|
|
1
|
-
module Mumukit::Platform::User::Helpers
|
2
|
-
include Mumukit::Auth::Roles
|
3
|
-
include Mumukit::Platform::Notifiable
|
4
|
-
|
5
|
-
extend Gem::Deprecate
|
6
|
-
|
7
|
-
## Implementors must declare the following methods:
|
8
|
-
#
|
9
|
-
# * permissions
|
10
|
-
# * uid
|
11
|
-
# * social_id
|
12
|
-
# * image_url
|
13
|
-
# * email
|
14
|
-
# * first_name
|
15
|
-
# * last_name
|
16
|
-
|
17
|
-
## Permissions
|
18
|
-
|
19
|
-
delegate :has_role?,
|
20
|
-
:add_permission!,
|
21
|
-
:remove_permission!,
|
22
|
-
:has_permission?,
|
23
|
-
:has_permission_delegation?,
|
24
|
-
:protect!,
|
25
|
-
:protect_delegation!,
|
26
|
-
:protect_permissions_assignment!,
|
27
|
-
to: :permissions
|
28
|
-
|
29
|
-
def platform_class_name
|
30
|
-
:User
|
31
|
-
end
|
32
|
-
|
33
|
-
def merge_permissions!(new_permissions)
|
34
|
-
self.permissions = permissions.merge(new_permissions)
|
35
|
-
end
|
36
|
-
|
37
|
-
[:student, :teacher, :headmaster, :janitor].each do |role|
|
38
|
-
role_of = "#{role}_of?"
|
39
|
-
role_here = "#{role}_here?"
|
40
|
-
|
41
|
-
define_method role_of do |organization|
|
42
|
-
has_permission? role, organization.slug
|
43
|
-
end
|
44
|
-
|
45
|
-
define_method role_here do
|
46
|
-
send role_of, Mumukit::Platform::Organization.current
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def make_student_of!(slug)
|
51
|
-
add_permission! :student, slug
|
52
|
-
end
|
53
|
-
|
54
|
-
## Profile
|
55
|
-
|
56
|
-
def full_name
|
57
|
-
"#{first_name} #{last_name}"
|
58
|
-
end
|
59
|
-
|
60
|
-
alias_method :name, :full_name
|
61
|
-
|
62
|
-
def profile_completed?
|
63
|
-
[first_name, last_name].all? &:present?
|
64
|
-
end
|
65
|
-
|
66
|
-
def to_s
|
67
|
-
"#{full_name} <#{email}> [#{uid}]"
|
68
|
-
end
|
69
|
-
|
70
|
-
## Accesible organizations
|
71
|
-
|
72
|
-
def student_granted_organizations
|
73
|
-
permissions.student_granted_organizations.map do |org|
|
74
|
-
Mumukit::Platform::Organization.find_by_name!(org) rescue nil
|
75
|
-
end.compact
|
76
|
-
end
|
77
|
-
|
78
|
-
def has_student_granted_organizations?
|
79
|
-
student_granted_organizations.present?
|
80
|
-
end
|
81
|
-
|
82
|
-
[[:accessible_organizations, :student_granted_organizations],
|
83
|
-
[:has_accessible_organizations?, :has_student_granted_organizations?]].each do |it, replacement|
|
84
|
-
alias_method it, replacement
|
85
|
-
deprecate it, replacement, 2019, 6
|
86
|
-
end
|
87
|
-
|
88
|
-
def main_organization
|
89
|
-
student_granted_organizations.first
|
90
|
-
end
|
91
|
-
|
92
|
-
def has_main_organization?
|
93
|
-
student_granted_organizations.length == 1
|
94
|
-
end
|
95
|
-
|
96
|
-
def has_immersive_main_organization?
|
97
|
-
!!main_organization.try(&:immersive?)
|
98
|
-
end
|
99
|
-
|
100
|
-
## API Exposure
|
101
|
-
|
102
|
-
def to_param
|
103
|
-
uid
|
104
|
-
end
|
105
|
-
|
106
|
-
## Resource Hash
|
107
|
-
|
108
|
-
def self.slice_resource_h(resource_h)
|
109
|
-
resource_h.slice(:uid, :social_id, :image_url, :email, :first_name, :last_name, :permissions)
|
110
|
-
end
|
111
|
-
|
112
|
-
def to_resource_h
|
113
|
-
{
|
114
|
-
uid: uid,
|
115
|
-
social_id: social_id,
|
116
|
-
image_url: image_url,
|
117
|
-
email: email,
|
118
|
-
first_name: first_name,
|
119
|
-
last_name: last_name,
|
120
|
-
permissions: permissions
|
121
|
-
}.except(*protected_resource_fields).compact
|
122
|
-
end
|
123
|
-
|
124
|
-
def protected_resource_fields
|
125
|
-
[]
|
126
|
-
end
|
127
|
-
end
|