Skip to content

Commit 063399f

Browse files
committed
Use correct 'role' or 'roles' delineation in JSON
1 parent a7ec3dd commit 063399f

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Share/Web/Authorization/Types.hs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -353,19 +353,33 @@ deriving instance (Ord (f RoleRef), Ord subject) => Ord (RoleAssignment f subjec
353353

354354
deriving instance (Show (f RoleRef), Show subject) => Show (RoleAssignment f subject)
355355

356-
instance (ToJSON user, ToJSON (f RoleRef)) => ToJSON (RoleAssignment f user) where
356+
instance (ToJSON user) => ToJSON (RoleAssignment Identity user) where
357+
toJSON RoleAssignment {..} =
358+
object
359+
[ "subject" Aeson..= subject,
360+
"role" Aeson..= roles
361+
]
362+
363+
instance (ToJSON user) => ToJSON (RoleAssignment Set user) where
357364
toJSON RoleAssignment {..} =
358365
object
359366
[ "subject" Aeson..= subject,
360367
"roles" Aeson..= roles
361368
]
362369

363-
instance (FromJSON user, FromJSON (f RoleRef)) => FromJSON (RoleAssignment f user) where
370+
instance (FromJSON user) => FromJSON (RoleAssignment Identity user) where
371+
parseJSON = Aeson.withObject "RoleAssignment" $ \o -> do
372+
subject <- o Aeson..: "subject"
373+
roles <- o Aeson..: "role"
374+
pure RoleAssignment {..}
375+
376+
instance (FromJSON user) => FromJSON (RoleAssignment Set user) where
364377
parseJSON = Aeson.withObject "RoleAssignment" $ \o -> do
365378
subject <- o Aeson..: "subject"
366379
roles <- o Aeson..: "roles"
367380
pure RoleAssignment {..}
368381

382+
369383
-- | A type for mixing in permissions info on a response for a resource.
370384
newtype PermissionsInfo = PermissionsInfo (Set RolePermission)
371385
deriving (Show)

0 commit comments

Comments
 (0)