-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30 from OpenSourcePolitics/impersonation_poc
Impersonation poc
- Loading branch information
Showing
6 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
projects/marseille/models/marts/proposals_with_impersonation_info.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
WITH proposals_under_impersonation AS ( | ||
SELECT | ||
proposals.id AS proposal_id | ||
FROM {{ ref('proposals') }} AS proposals | ||
LEFT JOIN {{ ref('stg_decidim_impersonation_logs') }} AS impersonations ON proposals.first_author_id = impersonations.user_id | ||
WHERE proposals.created_at BETWEEN impersonations.started_at AND impersonations.ended_at | ||
ORDER BY proposals.id | ||
) | ||
|
||
SELECT | ||
*, | ||
(CASE WHEN proposals_under_impersonation.proposal_id IS NOT NULL THEN true ELSE false END) AS authored_under_impersonation | ||
FROM {{ ref('proposals') }} AS proposals | ||
LEFT JOIN proposals_under_impersonation ON proposals.id = proposals_under_impersonation.proposal_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#test disabled because of ARRAY incompatibility (dbt limitation) | ||
#unit_tests: | ||
# - name: date_match_test | ||
# description: "Check that proposals with creation dates outside impersonation ranges are properly flagged as not impersonated" | ||
# model: proposals_with_impersonation_info | ||
# given: | ||
# - input: ref('proposals') | ||
# format: dict | ||
# rows: | ||
# - {id: 1, first_author_id: 42, created_at: "2021-08-31 14:12:33.144731"} | ||
# - {id: 1, first_author_id: 43, created_at: "2021-08-31 14:12:34.144731"} | ||
# - {id: 1, first_author_id: 44, created_at: "2021-08-31 14:12:31.144731"} | ||
# - input: ref('decidim_impersonation_logs') | ||
# format: dict | ||
# rows: | ||
# - {user_id: 42, started_at: "2021-08-31 14:12:32", ended_at: "2021-08-31 14:12:34"} | ||
# - {user_id: 43, started_at: "2021-08-31 14:12:32", ended_at: "2021-08-31 14:12:34"} | ||
# - {user_id: 44, started_at: "2021-08-31 14:12:32", ended_at: "2021-08-31 14:12:34"} | ||
# expect: | ||
# format: dict | ||
# rows: | ||
# - {authored_under_impersonation: true} | ||
# - {authored_under_impersonation: false} | ||
# - {authored_under_impersonation: false} |
22 changes: 22 additions & 0 deletions
22
projects/marseille/models/marts/users_with_promote_info.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
WITH promote_actions AS ( | ||
SELECT | ||
DISTINCT ON (users.id) | ||
users.id AS user_id, | ||
decidim_action_logs.id AS log_id, | ||
action | ||
FROM {{ ref('stg_decidim_action_logs') }} AS decidim_action_logs | ||
LEFT JOIN {{ ref('users') }} AS users ON users.id = decidim_action_logs.resource_id | ||
WHERE resource_type = 'Decidim::User' | ||
AND action = 'promote' | ||
) | ||
|
||
SELECT | ||
users.*, | ||
(CASE | ||
WHEN promote_actions.action IS NOT NULL AND users.managed = false THEN 'Confirmée' | ||
WHEN promote_actions.action IS NOT NULL AND users.managed = true THEN 'En attente' | ||
WHEN promote_actions.action IS NULL AND users.managed = false THEN 'Utilisateur non représenté' | ||
ELSE 'Non proposée' | ||
END) AS promotion_status | ||
FROM {{ ref('users') }} AS users | ||
LEFT JOIN promote_actions ON users.id = promote_actions.user_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
version: 2 | ||
|
||
sources: | ||
- name: decidim | ||
database: "{{ env_var('DBNAME') }}" | ||
schema: public | ||
tables: | ||
- name: decidim_impersonation_logs | ||
- name: decidim_action_logs |
13 changes: 13 additions & 0 deletions
13
projects/marseille/models/staging/decidim/stg_decidim_action_logs.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
WITH source AS ( | ||
SELECT * FROM {{ source('decidim', 'decidim_action_logs') }} | ||
) | ||
|
||
SELECT | ||
id, | ||
created_at, | ||
updated_at, | ||
decidim_user_id, | ||
action, | ||
resource_type, | ||
resource_id | ||
FROM source |
11 changes: 11 additions & 0 deletions
11
projects/marseille/models/staging/decidim/stg_decidim_impersonation_logs.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
WITH source AS ( | ||
SELECT * FROM {{ source('decidim', 'decidim_impersonation_logs') }} | ||
) | ||
|
||
SELECT | ||
id, | ||
decidim_user_id AS user_id, | ||
reason, | ||
started_at, | ||
ended_at | ||
FROM source |