mumukit-platform 1.0.1 → 1.1.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: 4a6a060c216d2ab7dcae48ff7d9301e711e83d21ce0259401ac9982eb6cffc15
4
- data.tar.gz: ae565a64db783ddfd919773d4a59142ee2f3943dc3562cb8b225fe99723b4dc8
3
+ metadata.gz: a00ec1f20246a0081a57e61844c352e4bc14b16b61d593cdebd496f1b8712852
4
+ data.tar.gz: 07307e831a3c64c6292f28e22fe3fcb4f9d1009f29c602c552e5bd6f113137af
5
5
  SHA512:
6
- metadata.gz: 26b62658bb879bb9d467b1c0a8502c9166af67d9b4db3964c0ef4389dc145f7410e40d9d3ca8be964a1375e3315ab145de7f9317f125e9c86b63a97c6ceec5d3
7
- data.tar.gz: e51ded70e610773da6ffd4bc1d4479ebb75853582c033d351e2d79d6ec0014e6b157d8e8b213d226a52bc0f1179c0fbfe2667b818a98ddc0cb56fe15efe1ab60
6
+ metadata.gz: 22f6140f40dca4b7f981e47cd773a09e9b72f48d8c4e833fd9442c6e433c0edcf91af9f05172e7aabcb12e0862bd79e61a5718c9183cf399eb7ada182bcd650c
7
+ data.tar.gz: 397c264e64d2d0cd0076d6942d91f8dc69df4312dc9f1aa3d082b46960c473c51faed547d66835d4174efdbb50809457cdb809ab37ee4d0f5afc20ef52d8731f
@@ -1,4 +1,5 @@
1
1
  require 'mumukit/core'
2
+ require 'mumukit/auth'
2
3
 
3
4
  require_relative './platform/version'
4
5
  require_relative './platform/uri'
@@ -17,7 +18,6 @@ module Mumukit::Platform
17
18
  config.thesaurus_url = ENV['MUMUKI_THESAURUS_URL'] || "http://thesaurus.#{domain}"
18
19
  config.bibliotheca_url = ENV['MUMUKI_BIBLIOTHECA_URL'] || "http://bibliotheca.#{domain}"
19
20
  config.bibliotheca_api_url = ENV['MUMUKI_BIBLIOTHECA_API_URL'] || "http://bibliotheca-api.#{domain}"
20
- config.office_url = ENV['MUMUKI_OFFICE_URL'] || "http://office.#{domain}"
21
21
  config.classroom_url = ENV['MUMUKI_CLASSROOM_URL'] || "http://classroom.#{domain}"
22
22
  config.classroom_api_url = ENV['MUMUKI_CLASSROOM_API_URL'] || "http://classroom-api.#{domain}"
23
23
  config.organization_mapping = Mumukit::Platform::OrganizationMapping.from_env
@@ -27,11 +27,22 @@ module Mumukit::Platform
27
27
  def self.config
28
28
  @config
29
29
  end
30
+
31
+ [:organization, :user].each do |klass|
32
+ define_singleton_method("#{klass}_class") do
33
+ begin
34
+ config["#{klass}_class"] ||= config["#{klass}_class_name"].constantize
35
+ rescue
36
+ raise "You must configure your #{klass} class first"
37
+ end
38
+ end
39
+ end
30
40
  end
31
41
 
32
42
  require_relative './platform/domain'
33
43
  require_relative './platform/model'
34
44
  require_relative './platform/locale'
45
+ require_relative './platform/user'
35
46
  require_relative './platform/organization'
36
47
  require_relative './platform/organization_mapping'
37
48
  require_relative './platform/application'
@@ -8,17 +8,40 @@ class Mumukit::Platform::Model
8
8
  end
9
9
 
10
10
  def self.model_attr_accessor(*keys)
11
+ bools, raws = keys.partition { |it| it.to_s.end_with? '?' }
12
+ raw_bools = bools.map { |it| it.to_s[0..-2].to_sym }
13
+ keys = raws + raw_bools
14
+
11
15
  attr_accessor(*keys)
16
+
17
+ raw_bools.each do |it|
18
+ define_method("#{it}?") { !!send(it) }
19
+ define_method("#{it}=") { |value| instance_variable_set("@#{it}", value.to_boolean) }
20
+ end
21
+
22
+ # Parses model from an event.
23
+ # Only allowed keys are accepted
12
24
  define_singleton_method :parse do |hash|
13
25
  hash ? new(hash.slice(*keys)) : new
14
26
  end
15
27
  end
16
28
 
29
+ ## Serialization
30
+
31
+ # Serializes model
17
32
  def self.dump(obj)
18
33
  obj.to_json
19
34
  end
20
35
 
36
+ # Deserializes model
21
37
  def self.load(json)
22
38
  json ? new(JSON.parse(json)) : new
23
39
  end
24
40
  end
41
+
42
+
43
+ class Object
44
+ def to_boolean
45
+ [true, 'true', '1', 1].include?(self)
46
+ end
47
+ end
@@ -11,6 +11,10 @@ module Mumukit::Platform::Organization
11
11
  def self.current
12
12
  Thread.current[:organization] || raise('organization not selected')
13
13
  end
14
+
15
+ def self.find_by_name!(name)
16
+ Mumukit::Platform.organization_class.find_by_name!(name)
17
+ end
14
18
  end
15
19
 
16
20
  require_relative './organization/settings'
@@ -1,7 +1,14 @@
1
-
2
1
  module Mumukit::Platform::Organization::Helpers
3
2
  extend ActiveSupport::Concern
4
3
 
4
+ ## Implementors must declare the following methods:
5
+ #
6
+ # * name
7
+ # * book
8
+ # * profile
9
+ # * settings
10
+ # * theme
11
+
5
12
  included do
6
13
  delegate :theme_stylesheet,
7
14
  :theme_stylesheet=,
@@ -37,6 +44,7 @@ module Mumukit::Platform::Organization::Helpers
37
44
  :description,
38
45
  :description=,
39
46
  :community_link,
47
+ :community_link=,
40
48
  :terms_of_service,
41
49
  :terms_of_service=,
42
50
  :contact_email,
@@ -76,6 +84,14 @@ module Mumukit::Platform::Organization::Helpers
76
84
  Mumukit::Platform.application.organic_domain(name)
77
85
  end
78
86
 
87
+ ## API Exposure
88
+
89
+ def to_param
90
+ name
91
+ end
92
+
93
+ ## Name validation
94
+
79
95
  def self.valid_name?(name)
80
96
  !!(name =~ anchored_valid_name_regex)
81
97
  end
@@ -88,6 +104,36 @@ module Mumukit::Platform::Organization::Helpers
88
104
  /([-a-z0-9_]+(\.[-a-z0-9_]+)*)?/
89
105
  end
90
106
 
107
+ ## Platform JSON
108
+
109
+ def as_platform_json
110
+ {
111
+ name: name,
112
+ book: book.slug,
113
+ banner_url: banner_url,
114
+ breadcrumb_image_url: breadcrumb_image_url,
115
+ community_link: community_link,
116
+ contact_email: contact_email,
117
+ description: description,
118
+ extension_javascript: extension_javascript,
119
+ favicon_url: favicon_url,
120
+ feedback_suggestions_enabled: feedback_suggestions_enabled?,
121
+ immersive: immersive?,
122
+ locale: locale,
123
+ login_methods: login_methods,
124
+ logo_url: logo_url,
125
+ open_graph_image_url: open_graph_image_url,
126
+ public: public?,
127
+ raise_hand_enabled: raise_hand_enabled?,
128
+ terms_of_service: terms_of_service,
129
+ theme_stylesheet: theme_stylesheet
130
+ }.except(*protected_platform_fields).compact
131
+ end
132
+
133
+ def protected_platform_fields
134
+ []
135
+ end
136
+
91
137
  module ClassMethods
92
138
  def current
93
139
  Mumukit::Platform::Organization.current
@@ -1,30 +1,14 @@
1
1
  class Mumukit::Platform::Organization::Settings < Mumukit::Platform::Model
2
2
  model_attr_accessor :login_methods,
3
- :raise_hand_enabled,
4
- :feedback_suggestions_enabled,
5
- :public,
6
- :immersive
7
-
8
- def raise_hand_enabled?
9
- !!raise_hand_enabled
10
- end
11
-
12
- def feedback_suggestions_enabled?
13
- !!feedback_suggestions_enabled
14
- end
15
-
16
- def public?
17
- !!public
18
- end
3
+ :raise_hand_enabled?,
4
+ :feedback_suggestions_enabled?,
5
+ :public?,
6
+ :immersive?
19
7
 
20
8
  def private?
21
9
  !public?
22
10
  end
23
11
 
24
- def immersive?
25
- !!immersive
26
- end
27
-
28
12
  def login_methods
29
13
  @login_methods ||= ['user_pass']
30
14
  end
@@ -0,0 +1,7 @@
1
+ module Mumukit::Platform::User
2
+ def self.find_by_uid!(uid)
3
+ Mumukit::Platform.user_class.find_by_uid!(uid)
4
+ end
5
+ end
6
+
7
+ require_relative './user/helpers'
@@ -0,0 +1,108 @@
1
+ module Mumukit::Platform::User::Helpers
2
+ include Mumukit::Auth::Roles
3
+
4
+ ## Implementors must declare the following methods:
5
+ #
6
+ # * permissions
7
+ # * uid
8
+ # * social_id
9
+ # * image_url
10
+ # * email
11
+ # * first_name
12
+ # * last_name
13
+
14
+ ## Permissions
15
+
16
+ delegate :has_role?,
17
+ :add_permission!,
18
+ :remove_permission!,
19
+ :has_permission?,
20
+ :has_permission_delegation?,
21
+ :protect!,
22
+ :protect_delegation!,
23
+ :protect_permissions_assignment!,
24
+ to: :permissions
25
+
26
+ def merge_permissions!(new_permissions)
27
+ self.permissions = permissions.merge(new_permissions)
28
+ end
29
+
30
+ [:student, :teacher, :headmaster, :janitor].each do |role|
31
+ role_of = "#{role}_of?"
32
+ role_here = "#{role}_here?"
33
+
34
+ define_method role_of do |organization|
35
+ has_permission? role, organization.slug
36
+ end
37
+
38
+ define_method role_here do
39
+ send role_of, Mumukit::Platform::Organization.current
40
+ end
41
+ end
42
+
43
+ def make_student_of!(organization)
44
+ add_permission! :student, organization.slug
45
+ end
46
+
47
+ ## Profile
48
+
49
+ def full_name
50
+ "#{first_name} #{last_name}"
51
+ end
52
+
53
+ def profile_completed?
54
+ [first_name, last_name].all? &:present?
55
+ end
56
+
57
+ def to_s
58
+ "#{full_name} <#{email}> [#{uid}]"
59
+ end
60
+
61
+ ## Accesible organizations
62
+
63
+ def accessible_organizations
64
+ permissions.accessible_organizations.map do |org|
65
+ Mumukit::Platform::Organization.find_by_name!(org) rescue nil
66
+ end.compact
67
+ end
68
+
69
+ def has_accessible_organizations?
70
+ accessible_organizations.present?
71
+ end
72
+
73
+ def main_organization
74
+ accessible_organizations.first
75
+ end
76
+
77
+ def has_main_organization?
78
+ accessible_organizations.length == 1
79
+ end
80
+
81
+ def has_immersive_main_organization?
82
+ !!main_organization.try(&:immersive?)
83
+ end
84
+
85
+ ## API Exposure
86
+
87
+ def to_param
88
+ uid
89
+ end
90
+
91
+ ## Platform JSON
92
+
93
+ def as_platform_json
94
+ {
95
+ uid: uid,
96
+ social_id: social_id,
97
+ image_url: image_url,
98
+ email: email,
99
+ first_name: first_name,
100
+ last_name: last_name,
101
+ permissions: permissions
102
+ }.except(*protected_platform_fields).compact
103
+ end
104
+
105
+ def protected_platform_fields
106
+ []
107
+ end
108
+ end
@@ -1,5 +1,5 @@
1
1
  module Mumukit
2
2
  module Platform
3
- VERSION = '1.0.1'
3
+ VERSION = '1.1.0'
4
4
  end
5
5
  end
@@ -14,10 +14,6 @@ module Mumukit::Platform::WithApplications
14
14
  Mumukit::Platform::Application::Organic.new config.classroom_api_url, organization_mapping
15
15
  end
16
16
 
17
- def office
18
- Mumukit::Platform::Application::Basic.new config.office_url
19
- end
20
-
21
17
  def bibliotheca
22
18
  Mumukit::Platform::Application::Basic.new config.bibliotheca_url
23
19
  end
@@ -29,4 +25,4 @@ module Mumukit::Platform::WithApplications
29
25
  def application_for(name)
30
26
  send name
31
27
  end
32
- end
28
+ end
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.require_paths = ['lib']
23
23
 
24
24
  spec.add_dependency 'mumukit-core', '~> 1.2'
25
+ spec.add_dependency 'mumukit-auth', '~> 7.0'
25
26
  spec.add_dependency 'activemodel', '>= 4.0'
26
27
 
27
28
  spec.add_development_dependency 'bundler', '~> 1.14'
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: 1.0.1
4
+ version: 1.1.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: 2018-02-08 00:00:00.000000000 Z
11
+ date: 2018-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mumukit-core
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
+ - !ruby/object:Gem::Dependency
28
+ name: mumukit-auth
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '7.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '7.0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: activemodel
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -110,6 +124,8 @@ files:
110
124
  - lib/mumukit/platform/organization/theme.rb
111
125
  - lib/mumukit/platform/organization_mapping.rb
112
126
  - lib/mumukit/platform/uri.rb
127
+ - lib/mumukit/platform/user.rb
128
+ - lib/mumukit/platform/user/helpers.rb
113
129
  - lib/mumukit/platform/version.rb
114
130
  - lib/mumukit/platform/web_framework.rb
115
131
  - lib/mumukit/platform/with_applications.rb
@@ -137,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
153
  version: '0'
138
154
  requirements: []
139
155
  rubyforge_project:
140
- rubygems_version: 2.7.5
156
+ rubygems_version: 2.7.6
141
157
  signing_key:
142
158
  specification_version: 4
143
159
  summary: Shared Mumuki Platform Components