ibrain-core 0.4.6 → 0.4.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/ibrain/base_controller.rb +14 -12
- data/app/controllers/ibrain/core/graphql_controller.rb +83 -79
- data/app/graphql/ibrain/base_schema.rb +52 -50
- data/app/graphql/ibrain/extentions/default_value.rb +11 -7
- data/app/graphql/ibrain/extentions/roles.rb +20 -15
- data/app/graphql/ibrain/extentions/session_required.rb +14 -10
- data/app/graphql/ibrain/lazy/base.rb +6 -2
- data/app/graphql/ibrain/loaders/association_loader.rb +55 -51
- data/app/graphql/ibrain/mutations/base_mutation.rb +56 -52
- data/app/graphql/ibrain/policies/base_policy.rb +47 -43
- data/app/graphql/ibrain/policies/graphql_policy.rb +6 -2
- data/app/graphql/ibrain/resolvers/base_aggregate.rb +10 -6
- data/app/graphql/ibrain/resolvers/base_resolver.rb +12 -8
- data/app/graphql/ibrain/types/aggregate_type.rb +8 -4
- data/app/graphql/ibrain/types/attribute_type.rb +5 -2
- data/app/graphql/ibrain/types/base_api_connection.rb +10 -6
- data/app/graphql/ibrain/types/base_api_edge.rb +8 -4
- data/app/graphql/ibrain/types/base_api_field.rb +11 -7
- data/app/graphql/ibrain/types/base_api_object.rb +10 -6
- data/app/graphql/ibrain/types/base_argument.rb +7 -3
- data/app/graphql/ibrain/types/base_connection.rb +11 -7
- data/app/graphql/ibrain/types/base_edge.rb +7 -3
- data/app/graphql/ibrain/types/base_enum.rb +5 -1
- data/app/graphql/ibrain/types/base_field.rb +10 -6
- data/app/graphql/ibrain/types/base_input_object.rb +10 -6
- data/app/graphql/ibrain/types/base_interface.rb +9 -5
- data/app/graphql/ibrain/types/base_object.rb +16 -12
- data/app/graphql/ibrain/types/base_scalar.rb +5 -1
- data/app/graphql/ibrain/types/base_type.rb +10 -4
- data/app/graphql/ibrain/types/base_union.rb +7 -3
- data/app/graphql/ibrain/types/filter_type.rb +5 -1
- data/app/graphql/ibrain/types/node_type.rb +8 -4
- data/app/graphql/ibrain/util/field_combiner.rb +9 -5
- data/app/graphql/ibrain/util/query_combiner.rb +8 -4
- data/app/models/concerns/ibrain/soft_deletable.rb +8 -6
- data/app/models/concerns/ibrain/user_api_authentication.rb +16 -14
- data/app/models/concerns/ibrain/user_methods.rb +13 -11
- data/app/models/ibrain/ability.rb +32 -31
- data/app/models/ibrain/aggregate.rb +7 -5
- data/app/models/ibrain/application_record.rb +4 -2
- data/app/models/ibrain/legacy_user.rb +13 -7
- data/app/models/ibrain/role.rb +8 -6
- data/app/models/ibrain/role_user.rb +10 -8
- data/app/repositories/ibrain/base_repository.rb +11 -9
- data/lib/generators/ibrain/core/model_generator.rb +21 -17
- data/lib/generators/ibrain/graphql/core.rb +59 -55
- data/lib/generators/ibrain/graphql/mutation_generator.rb +66 -58
- data/lib/generators/ibrain/graphql/object_generator.rb +70 -58
- data/lib/generators/ibrain/graphql/resolver_generator.rb +25 -17
- data/lib/generators/ibrain/graphql/resolvers_generator.rb +67 -59
- data/lib/generators/ibrain/graphql/templates/aggregate.erb +7 -5
- data/lib/generators/ibrain/graphql/templates/input.erb +9 -5
- data/lib/generators/ibrain/graphql/templates/mutation.erb +26 -24
- data/lib/generators/ibrain/graphql/templates/object.erb +10 -6
- data/lib/generators/ibrain/graphql/templates/resolver.erb +11 -9
- data/lib/generators/ibrain/graphql/templates/resolvers.erb +10 -8
- data/lib/generators/ibrain/graphql/type_generator.rb +88 -84
- data/lib/generators/ibrain/install/install_generator.rb +140 -137
- data/lib/generators/ibrain/install/templates/graphql/types/mutation_type.rb.tt +15 -13
- data/lib/generators/ibrain/install/templates/graphql/types/query_type.rb.tt +13 -11
- data/lib/generators/ibrain/install/templates/rubocop.yml.tt +30 -83
- data/lib/ibrain/app_configuration.rb +36 -34
- data/lib/ibrain/core/class_constantizer.rb +33 -30
- data/lib/ibrain/core/controller_helpers/auth.rb +59 -53
- data/lib/ibrain/core/controller_helpers/current_host.rb +11 -5
- data/lib/ibrain/core/controller_helpers/response.rb +49 -43
- data/lib/ibrain/core/controller_helpers/strong_parameters.rb +15 -9
- data/lib/ibrain/core/engine.rb +9 -5
- data/lib/ibrain/core/environment.rb +9 -5
- data/lib/ibrain/core/environment_extension.rb +17 -13
- data/lib/ibrain/core/role_configuration.rb +54 -52
- data/lib/ibrain/core/validators/email.rb +17 -15
- data/lib/ibrain/core/version.rb +2 -2
- data/lib/ibrain/core/versioned_value.rb +65 -61
- data/lib/ibrain/encryptor.rb +20 -18
- data/lib/ibrain/logger.rb +15 -13
- data/lib/ibrain/permission_sets/base.rb +26 -22
- data/lib/ibrain/permission_sets/super_user.rb +7 -3
- data/lib/ibrain/permitted_attributes.rb +20 -18
- data/lib/ibrain/preferences/configuration.rb +137 -135
- data/lib/ibrain/preferences/preferable.rb +162 -158
- data/lib/ibrain/preferences/preferable_class_methods.rb +114 -112
- data/lib/ibrain/user_class_handle.rb +24 -22
- data/lib/ibrain_core.rb +1 -7
- metadata +1 -1
|
@@ -2,12 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
require 'ibrain/core/environment_extension'
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
module Ibrain
|
|
6
|
+
module Core
|
|
7
|
+
class Environment
|
|
8
|
+
include EnvironmentExtension
|
|
7
9
|
|
|
8
|
-
|
|
10
|
+
attr_accessor :preferences
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
+
def initialize(ibrain_config)
|
|
13
|
+
@preferences = ibrain_config
|
|
14
|
+
end
|
|
15
|
+
end
|
|
12
16
|
end
|
|
13
17
|
end
|
|
@@ -2,21 +2,25 @@
|
|
|
2
2
|
|
|
3
3
|
require 'ibrain/core/class_constantizer'
|
|
4
4
|
|
|
5
|
-
module Ibrain
|
|
6
|
-
|
|
5
|
+
module Ibrain
|
|
6
|
+
module Core
|
|
7
|
+
module EnvironmentExtension
|
|
8
|
+
extend ActiveSupport::Concern
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
10
|
+
class_methods do
|
|
11
|
+
def add_class_set(name)
|
|
12
|
+
define_method(name) do
|
|
13
|
+
set = instance_variable_get("@#{name}")
|
|
14
|
+
set ||= send("#{name}=", [])
|
|
15
|
+
set
|
|
16
|
+
end
|
|
15
17
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
define_method("#{name}=") do |klasses|
|
|
19
|
+
set = ClassConstantizer::Set.new
|
|
20
|
+
set.concat(klasses)
|
|
21
|
+
instance_variable_set("@#{name}", set)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
20
24
|
end
|
|
21
25
|
end
|
|
22
26
|
end
|
|
@@ -3,68 +3,70 @@
|
|
|
3
3
|
require 'singleton'
|
|
4
4
|
require 'ibrain/core/class_constantizer'
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
6
|
+
module Ibrain
|
|
7
|
+
# A class responsible for associating {Ibrain::Role} with a list of permission sets.
|
|
8
|
+
#
|
|
9
|
+
# @see Ibrain::PermissionSets
|
|
10
|
+
#
|
|
11
|
+
# @example Adding order, data, and user display to customer service users.
|
|
12
|
+
# Ibrain::RoleConfiguration.configure do |config|
|
|
13
|
+
# config.assign_permissions :customer_service, [
|
|
14
|
+
# Ibrain::PermissionSets::UserDisplay,
|
|
15
|
+
# ]
|
|
16
|
+
# end
|
|
17
|
+
class RoleConfiguration
|
|
18
|
+
# An internal structure for the association between a role and a
|
|
19
|
+
# set of permissions.
|
|
20
|
+
class Role
|
|
21
|
+
attr_reader :name, :permission_sets
|
|
21
22
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
def initialize(name, permission_sets)
|
|
24
|
+
@name = name
|
|
25
|
+
@permission_sets = Ibrain::Core::ClassConstantizer::Set.new
|
|
26
|
+
@permission_sets.concat permission_sets
|
|
27
|
+
end
|
|
26
28
|
end
|
|
27
|
-
end
|
|
28
29
|
|
|
29
|
-
|
|
30
|
+
attr_accessor :roles
|
|
30
31
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
32
|
+
# Given a CanCan::Ability, and a user, determine what permissions sets can
|
|
33
|
+
# be activated on the ability, then activate them.
|
|
34
|
+
#
|
|
35
|
+
# This performs can/cannot declarations on the ability, and can modify its
|
|
36
|
+
# internal permissions.
|
|
37
|
+
#
|
|
38
|
+
# @param ability [CanCan::Ability] the ability to invoke declarations on
|
|
39
|
+
# @param user [#roles] the user that holds the roles association.
|
|
40
|
+
def activate_permissions!(ability, user)
|
|
41
|
+
ibrain_roles = ['default'] | user.roles.map(&:name)
|
|
42
|
+
applicable_permissions = Set.new
|
|
42
43
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
ibrain_roles.each do |role_name|
|
|
45
|
+
applicable_permissions |= roles[role_name].permission_sets
|
|
46
|
+
end
|
|
46
47
|
|
|
47
|
-
|
|
48
|
-
|
|
48
|
+
applicable_permissions.each do |permission_set|
|
|
49
|
+
permission_set.new(ability).activate!
|
|
50
|
+
end
|
|
49
51
|
end
|
|
50
|
-
end
|
|
51
52
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
# Not public due to the fact this class is a Singleton
|
|
54
|
+
# @!visibility private
|
|
55
|
+
def initialize
|
|
56
|
+
@roles = Hash.new do |hash, name|
|
|
57
|
+
hash[name] = Role.new(name, Set.new)
|
|
58
|
+
end
|
|
57
59
|
end
|
|
58
|
-
end
|
|
59
60
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
# Assign permission sets for a {Ibrain::Role} that has the name of role_name
|
|
62
|
+
# @param role_name [Symbol, String] The name of the role to associate permissions with
|
|
63
|
+
# @param permission_sets [Array<Ibrain::PermissionSets::Base>, Set<Ibrain::PermissionSets::Base>]
|
|
64
|
+
# A list of permission sets to activate if the user has the role indicated by role_name
|
|
65
|
+
def assign_permissions(role_name, permission_sets)
|
|
66
|
+
name = role_name.to_s
|
|
66
67
|
|
|
67
|
-
|
|
68
|
-
|
|
68
|
+
roles[name].permission_sets.concat permission_sets
|
|
69
|
+
roles[name]
|
|
70
|
+
end
|
|
69
71
|
end
|
|
70
72
|
end
|
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
|
|
14
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
# == An ActiveModel Email Validator
|
|
5
|
+
#
|
|
6
|
+
# === Usage
|
|
7
|
+
#
|
|
8
|
+
# require 'ibrain/core/validators/email'
|
|
9
|
+
#
|
|
10
|
+
# class Person < ApplicationRecord
|
|
11
|
+
# validates :email_address, 'ibrain/email' => true
|
|
12
|
+
# end
|
|
13
|
+
#
|
|
14
|
+
class EmailValidator < ActiveModel::EachValidator
|
|
15
|
+
EMAIL_REGEXP = URI::MailTo::EMAIL_REGEXP
|
|
15
16
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
def validate_each(record, attribute, value)
|
|
18
|
+
unless EMAIL_REGEXP.match? value
|
|
19
|
+
record.errors.add(attribute, :invalid, **{ value: value }.merge!(options))
|
|
20
|
+
end
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
23
|
end
|
data/lib/ibrain/core/version.rb
CHANGED
|
@@ -1,69 +1,73 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
#
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
12
|
-
#
|
|
13
|
-
#
|
|
14
|
-
#
|
|
15
|
-
#
|
|
16
|
-
# value.
|
|
17
|
-
# value.call("
|
|
18
|
-
#
|
|
19
|
-
#
|
|
20
|
-
#
|
|
21
|
-
#
|
|
22
|
-
#
|
|
23
|
-
#
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
# value
|
|
27
|
-
#
|
|
28
|
-
#
|
|
29
|
-
#
|
|
30
|
-
#
|
|
31
|
-
#
|
|
32
|
-
#
|
|
33
|
-
#
|
|
34
|
-
# value.
|
|
35
|
-
# value.call("
|
|
36
|
-
|
|
37
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module Core
|
|
5
|
+
# Wrapper for a value that can be different depending on the Ibrain version
|
|
6
|
+
#
|
|
7
|
+
# Some configuration defaults can be added or changed when a new Ibrain
|
|
8
|
+
# version is released. This class encapsulates getting the correct value for a
|
|
9
|
+
# given Ibrain version.
|
|
10
|
+
#
|
|
11
|
+
# The way it works is you provide an initial value in time, plus the version
|
|
12
|
+
# boundary where it got changed. Then you can fetch the value providing the
|
|
13
|
+
# desired Ibrain version:
|
|
14
|
+
#
|
|
15
|
+
# @example
|
|
16
|
+
# value = VersionedValue.new(true, "3.0.0" => false)
|
|
17
|
+
# value.call("2.7.0") # => true
|
|
18
|
+
# value.call("3.0.0") # => false
|
|
19
|
+
# value.call("3.1.0") # => false
|
|
20
|
+
#
|
|
21
|
+
# Remember that you must provide the exact boundary when a value got changed,
|
|
22
|
+
# which could easily be during a pre-release:
|
|
23
|
+
#
|
|
24
|
+
# @example
|
|
25
|
+
# value = VersionedValue.new(true, "3.0.0" => false)
|
|
26
|
+
# value.call("3.0.0.alpha") # => true
|
|
27
|
+
#
|
|
28
|
+
# value = VersionedValue.new(true, "3.0.0.alpha" => false)
|
|
29
|
+
# value.call("3.0.0.alpha") # => false
|
|
30
|
+
#
|
|
31
|
+
# Multiple boundaries can also be provided:
|
|
32
|
+
#
|
|
33
|
+
# @example
|
|
34
|
+
# value = VersionedValue.new(0, "2.0.0" => 1, "3.0.0" => 2)
|
|
35
|
+
# value.call("1.0.0") # => 0
|
|
36
|
+
# value.call("2.1.0") # => 1
|
|
37
|
+
# value.call("3.0.0") # => 2
|
|
38
|
+
class VersionedValue
|
|
39
|
+
attr_reader :boundaries
|
|
38
40
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
41
|
+
# @param initial_value [Any]
|
|
42
|
+
# @param boundary [Hash<String, Any>] Map from version number to new value
|
|
43
|
+
def initialize(initial_value, boundaries = {})
|
|
44
|
+
@boundaries = { '0' => initial_value }
|
|
45
|
+
.merge(boundaries)
|
|
46
|
+
.transform_keys { |version| to_gem_version(version) }
|
|
47
|
+
.sort.to_h
|
|
48
|
+
end
|
|
47
49
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
50
|
+
# @param ibrain_version [String]
|
|
51
|
+
def call(ibrain_version = Ibrain.ibrain_version)
|
|
52
|
+
ibrain_version = to_gem_version(ibrain_version)
|
|
53
|
+
boundaries.fetch(
|
|
54
|
+
boundaries
|
|
55
|
+
.keys
|
|
56
|
+
.reduce do |target, following|
|
|
57
|
+
if target <= ibrain_version && ibrain_version < following
|
|
58
|
+
target
|
|
59
|
+
else
|
|
60
|
+
following
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
)
|
|
64
|
+
end
|
|
63
65
|
|
|
64
|
-
|
|
66
|
+
private
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
def to_gem_version(string)
|
|
69
|
+
Gem::Version.new(string)
|
|
70
|
+
end
|
|
71
|
+
end
|
|
68
72
|
end
|
|
69
73
|
end
|
data/lib/ibrain/encryptor.rb
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
key =
|
|
3
|
+
module Ibrain
|
|
4
|
+
# Ibrain::Encryptor is a thin wrapper around ActiveSupport::MessageEncryptor.
|
|
5
|
+
class Encryptor
|
|
6
|
+
# @param key [String] the 256 bits signature key
|
|
7
|
+
def initialize(key = Ibrain::Config.ibrain_encryptor_key)
|
|
8
|
+
key = Rails.application.secrets.secret_key_base.byteslice(0..31) if key.blank?
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
10
|
+
@crypt = ActiveSupport::MessageEncryptor.new(key)
|
|
11
|
+
end
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
# Encrypt a value
|
|
14
|
+
# @param value [String] the value to encrypt
|
|
15
|
+
# @return [String] the encrypted value
|
|
16
|
+
def encrypt(value)
|
|
17
|
+
@crypt.encrypt_and_sign(value)
|
|
18
|
+
end
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
# Decrypt an encrypted value
|
|
21
|
+
# @param encrypted_value [String] the value to decrypt
|
|
22
|
+
# @return [String] the decrypted value
|
|
23
|
+
def decrypt(encrypted_value)
|
|
24
|
+
@crypt.decrypt_and_verify(encrypted_value)
|
|
25
|
+
end
|
|
24
26
|
end
|
|
25
27
|
end
|
data/lib/ibrain/logger.rb
CHANGED
|
@@ -1,21 +1,23 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
class
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
class Logger
|
|
5
|
+
class << self
|
|
6
|
+
def info(message)
|
|
7
|
+
Rails.logger.info("[Ibrain] #{message}")
|
|
8
|
+
end
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
def warn(message)
|
|
11
|
+
Rails.logger.warn("[Ibrain] #{message}")
|
|
12
|
+
end
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
def debug(message)
|
|
15
|
+
Rails.logger.debug { "[Ibrain] #{message}" }
|
|
16
|
+
end
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
def error(message)
|
|
19
|
+
Rails.logger.error("[Ibrain] #{message}")
|
|
20
|
+
end
|
|
19
21
|
end
|
|
20
22
|
end
|
|
21
23
|
end
|
|
@@ -1,29 +1,33 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
# This is
|
|
6
|
-
#
|
|
7
|
-
#
|
|
8
|
-
#
|
|
9
|
-
#
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module PermissionSets
|
|
5
|
+
# This is the base class used for crafting permission sets.
|
|
6
|
+
#
|
|
7
|
+
# This is used by {Ibrain::RoleConfiguration} when adding custom behavior to {Ibrain::Ability}.
|
|
8
|
+
# See one of the subclasses for example structure such as {Ibrain::PermissionSets::UserDisplay}
|
|
9
|
+
#
|
|
10
|
+
# @see Ibrain::RoleConfiguration
|
|
11
|
+
# @see Ibrain::PermissionSets
|
|
12
|
+
class Base
|
|
13
|
+
# @param ability [CanCan::Ability]
|
|
14
|
+
# The ability that will be extended with the current permission set.
|
|
15
|
+
# The ability passed in must respond to #user
|
|
16
|
+
def initialize(ability)
|
|
17
|
+
@ability = ability
|
|
18
|
+
end
|
|
17
19
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
20
|
+
# Activate permissions on the ability. Put your can and cannot statements here.
|
|
21
|
+
# Must be overriden by subclasses
|
|
22
|
+
def activate!
|
|
23
|
+
raise NotImplementedError.new
|
|
24
|
+
end
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
private
|
|
25
27
|
|
|
26
|
-
|
|
28
|
+
attr_reader :ability
|
|
27
29
|
|
|
28
|
-
|
|
30
|
+
delegate :can, :cannot, :user, to: :ability
|
|
31
|
+
end
|
|
32
|
+
end
|
|
29
33
|
end
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
module PermissionSets
|
|
5
|
+
class SuperUser < PermissionSets::Base
|
|
6
|
+
def activate!
|
|
7
|
+
can :manage, :all
|
|
8
|
+
end
|
|
9
|
+
end
|
|
6
10
|
end
|
|
7
11
|
end
|
|
@@ -1,24 +1,26 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
#
|
|
5
|
-
#
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
module Ibrain
|
|
4
|
+
# Ibrain::PermittedAttributes contains the attributes permitted through strong
|
|
5
|
+
# params in various controllers in the frontend. Extensions and stores that
|
|
6
|
+
# need additional params to be accepted can mutate these arrays to add them.
|
|
7
|
+
module PermittedAttributes
|
|
8
|
+
ATTRIBUTES = [
|
|
9
|
+
:address_attributes,
|
|
10
|
+
:user_attributes
|
|
11
|
+
]
|
|
11
12
|
|
|
12
|
-
|
|
13
|
+
mattr_reader(*ATTRIBUTES)
|
|
13
14
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
@@address_attributes = [
|
|
16
|
+
:id, :name, :address1, :address2, :city, :country_id, :state_id,
|
|
17
|
+
:zipcode, :phone, :state_name, :province_id, :ward_id, :district_id
|
|
18
|
+
]
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
# Intentionally leaving off email here to prevent privilege escalation
|
|
21
|
+
# by changing a user with higher priveleges' email to one a lower-priveleged
|
|
22
|
+
# admin owns. Creating a user with an email is handled separate at the
|
|
23
|
+
# controller level.
|
|
24
|
+
@@user_attributes = [:name, :email, :provider, :uid, :first_name, :last_name, :password, :password_confirmation]
|
|
25
|
+
end
|
|
24
26
|
end
|