Skip to content

Commit 17896a7

Browse files
authored
Merge pull request #66 from unisoncomputing/cp/more-unified-display-info
More unified display info
2 parents 3f64a6f + b72aab2 commit 17896a7

7 files changed

Lines changed: 58 additions & 62 deletions

File tree

src/Share/Web/Share/Impl.hs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -288,29 +288,27 @@ namespacesByNameEndpoint (AuthN.MaybeAuthedUserID callerUserId) userHandle (from
288288

289289
getUserProfileEndpoint :: Maybe UserId -> UserHandle -> WebApp DescribeUserProfile
290290
getUserProfileEndpoint callerUserId userHandle = do
291-
(UserProfile {user_name, avatar_url, bio, website, location, twitterHandle, pronouns}, kind, permissions) <- PG.runTransactionOrRespondError do
291+
PG.runTransactionOrRespondError do
292292
User {user_id} <- UserQ.userByHandle userHandle `whenNothingM` throwError (EntityMissing (ErrorID "no-user-for-handle") $ "User not found for handle: " <> IDs.toText userHandle)
293-
profile <- UsersQ.userProfileById user_id `whenNothingM` throwError (EntityMissing (ErrorID "no-user-for-handle") $ "User not found for handle: " <> IDs.toText userHandle)
293+
displayInfo <- DisplayInfoQ.unifiedDisplayInfoForUserOf id user_id
294+
UserProfile {bio, website, location, twitterHandle, pronouns} <- UsersQ.userProfileById user_id `whenNothingM` throwError (EntityMissing (ErrorID "no-user-for-handle") $ "User not found for handle: " <> IDs.toText userHandle)
294295
(kind, permissions) <-
295296
OrgQ.orgByUserId user_id >>= \case
296297
Just (Org {orgId}) -> do
297298
permissionsWithinOrg <- AuthZQ.permissionsForOrg callerUserId orgId
298299
pure (OrgKind, permissionsWithinOrg)
299300
Nothing -> pure (UserKind, mempty)
300-
pure (profile, kind, permissions)
301-
pure $
302-
DescribeUserProfile
303-
{ handle = userHandle,
304-
name = user_name,
305-
avatarUrl = avatar_url,
306-
bio = bio,
307-
website = website,
308-
location = location,
309-
twitterHandle = twitterHandle,
310-
pronouns = pronouns,
311-
kind,
312-
permissions
313-
}
301+
pure $
302+
DescribeUserProfile
303+
{ bio = bio,
304+
website = website,
305+
location = location,
306+
twitterHandle = twitterHandle,
307+
pronouns = pronouns,
308+
kind,
309+
permissions,
310+
displayInfo = displayInfo
311+
}
314312

315313
updateUserEndpoint :: UserHandle -> UserId -> UpdateUserRequest -> WebApp DescribeUserProfile
316314
updateUserEndpoint userHandle callerUserId (UpdateUserRequest {name, avatarUrl, bio, website, location, twitterHandle, pronouns}) = do
@@ -480,19 +478,15 @@ searchDefinitionsEndpoint callerUserId (Query query) mayLimit userFilter project
480478

481479
accountInfoEndpoint :: Session -> WebApp UserAccountInfo
482480
accountInfoEndpoint Session {sessionUserId} = do
483-
User {user_name, avatar_url, user_email, handle, user_id} <- PGO.expectUserById sessionUserId
481+
User {user_email, user_id} <- PGO.expectUserById sessionUserId
484482
PG.runTransaction $ do
485483
completedTours <- Q.getCompletedToursForUser user_id
486484
organizationMemberships <- Q.organizationMemberships user_id
487485
isSuperadmin <- AuthZQ.isSuperadmin user_id
488486
displayInfo <- DisplayInfoQ.unifiedDisplayInfoForUserOf id user_id
489487
pure $
490488
UserAccountInfo
491-
{ handle = handle,
492-
name = user_name,
493-
avatarUrl = avatar_url,
494-
userId = user_id,
495-
primaryEmail = user_email,
489+
{ primaryEmail = user_email,
496490
completedTours,
497491
organizationMemberships,
498492
isSuperadmin,

src/Share/Web/Share/Types.hs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,32 +50,28 @@ instance ToJSON UserKind where
5050
OrgKind -> "org"
5151

5252
data DescribeUserProfile = DescribeUserProfile
53-
{ handle :: UserHandle,
54-
name :: Maybe Text,
55-
avatarUrl :: Maybe URIParam,
56-
bio :: Maybe Text,
53+
{ bio :: Maybe Text,
5754
website :: Maybe Text,
5855
location :: Maybe Text,
5956
twitterHandle :: Maybe Text,
6057
pronouns :: Maybe Text,
6158
kind :: UserKind,
62-
permissions :: Set RolePermission
59+
permissions :: Set RolePermission,
60+
displayInfo :: UnifiedDisplayInfo
6361
}
6462
deriving (Show)
6563

6664
instance ToJSON DescribeUserProfile where
67-
toJSON (DescribeUserProfile handle name avatarUrl bio website location twitterHandle pronouns kind permissions) =
65+
toJSON (DescribeUserProfile bio website location twitterHandle pronouns kind permissions displayInfo) =
6866
Aeson.object
69-
[ "handle" .= fromId @UserHandle @Text handle,
70-
"name" .= name,
71-
"avatarUrl" .= avatarUrl,
72-
"bio" .= bio,
67+
[ "bio" .= bio,
7368
"website" .= website,
7469
"location" .= location,
7570
"twitterHandle" .= twitterHandle,
7671
"pronouns" .= pronouns,
7772
"kind" .= kind,
78-
"permissions" Aeson..= permissions
73+
"permissions" Aeson..= permissions,
74+
"displayInfo" .= displayInfo
7975
]
8076

8177
data ReadmeResponse = ReadmeResponse
@@ -133,11 +129,7 @@ instance ToJSON SearchResult where
133129
]
134130

135131
data UserAccountInfo = UserAccountInfo
136-
{ handle :: UserHandle,
137-
name :: Maybe Text,
138-
avatarUrl :: Maybe URIParam,
139-
userId :: UserId,
140-
primaryEmail :: Maybe Email,
132+
{ primaryEmail :: Maybe Email,
141133
-- List of tours which the user has completed.
142134
completedTours :: [TourId],
143135
organizationMemberships :: [UserHandle],
@@ -149,11 +141,7 @@ data UserAccountInfo = UserAccountInfo
149141
instance ToJSON UserAccountInfo where
150142
toJSON UserAccountInfo {..} =
151143
Aeson.object
152-
[ "handle" .= fromId @UserHandle @Text handle,
153-
"name" .= name,
154-
"avatarUrl" .= avatarUrl,
155-
"primaryEmail" .= primaryEmail,
156-
"userId" .= userId,
144+
[ "primaryEmail" .= primaryEmail,
157145
"completedTours" .= completedTours,
158146
"organizationMemberships" .= organizationMemberships,
159147
"isSuperadmin" .= isSuperadmin,

transcripts/share-apis/code-browse/account.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"body": {
3-
"avatarUrl": "https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?f=y&d=retro",
43
"completedTours": [],
54
"displayInfo": {
65
"info": {
@@ -11,14 +10,11 @@
1110
},
1211
"kind": "user"
1312
},
14-
"handle": "transcripts",
1513
"isSuperadmin": false,
16-
"name": "Transcript User",
1714
"organizationMemberships": [
1815
"unison"
1916
],
20-
"primaryEmail": "transcripts@example.com",
21-
"userId": "U-<UUID>"
17+
"primaryEmail": "transcripts@example.com"
2218
},
2319
"status": [
2420
{

transcripts/share-apis/orgs/org-get-profile.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
11
{
22
"body": {
3-
"avatarUrl": "https://example.com/anvil.png",
43
"bio": null,
5-
"handle": "acme",
4+
"displayInfo": {
5+
"info": {
6+
"isCommercial": true,
7+
"orgId": "ORG-<UUID>",
8+
"user": {
9+
"avatarUrl": "https://example.com/anvil.png",
10+
"handle": "acme",
11+
"name": "ACME",
12+
"userId": "U-<UUID>"
13+
}
14+
},
15+
"kind": "org"
16+
},
617
"kind": "org",
718
"location": null,
8-
"name": "ACME",
919
"permissions": [
1020
"project:view",
1121
"project:manage",

transcripts/share-apis/user-creation/new-user-profile.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
22
"body": {
3-
"avatarUrl": "https://avatars.githubusercontent.com/u/0?v=4",
43
"completedTours": [],
54
"displayInfo": {
65
"info": {
@@ -11,12 +10,9 @@
1110
},
1211
"kind": "user"
1312
},
14-
"handle": "localgithubuser",
1513
"isSuperadmin": false,
16-
"name": "Local Github User",
1714
"organizationMemberships": [],
18-
"primaryEmail": "local@example.com",
19-
"userId": "U-<UUID>"
15+
"primaryEmail": "local@example.com"
2016
},
2117
"status": [
2218
{

transcripts/share-apis/users/user-profile-update.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
{
22
"body": {
3-
"avatarUrl": "http://updated.com",
43
"bio": "Updated bio",
5-
"handle": "transcripts",
4+
"displayInfo": {
5+
"info": {
6+
"avatarUrl": "http://updated.com",
7+
"handle": "transcripts",
8+
"name": "Updated Transcripts",
9+
"userId": "U-<UUID>"
10+
},
11+
"kind": "user"
12+
},
613
"kind": "user",
714
"location": "Updated location",
8-
"name": "Updated Transcripts",
915
"permissions": [],
1016
"pronouns": "updated/pronouns",
1117
"twitterHandle": "updated-twitter",

transcripts/share-apis/users/user-profile.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
{
22
"body": {
3-
"avatarUrl": "https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?f=y&d=retro",
43
"bio": "A transcript!",
5-
"handle": "transcripts",
4+
"displayInfo": {
5+
"info": {
6+
"avatarUrl": "https://www.gravatar.com/avatar/205e460b479e2e5b48aec07710c08d50?f=y&d=retro",
7+
"handle": "transcripts",
8+
"name": "Transcript User",
9+
"userId": "U-<UUID>"
10+
},
11+
"kind": "user"
12+
},
613
"kind": "user",
714
"location": "Unison Share",
8-
"name": "Transcript User",
915
"permissions": [],
1016
"pronouns": "they/them",
1117
"twitterHandle": "@unisonTranscript",

0 commit comments

Comments
 (0)