effective_organizations 0.0.3 → 0.0.7

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: 1d1867153f3a3fd958c18fd26c374fba6a439516480ffac3825aabdbc5dadf5f
4
- data.tar.gz: 14bf4b503c58169387f886c3781bb2843f51cf90fedd3994eb5333850abc8461
3
+ metadata.gz: cacbee4a7dd40f4151038a00c39b0e7ef134f0ec739ee29753bc8aa34a73dc8c
4
+ data.tar.gz: 38e3039961b2ff7ceff0b66090370c9ace3f54ab6f16c666cdc68ca82b699d03
5
5
  SHA512:
6
- metadata.gz: 7139213c4c010b19cb733d50c1b042fb25f23246c1c1295ca23fe05c1f17e9705f64476b46acbe19833b0b13c7ade72918207b0fceab50fc62586163c332ed92
7
- data.tar.gz: ee0dd2280a17fd2ba168a257a875608bf8027b7548db9d3482728f54e4b3898087645d212f860e8307eb0aa8fbfdbe55626327608858ad8aa6911365ad30d280
6
+ metadata.gz: bd0fd64f099a8a15adb96f3d7d0be5952e4a371f33beddab08427491b818fdcfd12484c376fceb8f0b468ed88423cd47f95c39f8bd9d45e14d2f51c98071b7fa
7
+ data.tar.gz: 5a69fcb0b32b336e92cfe714c4641e1f38b7a549080e11e20c27031320a9a661d02c06fb7567831f04e105c0f7b9f3c1f4ee003342d67b0a05e4348317feffd9
@@ -11,11 +11,24 @@ class EffectiveRepresentativesDatatable < Effective::Datatable
11
11
 
12
12
  col :roles, search: roles_collection
13
13
 
14
- actions_col
14
+ unless attributes[:actions] == false
15
+ actions_col
16
+ end
17
+
15
18
  end
16
19
 
17
20
  collection do
18
- Effective::Representative.deep.all.where(organization: current_user.organizations)
21
+ scope = Effective::Representative.deep.all.where(organization: current_user.organizations)
22
+
23
+ if attributes[:organization_id]
24
+ scope = scope.where(organization_id: attributes[:organization_id])
25
+ end
26
+
27
+ if attributes[:user_id]
28
+ scope = scope.where(user_id: attributes[:user_id])
29
+ end
30
+
31
+ scope
19
32
  end
20
33
 
21
34
  def roles_collection
@@ -6,11 +6,7 @@ module EffectiveOrganizationsOrganization
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  module Base
9
- def effective_organizations_organization(users_source_type: nil)
10
- @effective_organizations_organization_opts = {
11
- users_source_type: users_source_type
12
- }
13
-
9
+ def effective_organizations_organization
14
10
  include ::EffectiveOrganizationsOrganization
15
11
  end
16
12
  end
@@ -32,8 +28,7 @@ module EffectiveOrganizationsOrganization
32
28
  has_many :representatives, -> { Effective::Representative.sorted },
33
29
  class_name: 'Effective::Representative', inverse_of: :organization, dependent: :delete_all
34
30
 
35
- has_many :users, through: :representatives,
36
- source_type: (@effective_organizations_organization_opts[:users_source_type] || (name.start_with?('Effective') ? '::User' : "#{name.split('::').first}::Organization"))
31
+ accepts_nested_attributes_for :representatives, allow_destroy: true
37
32
 
38
33
  effective_resource do
39
34
  title :string
@@ -54,8 +49,17 @@ module EffectiveOrganizationsOrganization
54
49
 
55
50
  # Instance Methods
56
51
 
57
- def to_s
58
- title.presence || 'New Organization'
52
+ def representative(user:)
53
+ representatives.find { |rep| rep.user_id == user.id }
54
+ end
55
+
56
+ # Find or build
57
+ def build_representative(user:)
58
+ representative(user: user) || representatives.build(user: user)
59
+ end
60
+
61
+ def users
62
+ representatives.reject(&:marked_for_destruction?).map(&:user)
59
63
  end
60
64
 
61
65
  end
@@ -6,11 +6,7 @@ module EffectiveOrganizationsUser
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  module Base
9
- def effective_organizations_user(organizations_source_type: nil)
10
- @effective_organizations_user_opts = {
11
- organizations_source_type: organizations_source_type
12
- }
13
-
9
+ def effective_organizations_user
14
10
  include ::EffectiveOrganizationsUser
15
11
  end
16
12
  end
@@ -20,17 +16,25 @@ module EffectiveOrganizationsUser
20
16
  end
21
17
 
22
18
  included do
23
- # My teams
24
19
  has_many :representatives, -> { Effective::Representative.sorted },
25
20
  class_name: 'Effective::Representative', inverse_of: :user, dependent: :delete_all
26
21
 
27
- # App scoped
28
- has_many :organizations, through: :representatives,
29
- source_type: @effective_organizations_user_opts[:organizations_source_type] || "#{name.split('::').first}::Organization"
22
+ accepts_nested_attributes_for :representatives, allow_destroy: true
30
23
  end
31
24
 
25
+ # Instance Methods
26
+
32
27
  def representative(organization:)
33
28
  representatives.find { |rep| rep.organization_id == organization.id }
34
29
  end
35
30
 
31
+ # Find or build
32
+ def build_representative(organization:)
33
+ representative(organization: organization) || representatives.build(organization: organization)
34
+ end
35
+
36
+ def organizations
37
+ representatives.reject(&:marked_for_destruction?).map(&:organization)
38
+ end
39
+
36
40
  end
@@ -5,5 +5,5 @@
5
5
 
6
6
  - if organization.persisted?
7
7
  %h2 Representatives
8
- - datatable = Admin::EffectiveRepresentativesDatatable.new(organization_id: organization.id)
8
+ - datatable = Admin::EffectiveRepresentativesDatatable.new(organization_id: organization.id, organization_type: organization.class.name)
9
9
  = render_inline_datatable(datatable)
@@ -4,12 +4,13 @@
4
4
  = f.hidden_field :user_id
5
5
  = f.hidden_field :user_type
6
6
  = f.hidden_field :organization_id
7
+ = f.hidden_field :organization_type
7
8
 
8
9
  - if f.object.new_record?
9
10
  - unless inline_datatable? && inline_datatable.attributes[:organization_id].present?
10
11
  = f.select :organization, { 'Organizations' => EffectiveOrganizations.Organization.sorted }, polymorphic: true
11
12
 
12
- = f.checks :roles, EffectiveRoles.roles_collection(f.object)
13
+ = f.checks :roles, EffectiveRoles.roles_collection(f.object, skip_disabled: true)
13
14
 
14
15
  - unless inline_datatable? && inline_datatable.attributes[:user_id].present?
15
16
  = f.radios :new_representative_user_action, ['Invite new user', 'Add existing user'], inline: true, label: 'Representative'
@@ -28,7 +29,7 @@
28
29
  - unless inline_datatable? && inline_datatable.attributes[:user_id].present?
29
30
  = f.static_field :user
30
31
 
31
- = f.checks :roles, EffectiveRoles.roles_collection(f.object)
32
+ = f.checks :roles, EffectiveRoles.roles_collection(f.object, skip_disabled: true)
32
33
 
33
34
  - unless inline_datatable? && inline_datatable.attributes[:user_id].present?
34
35
  = f.fields_for :user, f.object.user do |fu|
@@ -7,5 +7,5 @@
7
7
 
8
8
  - if organization.persisted?
9
9
  %h2 Representatives
10
- - datatable = EffectiveRepresentativesDatatable.new(organization_id: organization.id)
10
+ - datatable = EffectiveRepresentativesDatatable.new(organization: organization)
11
11
  = render_inline_datatable(datatable)
@@ -10,7 +10,7 @@
10
10
  - unless inline_datatable? && inline_datatable.attributes[:organization_id].present?
11
11
  = f.select :organization, { 'Organizations' => EffectiveOrganizations.Organization.sorted }, polymorphic: true
12
12
 
13
- = f.checks :roles, EffectiveRoles.roles_collection(f.object)
13
+ = f.checks :roles, EffectiveRoles.roles_collection(f.object, skip_disabled: true)
14
14
 
15
15
  - unless inline_datatable? && inline_datatable.attributes[:user_id].present?
16
16
  = f.hidden_field :new_representative_user_action, value: 'Invite new user'
@@ -25,7 +25,7 @@
25
25
  - unless inline_datatable? && inline_datatable.attributes[:user_id].present?
26
26
  = f.static_field :user
27
27
 
28
- = f.checks :roles, EffectiveRoles.roles_collection(f.object)
28
+ = f.checks :roles, EffectiveRoles.roles_collection(f.object, skip_disabled: true)
29
29
 
30
30
  = f.fields_for :user, f.object.user do |fu|
31
31
  = render 'effective/representatives/user_fields', f: fu
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrganizations
2
- VERSION = '0.0.3'.freeze
2
+ VERSION = '0.0.7'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_organizations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-15 00:00:00.000000000 Z
11
+ date: 2021-12-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails