effective_organizations 0.0.5 → 0.0.6

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: a2ee1cb9ffc7df883ea343966168245ab3d77ba59ef9753a20d825702ba46aaa
4
+ data.tar.gz: fcd8f65d9dbc66c5073077e6bd7fe9f48774c4444d965c7c4ce95d09c3d97935
5
5
  SHA512:
6
- metadata.gz: 2f07c62ddd2d61aa1f31c5abba3d5cd56b019b6fc58e474d1b063f3246416d077d357109b7c66fe9f514c1d263e18e23488662c9c2701fe52db5738ddba6ffe1
7
- data.tar.gz: ea9ecd0a199c925c5ddd3550a83524d23fab81d48c4e91d620bee64970d7ae95238f561c8184bbeb4c43182db2e7b030e1afa97d663049c2c1b8c24b706f2a16
6
+ metadata.gz: a34485e30e3d66f85cb4dff1ed2ccd6656134ac5171c2ceae64e8fc30336144c1ac6c9889dab98b018dbdad0c2b3bda96e583f70583a9907f09eaf1ed4ebe1a0
7
+ data.tar.gz: fb7e677000619da597b0b43f5ae827211d2d55fca0d51326559b27bb7fc7fbd7b3155260afa37f7768360a0f695d2d80667dabc680414f2479582c645c438dac
@@ -32,6 +32,8 @@ module EffectiveOrganizationsOrganization
32
32
  has_many :representatives, -> { Effective::Representative.sorted },
33
33
  class_name: 'Effective::Representative', inverse_of: :organization, dependent: :delete_all
34
34
 
35
+ accepts_nested_attributes_for :representatives, allow_destroy: true
36
+
35
37
  has_many :users, through: :representatives,
36
38
  source_type: (@effective_organizations_organization_opts[:users_source_type] || (name.start_with?('Effective') ? '::User' : "#{name.split('::').first}::Organization"))
37
39
 
@@ -58,4 +60,13 @@ module EffectiveOrganizationsOrganization
58
60
  title.presence || 'New Organization'
59
61
  end
60
62
 
63
+ def representative(user:)
64
+ representatives.find { |rep| rep.user_id == user.id }
65
+ end
66
+
67
+ # Find or build
68
+ def build_representative(user:)
69
+ representative(user: user) || representatives.build(user: user)
70
+ end
71
+
61
72
  end
@@ -24,6 +24,8 @@ module EffectiveOrganizationsUser
24
24
  has_many :representatives, -> { Effective::Representative.sorted },
25
25
  class_name: 'Effective::Representative', inverse_of: :user, dependent: :delete_all
26
26
 
27
+ accepts_nested_attributes_for :representatives, allow_destroy: true
28
+
27
29
  # App scoped
28
30
  has_many :organizations, through: :representatives,
29
31
  source_type: @effective_organizations_user_opts[:organizations_source_type] || "#{name.split('::').first}::Organization"
@@ -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.6'.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.6
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-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails