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