Skip to content

Commit

Permalink
add users with promote status model
Browse files Browse the repository at this point in the history
  • Loading branch information
hellpe committed Oct 31, 2024
1 parent 10539b5 commit a3aa09e
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
WITH proposals_under_impersonation AS (
SELECT
proposals.id AS proposal_id
FROM {{ ref("proposals") }} AS proposals
LEFT JOIN {{ ref("decidim_impersonation_logs") }} AS impersonations ON proposals.first_author_id = impersonations.user_id
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
FROM {{ ref('proposals') }} AS proposals
LEFT JOIN proposals_under_impersonation ON proposals.id = proposals_under_impersonation.proposal_id
22 changes: 22 additions & 0 deletions projects/marseille/models/marts/users_with_promote_info.sql
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
3 changes: 2 additions & 1 deletion projects/marseille/models/staging/decidim/schema.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ sources:
database: "{{ env_var('DBNAME') }}"
schema: public
tables:
- name: decidim_impersonation_logs
- name: decidim_impersonation_logs
- name: decidim_action_logs
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

0 comments on commit a3aa09e

Please sign in to comment.