effective_organizations 0.0.5 → 0.0.9

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: 1f978ab4fee3200d82c2f9c6858f707d35155c0da70f0f4a611e558597ea17e2
4
- data.tar.gz: 67a3e163f691e3baeec1e48ce0687fcb649e491b65e4fb9a01cd03575726b59c
3
+ metadata.gz: c1251bb3a7cf64ab3a2cc1019031611b6e62bcde3e146026075ca9f3a09a4950
4
+ data.tar.gz: c240b5ef71a712a338ccf3153a91f06babde47008cb5b30990fc88049406ed6b
5
5
  SHA512:
6
- metadata.gz: 2f07c62ddd2d61aa1f31c5abba3d5cd56b019b6fc58e474d1b063f3246416d077d357109b7c66fe9f514c1d263e18e23488662c9c2701fe52db5738ddba6ffe1
7
- data.tar.gz: ea9ecd0a199c925c5ddd3550a83524d23fab81d48c4e91d620bee64970d7ae95238f561c8184bbeb4c43182db2e7b030e1afa97d663049c2c1b8c24b706f2a16
6
+ metadata.gz: 444bb29c6c1ec54d698e10f4b0ba16cf418fccfede8aad5ef06fa59adc9ea3253f8f67bc5932e2d312fee608d609dc8bc9ef5ca5f9f832fadea700574bffe2d5
7
+ data.tar.gz: 2c0807e703a5bd3ff0db559de7d963e2f6ba3f772558543f16118063172cf1d4de3a6baba579adf054689b37e65a5149fa1ecc7a0a9ccfa19e7573edc2908715
@@ -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
@@ -1,10 +1,10 @@
1
1
  %h2 Organizations
2
2
 
3
3
  - if current_user.organizations.present?
4
- %p You belong to #{pluralize(current_user.organizations.length, 'organization')}
4
+ %p You are a representative for #{pluralize(current_user.organizations.length, 'organization')}.
5
5
 
6
6
  - datatable = EffectiveResources.best('EffectiveOrganizationsDatatable').new(self, namespace: :effective)
7
- = render_datatable(datatable)
7
+ = render_datatable(datatable, simple: true)
8
8
 
9
9
  - else
10
- %p You do not belong to any organizations.
10
+ %p You are not a representative. When you create an organization, or if someone else adds you to their organization, we'll show them here.
@@ -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)
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrganizations
2
- VERSION = '0.0.5'.freeze
2
+ VERSION = '0.0.9'.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.5
4
+ version: 0.0.9
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-17 00:00:00.000000000 Z
11
+ date: 2021-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails