Skip to content
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
30 changes: 19 additions & 11 deletions src/UnisonShare/Account.elm
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module UnisonShare.Account exposing (..)

import Json.Decode as Decode exposing (field, maybe, string)
import Json.Decode as Decode exposing (string)
import Json.Decode.Pipeline exposing (optional, required)
import Lib.Decode.Helpers exposing (url)
import Lib.UserHandle as UserHandle exposing (UserHandle)
import UI.Avatar as Avatar exposing (Avatar)
import UI.Icon as Icon
import UnisonShare.Project.ProjectRef as ProjectRef exposing (ProjectRef)
import UnisonShare.Tour as Tour exposing (Tour)
import UnisonShare.UnisonPlan as UnisonPlan exposing (UnisonPlan)
import UnisonShare.User exposing (UserSummary)
import Url exposing (Url)

Expand All @@ -21,6 +23,8 @@ type alias Account a =
, organizationMemberships : List OrganizationMembership
, isSuperAdmin : Bool
, primaryEmail : String
, plan : UnisonPlan
, hasUnreadNotifications : Bool
}


Expand Down Expand Up @@ -90,22 +94,26 @@ isProjectOwner projectRef account =
decodeSummary : Decode.Decoder AccountSummary
decodeSummary =
let
makeSummary handle name_ avatarUrl completedTours organizationMemberships isSuperAdmin primaryEmail =
makeSummary handle name_ avatarUrl completedTours organizationMemberships isSuperAdmin primaryEmail plan hasUnreadNotifications =
{ handle = handle
, name = name_
, avatarUrl = avatarUrl
, pronouns = Nothing
, completedTours = Maybe.withDefault [] completedTours
, organizationMemberships = organizationMemberships
, isSuperAdmin = Maybe.withDefault False isSuperAdmin
, isSuperAdmin = isSuperAdmin
, primaryEmail = primaryEmail
, plan = plan
, hasUnreadNotifications = hasUnreadNotifications
}
in
Decode.map7 makeSummary
(field "handle" UserHandle.decodeUnprefixed)
(maybe (field "name" string))
(maybe (field "avatarUrl" url))
(maybe (field "completedTours" (Decode.list Tour.decode)))
(field "organizationMemberships" (Decode.list (Decode.map OrganizationMembership UserHandle.decodeUnprefixed)))
(maybe (field "isSuperadmin" Decode.bool))
(field "primaryEmail" string)
Decode.succeed makeSummary
|> required "handle" UserHandle.decodeUnprefixed
|> optional "name" (Decode.map Just string) Nothing
|> optional "avatarUrl" (Decode.map Just url) Nothing
|> optional "completedTours" (Decode.map Just (Decode.list Tour.decode)) Nothing
|> required "organizationMemberships" (Decode.list (Decode.map OrganizationMembership UserHandle.decodeUnprefixed))
|> optional "isSuperadmin" Decode.bool False
|> required "primaryEmail" string
|> required "planTier" UnisonPlan.decode
|> required "hasUnreadNotifications" Decode.bool
5 changes: 4 additions & 1 deletion src/UnisonShare/Project.elm
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type alias ProjectDetails =
, permissions : List ProjectPermission
, createdAt : DateTime
, updatedAt : DateTime
, isPremiumProject : Bool
}


Expand Down Expand Up @@ -216,7 +217,7 @@ decodeIsFaved =
decodeDetails : Decode.Decoder ProjectDetails
decodeDetails =
let
makeProjectDetails handle_ slug_ summary tags visibility numFavs numActiveContributions numOpenTickets releaseDownloads isFaved_ latestVersion defaultBranch permissions createdAt updatedAt =
makeProjectDetails handle_ slug_ summary tags visibility numFavs numActiveContributions numOpenTickets releaseDownloads isFaved_ latestVersion defaultBranch permissions createdAt updatedAt isPremiumProject =
let
ref_ =
ProjectRef.projectRef handle_ slug_
Expand All @@ -235,6 +236,7 @@ decodeDetails =
, permissions = permissions
, createdAt = createdAt
, updatedAt = updatedAt
, isPremiumProject = isPremiumProject
}
in
Decode.succeed makeProjectDetails
Expand All @@ -253,6 +255,7 @@ decodeDetails =
|> required "permissions" ProjectPermission.decodeList
|> required "createdAt" DateTime.decode
|> required "updatedAt" DateTime.decode
|> optional "isPremiumProject" Decode.bool False


decode : Decode.Decoder (Project {})
Expand Down
43 changes: 43 additions & 0 deletions src/UnisonShare/UnisonPlan.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
module UnisonShare.UnisonPlan exposing (UnisonPlan(..), decode, fromString, toString)

import Json.Decode as Decode


type UnisonPlan
= Free
| Starter
| Pro


fromString : String -> UnisonPlan
fromString s =
case s of
"Free" ->
Free

"Starter" ->
Starter

"Pro" ->
Pro

_ ->
Free


toString : UnisonPlan -> String
toString p =
case p of
Free ->
"Free"

Starter ->
"Starter"

Pro ->
"Pro"


decode : Decode.Decoder UnisonPlan
decode =
Decode.map fromString Decode.string
1 change: 1 addition & 0 deletions tests/UnisonShare/ProjectTests.elm
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,5 @@ projectDetails isFaved numFavs =
, permissions = []
, createdAt = DateTime.fromPosix (Time.millisToPosix 1)
, updatedAt = DateTime.fromPosix (Time.millisToPosix 1)
, isPremiumProject = False
}
3 changes: 3 additions & 0 deletions tests/e2e/TestHelpers/Data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ function account(handle: string) {
isSuperadmin: false,
organizationMemberships: [],
primaryEmail: faker.internet.email(),
hasUnreadNotifications: false,
planTier: "Free",
};
}

Expand Down Expand Up @@ -120,6 +122,7 @@ function project(ref?: string) {
tags: [],
updatedAt: faker.date.past(),
visibility: "public",
isPremiumProject: false,
};
}

Expand Down
Loading