Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow staff to access detailed impacts from explorer. #878

Merged
merged 7 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions backend/authentication/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ def profile(request):
"first_name": u.first_name,
"last_name": u.last_name,
"organization": u.organization,
"staff": u.is_staff,
"terms_of_use": u.terms_of_use,
"token": u.token,
}
Expand Down
1 change: 1 addition & 0 deletions backend/tests/authentication/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ def test_authenticated_user_should_access_profile(client):
"last_name": "",
"organization": "",
"terms_of_use": False,
"staff": False,
"token": str(test_user.token),
}
2 changes: 2 additions & 0 deletions backend/tests/authentication/test_registration.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ def test_register_post(client, caplog):
"first_name": "John",
"last_name": "Doe",
"organization": "",
"staff": False,
"terms_of_use": True,
"token": str(created_user.token),
}
Expand Down Expand Up @@ -171,6 +172,7 @@ def test_as_admin(client):
"first_name": "",
"last_name": "",
"organization": "",
"staff": True,
"terms_of_use": True,
"token": str(super_user.token),
}
83 changes: 21 additions & 62 deletions src/Data/Dataset.elm
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,11 @@ type Dataset
| Countries (Maybe Country.Code)
| FoodExamples (Maybe Uuid)
| FoodIngredients (Maybe Ingredient.Id)
| FoodProcesses (Maybe Process.Id)
| Impacts (Maybe Definition.Trigram)
| ObjectExamples (Maybe Uuid)
| ObjectProcesses (Maybe Process.Id)
| Processes Scope (Maybe Process.Id)
| TextileExamples (Maybe Uuid)
| TextileMaterials (Maybe Material.Id)
| TextileProcesses (Maybe Process.Id)
| TextileProducts (Maybe Product.Id)


Expand All @@ -50,13 +48,13 @@ datasets scope =
, Impacts Nothing
, FoodIngredients Nothing
, Countries Nothing
, FoodProcesses Nothing
, Processes Scope.Food Nothing
]

Scope.Object ->
[ ObjectExamples Nothing
, Components Scope.Object Nothing
, ObjectProcesses Nothing
, Processes Scope.Object Nothing
, Impacts Nothing
]

Expand All @@ -66,7 +64,7 @@ datasets scope =
, Impacts Nothing
, TextileMaterials Nothing
, Countries Nothing
, TextileProcesses Nothing
, Processes Scope.Textile Nothing
, TextileProducts Nothing
]

Expand All @@ -85,7 +83,7 @@ fromSlug string =
FoodExamples Nothing

"food-processes" ->
FoodProcesses Nothing
Processes Scope.Food Nothing

"impacts" ->
Impacts Nothing
Expand All @@ -103,17 +101,20 @@ fromSlug string =
ObjectExamples Nothing

"object-processes" ->
ObjectProcesses Nothing
Processes Scope.Object Nothing

"processes" ->
TextileProcesses Nothing
Processes Scope.Textile Nothing

"products" ->
TextileProducts Nothing

"textile-components" ->
Components Scope.Textile Nothing

"textile-processes" ->
Processes Scope.Textile Nothing

_ ->
TextileExamples Nothing

Expand All @@ -133,16 +134,13 @@ isDetailed dataset =
FoodIngredients (Just _) ->
True

FoodProcesses (Just _) ->
True

Impacts (Just _) ->
True

ObjectExamples (Just _) ->
True

ObjectProcesses (Just _) ->
Processes _ (Just _) ->
True

TextileExamples (Just _) ->
Expand All @@ -151,9 +149,6 @@ isDetailed dataset =
TextileMaterials (Just _) ->
True

TextileProcesses (Just _) ->
True

TextileProducts (Just _) ->
True

Expand Down Expand Up @@ -186,27 +181,21 @@ reset dataset =
FoodIngredients _ ->
FoodIngredients Nothing

FoodProcesses _ ->
FoodProcesses Nothing

Impacts _ ->
Impacts Nothing

ObjectExamples _ ->
ObjectExamples Nothing

ObjectProcesses _ ->
ObjectProcesses Nothing
Processes scope _ ->
Processes scope Nothing

TextileExamples _ ->
TextileExamples Nothing

TextileMaterials _ ->
TextileMaterials Nothing

TextileProcesses _ ->
TextileProcesses Nothing

TextileProducts _ ->
TextileProducts Nothing

Expand All @@ -223,8 +212,8 @@ same a b =
( FoodIngredients _, FoodIngredients _ ) ->
True

( FoodProcesses _, FoodProcesses _ ) ->
True
( Processes scope1 _, Processes scope2 _ ) ->
scope1 == scope2

( Impacts _, Impacts _ ) ->
True
Expand All @@ -238,15 +227,9 @@ same a b =
( ObjectExamples _, ObjectExamples _ ) ->
True

( ObjectProcesses _, ObjectProcesses _ ) ->
True

( TextileMaterials _, TextileMaterials _ ) ->
True

( TextileProcesses _, TextileProcesses _ ) ->
True

( TextileProducts _, TextileProducts _ ) ->
True

Expand All @@ -269,27 +252,21 @@ setIdFromString idString dataset =
FoodIngredients _ ->
FoodIngredients (Ingredient.idFromString idString)

FoodProcesses _ ->
FoodProcesses (Process.idFromString idString)

Impacts _ ->
Impacts (Definition.toTrigram idString |> Result.toMaybe)

ObjectExamples _ ->
ObjectExamples (Uuid.fromString idString)

ObjectProcesses _ ->
ObjectProcesses (Process.idFromString idString)
Processes scope _ ->
Processes scope (Process.idFromString idString)

TextileExamples _ ->
TextileExamples (Uuid.fromString idString)

TextileMaterials _ ->
TextileMaterials (Just (Material.Id idString))

TextileProcesses _ ->
TextileProcesses (Process.idFromString idString)

TextileProducts _ ->
TextileProducts (Just (Product.Id idString))

Expand All @@ -314,27 +291,21 @@ strings dataset =
FoodIngredients _ ->
{ label = "Ingrédients", slug = "ingredients" }

FoodProcesses _ ->
{ label = "Procédés", slug = "food-processes" }

Impacts _ ->
{ label = "Impacts", slug = "impacts" }

ObjectExamples _ ->
{ label = "Exemples", slug = "object-examples" }

ObjectProcesses _ ->
{ label = "Procédés", slug = "object-processes" }
Processes scope _ ->
{ label = "Procédés", slug = Scope.toString scope ++ "-processes" }

TextileExamples _ ->
{ label = "Exemples", slug = "textile-examples" }

TextileMaterials _ ->
{ label = "Matières", slug = "materials" }

TextileProcesses _ ->
{ label = "Procédés", slug = "processes" }

TextileProducts _ ->
{ label = "Produits", slug = "products" }

Expand Down Expand Up @@ -366,12 +337,6 @@ toRoutePath dataset =
FoodIngredients Nothing ->
[ slug dataset ]

FoodProcesses (Just id) ->
[ slug dataset, Process.idToString id ]

FoodProcesses Nothing ->
[ slug dataset ]

Impacts (Just trigram) ->
[ slug dataset, Definition.toString trigram ]

Expand All @@ -384,10 +349,10 @@ toRoutePath dataset =
ObjectExamples Nothing ->
[ slug dataset ]

ObjectProcesses (Just id) ->
Processes _ (Just id) ->
[ slug dataset, Process.idToString id ]

ObjectProcesses Nothing ->
Processes _ Nothing ->
[ slug dataset ]

TextileExamples (Just id) ->
Expand All @@ -402,12 +367,6 @@ toRoutePath dataset =
TextileMaterials Nothing ->
[ slug dataset ]

TextileProcesses (Just id) ->
[ slug dataset, Process.idToString id ]

TextileProcesses Nothing ->
[ slug dataset ]

TextileProducts (Just id) ->
[ slug dataset, Product.idToString id ]

Expand Down
4 changes: 4 additions & 0 deletions src/Data/User.elm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type alias User =
, email : String
, firstname : String
, lastname : String
, staff : Bool
, token : String
}

Expand All @@ -33,6 +34,7 @@ decode =
|> Pipe.required "email" Decode.string
|> Pipe.required "first_name" Decode.string
|> Pipe.required "last_name" Decode.string
|> Pipe.optional "staff" Decode.bool False
|> Pipe.required "token" Decode.string


Expand All @@ -44,6 +46,7 @@ encode user =
, ( "last_name", Encode.string user.lastname )
, ( "organization", Encode.string user.company )
, ( "terms_of_use", Encode.bool user.cgu )
, ( "staff", Encode.bool user.staff )
, ( "token", Encode.string user.token )
]

Expand All @@ -68,5 +71,6 @@ form user =
, firstname = user.firstname
, lastname = user.lastname
, next = "/#/auth/authenticated"
, staff = False
, token = ""
}
59 changes: 34 additions & 25 deletions src/Page/Auth.elm
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ emptyModel { authenticated } =
, lastname = ""
, company = ""
, cgu = False
, staff = False
, token = ""
}
, formErrors = Dict.empty
Expand Down Expand Up @@ -251,33 +252,41 @@ view session model =

viewAccount : User -> Html Msg
viewAccount user =
div [ class "table-responsive border shadow-sm" ]
[ table [ class "table table-striped mb-0" ]
[ [ ( "Email", text user.email )
, ( "Nom", text user.lastname )
, ( "Prénom", text user.firstname )
, ( "Organisation", text user.company )
, ( "Jeton d'API"
, div []
[ code [] [ text user.token ]
, br [] []
, small [ class "text-muted" ]
[ text "Nécessaire pour obtenir les impacts détaillés dans "
, a [ Route.href Route.Api ] [ text "l'API" ]
[ Just ( "Email", text user.email )
, if user.staff then
Just ( "Équipe Ecobalyse", strong [] [ text "Oui" ] )

else
Nothing
, Just ( "Nom", text user.lastname )
, Just ( "Prénom", text user.firstname )
, Just ( "Organisation", text user.company )
, Just
( "Jeton d'API"
, div []
[ code [] [ text user.token ]
, br [] []
, small [ class "text-muted" ]
[ text "Nécessaire pour obtenir les impacts détaillés dans "
, a [ Route.href Route.Api ] [ text "l'API" ]
]
]
)
]
|> List.filterMap
(Maybe.map
(\( label, htmlValue ) ->
tr []
[ th [] [ text <| label ++ " : " ]
, td [] [ htmlValue ]
]
]
)
]
|> List.map
(\( label, htmlValue ) ->
tr []
[ th [] [ text <| label ++ " : " ]
, td [] [ htmlValue ]
]
)
|> tbody []
]
]
)
|> tbody []
|> List.singleton
|> table [ class "table table-striped mb-0" ]
|> List.singleton
|> div [ class "table-responsive border shadow-sm" ]


viewLoginRegisterForm : Model -> Html Msg
Expand Down
Loading
Loading