activerecord-tenant-level-security 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +6 -5
- data/CHANGELOG.md +14 -0
- data/CODE_OF_CONDUCT.jp.md +86 -0
- data/CODE_OF_CONDUCT.md +105 -46
- data/LICENSE.txt +4 -18
- data/README.md +8 -2
- data/lib/activerecord-tenant-level-security/schema_statements.rb +12 -2
- data/lib/activerecord-tenant-level-security/version.rb +1 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e847b09c2072b1d43800f05548532cbea63ee65700b80a50f48ce212ce1128c4
|
4
|
+
data.tar.gz: '0884eb072cb058b099b449cbc940a373abb247f6c01a396df64486941b091167'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2761438baef9b4e0c3ea159121f28da51f537bb5c70bcb8d4c81b6d22283d2d0bab9eea784ba84d0b68635d68954cc27eb3bc36f56f6c92508914998e548422
|
7
|
+
data.tar.gz: 33e9fbbc489d73f12418e7c53483989b404417051aff14a28ce0aa77598aef9547d89a08a6476e908cdb26972963b876c37a15d79e145f14a6c514f55dfc5310
|
data/.circleci/config.yml
CHANGED
@@ -11,6 +11,8 @@ jobs:
|
|
11
11
|
type: string
|
12
12
|
docker:
|
13
13
|
- image: << parameters.ruby >>
|
14
|
+
environment:
|
15
|
+
BUNDLE_GEMFILE: gemfiles/<< parameters.rails >>.gemfile
|
14
16
|
- image: cimg/<< parameters.postgres >>
|
15
17
|
environment:
|
16
18
|
POSTGRES_HOST_AUTH_METHOD: trust
|
@@ -18,8 +20,7 @@ jobs:
|
|
18
20
|
- checkout
|
19
21
|
- run: gem install bundler
|
20
22
|
- run: bundle install
|
21
|
-
- run: bundle exec
|
22
|
-
- run: bundle exec appraisal << parameters.rails >> rspec
|
23
|
+
- run: bundle exec rspec
|
23
24
|
|
24
25
|
workflows:
|
25
26
|
all-tests:
|
@@ -27,6 +28,6 @@ workflows:
|
|
27
28
|
- test:
|
28
29
|
matrix:
|
29
30
|
parameters:
|
30
|
-
ruby: ['ruby:
|
31
|
-
rails: ['
|
32
|
-
postgres: ['postgres:11.
|
31
|
+
ruby: ['ruby:3.0', 'ruby:3.1', 'ruby:3.2']
|
32
|
+
rails: ['rails_6.0', 'rails_6.1', 'rails_7.0']
|
33
|
+
postgres: ['postgres:11.19', 'postgres:12.14', 'postgres:13.10', 'postgres:14.7', 'postgres:15.2']
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,17 @@
|
|
1
|
+
## v0.2.0 (2023-04-14)
|
2
|
+
|
3
|
+
This release includes changes to policies created by `create_policy`. Migrations that have already been performed will not be affected, so it is safe to upgrade as-is, but for performance reasons it is recommended to update existing policies to the new format. See https://github.com/kufu/activerecord-tenant-level-security/pull/16 for details.
|
4
|
+
|
5
|
+
### Breaking Changes
|
6
|
+
|
7
|
+
- [#16](https://github.com/kufu/activerecord-tenant-level-security/pull/16): Cast `current_setting` instead of `tenant_id`
|
8
|
+
- [#17](https://github.com/kufu/activerecord-tenant-level-security/pull/17): CI against Ruby 3.2 and PostgreSQL 15, drop Ruby 2.7
|
9
|
+
|
10
|
+
### Chores
|
11
|
+
|
12
|
+
- [#13](https://github.com/kufu/activerecord-tenant-level-security/pull/13): Mention multiple databases support status
|
13
|
+
- [#15](https://github.com/kufu/activerecord-tenant-level-security/pull/15): Update License and CoC files
|
14
|
+
|
1
15
|
## v0.1.0 (2023-01-23)
|
2
16
|
|
3
17
|
### BugFixes
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# コントリビューター行動規範
|
2
|
+
|
3
|
+
## 私たちの約束
|
4
|
+
メンバー、コントリビューター、およびリーダーとして、年齢、体の大きさ、目に見えるまたは目に見えない障害、民族性、性別、
|
5
|
+
性同一性、表現、経験のレベル、教育、社会経済的地位、国籍、人格、人種、宗教、または性的同一性と指向に関係なく、
|
6
|
+
コミュニティへの参加をハラスメントのない体験にすることを誓います。
|
7
|
+
|
8
|
+
私たちは、オープンで親しみやすく、多様で包括的で健全なコミュニティに貢献する方法で行動し、交流することを誓います。
|
9
|
+
|
10
|
+
## 私たちの標準
|
11
|
+
|
12
|
+
前向きな環境を作り上げることに貢献する行動の例:
|
13
|
+
|
14
|
+
* 他人への共感と優しさを示す
|
15
|
+
|
16
|
+
* 異なる意見、視点、経験を尊重する
|
17
|
+
|
18
|
+
* 建設的なフィードバックを与え、優雅に受け入れる
|
19
|
+
|
20
|
+
* 私たちの過ちの影響を受けた人々に責任を受け入れ、謝罪し、そしてその経験から学ぶ
|
21
|
+
|
22
|
+
* 個人としてだけでなく、コミュニティ全体にとっても最善であることに焦点を当てる
|
23
|
+
|
24
|
+
許容できない行動の例は次のとおりです。
|
25
|
+
|
26
|
+
* 性的な言葉や画像の使用、および性的な注意またはその他あらゆる種類の問題行為
|
27
|
+
|
28
|
+
* トローリング、侮辱的または中傷的なコメント、個人的または政治的攻撃
|
29
|
+
|
30
|
+
* 公的またはプライベートの嫌がらせ
|
31
|
+
|
32
|
+
* 明示的な許可なしに、住所や電子メールアドレスなど、他者の個人情報を公開する
|
33
|
+
|
34
|
+
* 職業上不適切と合理的に考えられるその他の行為
|
35
|
+
|
36
|
+
## 執行責任
|
37
|
+
|
38
|
+
コミュニティリーダーは、許容される行動の基準を明確にし、実施する責任があり、不適切、脅迫的、攻撃的、または有害と見なされる行動に応じて、適切で公正な是正措置を講じます。
|
39
|
+
|
40
|
+
コミュニティリーダーは、コメント、コミット、コード、wikiの編集、問題、およびこの行動規範に沿っていないその他の貢献を削除、編集、または拒否する権利と責任を持ち、適切な場合はモデレーションの決定の理由を伝えます。
|
41
|
+
|
42
|
+
## 適用範囲
|
43
|
+
|
44
|
+
この行動規範は、すべてのコミュニティスペース内で適用され、個人がパブリックスペースでコミュニティを公式に代表している場合にも適用されます。
|
45
|
+
私たちのコミュニティを代表する例には、公式の電子メールアドレスの使用、公式のソーシャルメディアアカウントを介した投稿、オンラインまたはオフラインのイベントでの指定代理人としての行動などがあります。
|
46
|
+
|
47
|
+
## 執行
|
48
|
+
|
49
|
+
虐待的、嫌がらせ、またはその他の許容できない行動の事例は、執行を担当するコミュニティリーダーに対して `oss@smarthr.co.jp` で報告される場合があります。
|
50
|
+
すべての苦情は迅速かつ公正にレビューおよび調査されます。
|
51
|
+
|
52
|
+
すべてのコミュニティリーダーは、問題の報告者のプライバシーとセキュリティを尊重する義務があります。
|
53
|
+
|
54
|
+
## 執行ガイドライン
|
55
|
+
|
56
|
+
コミュニティリーダーは、この行動規範に違反していると見なした行動への帰結を判断する際に、これらのコミュニティガイドラインに従います。
|
57
|
+
|
58
|
+
### 1. 更生
|
59
|
+
|
60
|
+
**コミュニティへの影響**: コミュニティで専門家にふさわしくない、または歓迎されないと思われる不適切な言葉の使用やその他の不適切な行動をすること。
|
61
|
+
|
62
|
+
**帰結**: コミュニティリーダーからの非公開の書面による警告。違反の理由を明確にし、行動が不適切だった理由を説明します。 公の謝罪が要求される場合があります。
|
63
|
+
|
64
|
+
### 2. 警告
|
65
|
+
|
66
|
+
**コミュニティへの影響**: 単一の出来事または一連の動作による違反。
|
67
|
+
|
68
|
+
**帰結**: 持続的な行動の結果を伴う警告。 指定された期間、行動規範の実施者との一方的な対話を含め、関係者との対話はありません。 これには、コミュニティスペースやソーシャルメディアなどの外部チャネルでの相互作用の回避が含まれます。 これらの条件に違反すると、一時的または永続的に禁止される場合があります。
|
69
|
+
|
70
|
+
### 3. 一時的な禁止
|
71
|
+
**コミュニティへの影響**: 持続的で不適切な行動を含む、コミュニティ標準の重大な違反。
|
72
|
+
|
73
|
+
**帰結**: 指定された期間のコミュニティとのあらゆる種類の相互関係または公的なコミュニケーションの一時的な禁止。 この期間中、行動規範を実施する人々との一方的な対話を含め、関係する人々との公的または私的な対話は許可されません。
|
74
|
+
これらの条件に違反すると、永久的に禁止される場合があります。
|
75
|
+
### 4. 永久的な禁止
|
76
|
+
**コミュニティへの影響**: 連続的な不適切な行動、個人への嫌がらせ、または個人の集団に対する攻撃または名誉毀損を含む、コミュニティの標準への違反のパターンを示す。
|
77
|
+
|
78
|
+
**帰結**: コミュニティ内でのあらゆる種類の公的な相互関係の永久的な禁止。
|
79
|
+
|
80
|
+
## 帰属
|
81
|
+
この行動規範は、https://www.contributor-covenant.org/version/2/0/code_of_conduct.html で利用可能な [Contributor Covenant][homepage] バージョン2.0を基に作成されています。
|
82
|
+
|
83
|
+
コミュニティへの影響ガイドラインは[Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity)に適合しています。
|
84
|
+
|
85
|
+
[homepage]: https://www.contributor-covenant.org
|
86
|
+
この行動規範に関する一般的な質問への回答については、https://www.contributor-covenant.org/faq のFAQを参照してください。翻訳はhttps://www.contributor-covenant.org/translations で入手できます。
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,74 +1,133 @@
|
|
1
|
+
|
1
2
|
# Contributor Covenant Code of Conduct
|
2
3
|
|
3
4
|
## Our Pledge
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
nationality, personal appearance, race, religion, or sexual identity
|
10
|
-
orientation.
|
6
|
+
We as members, contributors, and leaders pledge to make participation in our
|
7
|
+
community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, visible or invisible disability, ethnicity, sex characteristics, gender
|
9
|
+
identity and expression, level of experience, education, socio-economic status,
|
10
|
+
nationality, personal appearance, race, religion, or sexual identity
|
11
|
+
and orientation.
|
12
|
+
|
13
|
+
We pledge to act and interact in ways that contribute to an open, welcoming,
|
14
|
+
diverse, inclusive, and healthy community.
|
11
15
|
|
12
16
|
## Our Standards
|
13
17
|
|
14
|
-
Examples of behavior that contributes to
|
15
|
-
include:
|
18
|
+
Examples of behavior that contributes to a positive environment for our
|
19
|
+
community include:
|
16
20
|
|
17
|
-
*
|
18
|
-
* Being respectful of differing viewpoints and experiences
|
19
|
-
*
|
20
|
-
*
|
21
|
-
|
21
|
+
* Demonstrating empathy and kindness toward other people
|
22
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
23
|
+
* Giving and gracefully accepting constructive feedback
|
24
|
+
* Accepting responsibility and apologizing to those affected by our mistakes,
|
25
|
+
and learning from the experience
|
26
|
+
* Focusing on what is best not just for us as individuals, but for the
|
27
|
+
overall community
|
22
28
|
|
23
|
-
Examples of unacceptable behavior
|
29
|
+
Examples of unacceptable behavior include:
|
24
30
|
|
25
|
-
* The use of sexualized language or imagery and
|
26
|
-
advances
|
27
|
-
* Trolling, insulting
|
31
|
+
* The use of sexualized language or imagery, and sexual attention or
|
32
|
+
advances of any kind
|
33
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
28
34
|
* Public or private harassment
|
29
|
-
* Publishing others' private information, such as a physical or
|
30
|
-
address, without explicit permission
|
35
|
+
* Publishing others' private information, such as a physical or email
|
36
|
+
address, without their explicit permission
|
31
37
|
* Other conduct which could reasonably be considered inappropriate in a
|
32
38
|
professional setting
|
33
39
|
|
34
|
-
##
|
40
|
+
## Enforcement Responsibilities
|
35
41
|
|
36
|
-
|
37
|
-
behavior and
|
38
|
-
response to any
|
42
|
+
Community leaders are responsible for clarifying and enforcing our standards of
|
43
|
+
acceptable behavior and will take appropriate and fair corrective action in
|
44
|
+
response to any behavior that they deem inappropriate, threatening, offensive,
|
45
|
+
or harmful.
|
39
46
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
threatening, offensive, or harmful.
|
47
|
+
Community leaders have the right and responsibility to remove, edit, or reject
|
48
|
+
comments, commits, code, wiki edits, issues, and other contributions that are
|
49
|
+
not aligned to this Code of Conduct, and will communicate reasons for moderation
|
50
|
+
decisions when appropriate.
|
45
51
|
|
46
52
|
## Scope
|
47
53
|
|
48
|
-
This Code of Conduct applies
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
representative at an online or offline event.
|
53
|
-
further defined and clarified by project maintainers.
|
54
|
+
This Code of Conduct applies within all community spaces, and also applies when
|
55
|
+
an individual is officially representing the community in public spaces.
|
56
|
+
Examples of representing our community include using an official e-mail address,
|
57
|
+
posting via an official social media account, or acting as an appointed
|
58
|
+
representative at an online or offline event.
|
54
59
|
|
55
60
|
## Enforcement
|
56
61
|
|
57
62
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
-
reported
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
+
reported to the community leaders responsible for enforcement at
|
64
|
+
`oss@smarthr.co.jp`.
|
65
|
+
All complaints will be reviewed and investigated promptly and fairly.
|
66
|
+
|
67
|
+
All community leaders are obligated to respect the privacy and security of the
|
68
|
+
reporter of any incident.
|
69
|
+
|
70
|
+
## Enforcement Guidelines
|
71
|
+
|
72
|
+
Community leaders will follow these Community Impact Guidelines in determining
|
73
|
+
the consequences for any action they deem in violation of this Code of Conduct:
|
74
|
+
|
75
|
+
### 1. Correction
|
76
|
+
|
77
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed
|
78
|
+
unprofessional or unwelcome in the community.
|
79
|
+
|
80
|
+
**Consequence**: A private, written warning from community leaders, providing
|
81
|
+
clarity around the nature of the violation and an explanation of why the
|
82
|
+
behavior was inappropriate. A public apology may be requested.
|
83
|
+
|
84
|
+
### 2. Warning
|
63
85
|
|
64
|
-
|
65
|
-
|
66
|
-
|
86
|
+
**Community Impact**: A violation through a single incident or series
|
87
|
+
of actions.
|
88
|
+
|
89
|
+
**Consequence**: A warning with consequences for continued behavior. No
|
90
|
+
interaction with the people involved, including unsolicited interaction with
|
91
|
+
those enforcing the Code of Conduct, for a specified period of time. This
|
92
|
+
includes avoiding interactions in community spaces as well as external channels
|
93
|
+
like social media. Violating these terms may lead to a temporary or
|
94
|
+
permanent ban.
|
95
|
+
|
96
|
+
### 3. Temporary Ban
|
97
|
+
|
98
|
+
**Community Impact**: A serious violation of community standards, including
|
99
|
+
sustained inappropriate behavior.
|
100
|
+
|
101
|
+
**Consequence**: A temporary ban from any sort of interaction or public
|
102
|
+
communication with the community for a specified period of time. No public or
|
103
|
+
private interaction with the people involved, including unsolicited interaction
|
104
|
+
with those enforcing the Code of Conduct, is allowed during this period.
|
105
|
+
Violating these terms may lead to a permanent ban.
|
106
|
+
|
107
|
+
### 4. Permanent Ban
|
108
|
+
|
109
|
+
**Community Impact**: Demonstrating a pattern of violation of community
|
110
|
+
standards, including sustained inappropriate behavior, harassment of an
|
111
|
+
individual, or aggression toward or disparagement of classes of individuals.
|
112
|
+
|
113
|
+
**Consequence**: A permanent ban from any sort of public interaction within
|
114
|
+
the community.
|
67
115
|
|
68
116
|
## Attribution
|
69
117
|
|
70
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
71
|
-
available at
|
118
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
119
|
+
version 2.0, available at
|
120
|
+
[https://www.contributor-covenant.org/version/2/0/code_of_conduct.html][v2.0].
|
121
|
+
|
122
|
+
Community Impact Guidelines were inspired by
|
123
|
+
[Mozilla's code of conduct enforcement ladder][Mozilla CoC].
|
124
|
+
|
125
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
126
|
+
[https://www.contributor-covenant.org/faq][FAQ]. Translations are available
|
127
|
+
at [https://www.contributor-covenant.org/translations][translations].
|
72
128
|
|
73
|
-
[homepage]:
|
74
|
-
[
|
129
|
+
[homepage]: https://www.contributor-covenant.org
|
130
|
+
[v2.0]: https://www.contributor-covenant.org/version/2/0/code_of_conduct.html
|
131
|
+
[Mozilla CoC]: https://github.com/mozilla/diversity
|
132
|
+
[FAQ]: https://www.contributor-covenant.org/faq
|
133
|
+
[translations]: https://www.contributor-covenant.org/translations
|
data/LICENSE.txt
CHANGED
@@ -1,21 +1,7 @@
|
|
1
|
-
|
1
|
+
Copyright 2023 SmartHR, Inc.
|
2
2
|
|
3
|
-
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
4
|
|
5
|
-
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
11
6
|
|
12
|
-
|
13
|
-
all copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
-
THE SOFTWARE.
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -82,8 +82,8 @@ CREATE POLICY tenant_policy ON employees
|
|
82
82
|
AS PERMISSIVE
|
83
83
|
FOR ALL
|
84
84
|
TO PUBLIC
|
85
|
-
USING (tenant_id
|
86
|
-
WITH CHECK (tenant_id
|
85
|
+
USING (tenant_id = NULLIF(current_setting('tenant_level_security.tenant_id'), '')::integer)
|
86
|
+
WITH CHECK (tenant_id = NULLIF(current_setting('tenant_level_security.tenant_id'), '')::integer)
|
87
87
|
```
|
88
88
|
|
89
89
|
In the table in which the policy is created, only the rows that match the current setting of `tenant_level_security.tenant_id` can be referenced. This value is set by `TenantLevelSecurity.with` etc.
|
@@ -124,6 +124,12 @@ end
|
|
124
124
|
|
125
125
|
The middleware propagates the current tenant to the job through the session. This allows RLS to be enabled even within workers.
|
126
126
|
|
127
|
+
## Multiple Databases
|
128
|
+
|
129
|
+
Active Record 6+ adds support for [multiple databases](https://guides.rubyonrails.org/active_record_multiple_databases.html). Note that when using multiple databases with this gem, you need to explicitly switch when connecting other databases.
|
130
|
+
|
131
|
+
In multiple databases, Active Record creates a connection pool for each connection, but `TenantLevelSecurity.switch` only switches for the current connection.
|
132
|
+
|
127
133
|
## Development
|
128
134
|
|
129
135
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -5,13 +5,14 @@ module TenantLevelSecurity
|
|
5
5
|
ALTER TABLE #{table_name} ENABLE ROW LEVEL SECURITY;
|
6
6
|
ALTER TABLE #{table_name} FORCE ROW LEVEL SECURITY;
|
7
7
|
SQL
|
8
|
+
tenant_id_data_type = get_tenant_id_data_type(table_name)
|
8
9
|
execute <<~SQL
|
9
10
|
CREATE POLICY tenant_policy ON #{table_name}
|
10
11
|
AS PERMISSIVE
|
11
12
|
FOR ALL
|
12
13
|
TO PUBLIC
|
13
|
-
USING (tenant_id
|
14
|
-
WITH CHECK (tenant_id
|
14
|
+
USING (tenant_id = NULLIF(current_setting('tenant_level_security.tenant_id'), '')::#{tenant_id_data_type})
|
15
|
+
WITH CHECK (tenant_id = NULLIF(current_setting('tenant_level_security.tenant_id'), '')::#{tenant_id_data_type})
|
15
16
|
SQL
|
16
17
|
end
|
17
18
|
|
@@ -24,5 +25,14 @@ module TenantLevelSecurity
|
|
24
25
|
DROP POLICY tenant_policy ON #{table_name}
|
25
26
|
SQL
|
26
27
|
end
|
28
|
+
|
29
|
+
private
|
30
|
+
def get_tenant_id_data_type(table_name)
|
31
|
+
tenant_id_column = columns(table_name)
|
32
|
+
.find{|column| column.name == 'tenant_id'}
|
33
|
+
raise "tenant_id column is missing in #{table_name}" if tenant_id_column.nil?
|
34
|
+
|
35
|
+
tenant_id_column.sql_type
|
36
|
+
end
|
27
37
|
end
|
28
38
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-tenant-level-security
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SmartHR
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -121,6 +121,7 @@ files:
|
|
121
121
|
- ".rspec"
|
122
122
|
- Appraisals
|
123
123
|
- CHANGELOG.md
|
124
|
+
- CODE_OF_CONDUCT.jp.md
|
124
125
|
- CODE_OF_CONDUCT.md
|
125
126
|
- Gemfile
|
126
127
|
- LICENSE.txt
|
@@ -145,8 +146,8 @@ licenses:
|
|
145
146
|
metadata:
|
146
147
|
homepage_uri: https://github.com/kufu/activerecord-tenant-level-security
|
147
148
|
source_code_uri: https://github.com/kufu/activerecord-tenant-level-security
|
148
|
-
changelog_uri: https://github.com/kufu/activerecord-tenant-level-security/blob/v0.
|
149
|
-
post_install_message:
|
149
|
+
changelog_uri: https://github.com/kufu/activerecord-tenant-level-security/blob/v0.2.0/CHANGELOG.md
|
150
|
+
post_install_message:
|
150
151
|
rdoc_options: []
|
151
152
|
require_paths:
|
152
153
|
- lib
|
@@ -161,8 +162,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
162
|
- !ruby/object:Gem::Version
|
162
163
|
version: '0'
|
163
164
|
requirements: []
|
164
|
-
rubygems_version: 3.
|
165
|
-
signing_key:
|
165
|
+
rubygems_version: 3.2.33
|
166
|
+
signing_key:
|
166
167
|
specification_version: 4
|
167
168
|
summary: An Active Record extension for Multitenancy with PostgreSQL Row Level Security
|
168
169
|
test_files: []
|