From: Dessalines Date: Tue, 4 Aug 2020 15:06:27 +0000 (-0400) Subject: Add bio federation. (#1052) X-Git-Url: http://these/git/readmes/%7B%60https:/%22https:/hacktivis.me/static/%7BpictrsAvatarThumbnail%28user.avatar%29%7D?a=commitdiff_plain;h=e9e14978305d17001b8978c129b35e6fa98c5ca1;p=lemmy.git Add bio federation. (#1052) * Re-organizing federation tests. #746 #1040 * Adding federation support for user bios. Fixes #992 --- diff --git a/docker/federation/docker-compose.yml b/docker/federation/docker-compose.yml index 4e087d10..a3d0cf43 100644 --- a/docker/federation/docker-compose.yml +++ b/docker/federation/docker-compose.yml @@ -41,6 +41,7 @@ services: - LEMMY_SETUP__SITE_NAME=lemmy-alpha - LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__REGISTER=99999 + - LEMMY_CAPTCHA__ENABLED=false - RUST_BACKTRACE=1 - RUST_LOG=debug depends_on: @@ -70,6 +71,7 @@ services: - LEMMY_SETUP__SITE_NAME=lemmy-beta - LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__REGISTER=99999 + - LEMMY_CAPTCHA__ENABLED=false - RUST_BACKTRACE=1 - RUST_LOG=debug depends_on: @@ -99,6 +101,7 @@ services: - LEMMY_SETUP__SITE_NAME=lemmy-gamma - LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__REGISTER=99999 + - LEMMY_CAPTCHA__ENABLED=false - RUST_BACKTRACE=1 - RUST_LOG=debug depends_on: diff --git a/docker/travis/docker-compose.yml b/docker/travis/docker-compose.yml index 03b3a7ec..7314e495 100644 --- a/docker/travis/docker-compose.yml +++ b/docker/travis/docker-compose.yml @@ -41,6 +41,7 @@ services: - LEMMY_SETUP__SITE_NAME=lemmy-alpha - LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__REGISTER=99999 + - LEMMY_CAPTCHA__ENABLED=false - RUST_BACKTRACE=1 - RUST_LOG=debug depends_on: @@ -70,6 +71,7 @@ services: - LEMMY_SETUP__SITE_NAME=lemmy-beta - LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__REGISTER=99999 + - LEMMY_CAPTCHA__ENABLED=false - RUST_BACKTRACE=1 - RUST_LOG=debug depends_on: @@ -99,6 +101,7 @@ services: - LEMMY_SETUP__SITE_NAME=lemmy-gamma - LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__REGISTER=99999 + - LEMMY_CAPTCHA__ENABLED=false - RUST_BACKTRACE=1 - RUST_LOG=debug depends_on: diff --git a/server/src/apub/user.rs b/server/src/apub/user.rs index 54e4552f..2922006d 100644 --- a/server/src/apub/user.rs +++ b/server/src/apub/user.rs @@ -63,6 +63,10 @@ impl ToApub for User_ { person.set_icon(image.into_any_base()?); } + if let Some(bio) = &self.bio { + person.set_summary(bio.to_owned()); + } + let mut ap_actor = ApActor::new(self.get_inbox_url()?, person); ap_actor .set_outbox(self.get_outbox_url()?) diff --git a/ui/src/api_tests/shared.ts b/ui/src/api_tests/shared.ts index 08c4ff23..3e668378 100644 --- a/ui/src/api_tests/shared.ts +++ b/ui/src/api_tests/shared.ts @@ -16,6 +16,7 @@ import { CommunityResponse, GetFollowedCommunitiesResponse, GetPostResponse, + RegisterForm, CommentForm, DeleteCommentForm, RemoveCommentForm, @@ -31,6 +32,10 @@ import { PrivateMessageResponse, PrivateMessagesResponse, GetUserMentionsResponse, + UserSettingsForm, + SortType, + ListingType, + GetSiteResponse, } from '../interfaces'; export interface API { @@ -278,6 +283,22 @@ export async function searchForBetaCommunity( return searchResponse; } +export async function searchForUser( + api: API, + apShortname: string +): Promise { + // Make sure lemmy-beta/c/main is cached on lemmy_alpha + // Use short-hand search url + let searchUrl = `${apiUrl( + api + )}/search?q=${apShortname}&type_=All&sort=TopAll`; + + let searchResponse: SearchResponse = await fetch(searchUrl, { + method: 'GET', + }).then(d => d.json()); + return searchResponse; +} + export async function followCommunity( api: API, follow: boolean, @@ -614,6 +635,73 @@ export async function deletePrivateMessage( return deleteRes; } +export async function registerUser( + api: API, + username: string = randomString(5) +): Promise { + let registerForm: RegisterForm = { + username, + password: 'test', + password_verify: 'test', + admin: false, + show_nsfw: true, + }; + + let registerRes: Promise = fetch( + `${apiUrl(api)}/user/register`, + { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: wrapper(registerForm), + } + ).then(d => d.json()); + + return registerRes; +} + +export async function saveUserSettingsBio( + api: API, + auth: string +): Promise { + let form: UserSettingsForm = { + show_nsfw: true, + theme: 'darkly', + default_sort_type: SortType.Hot, + default_listing_type: ListingType.All, + lang: 'en', + show_avatars: true, + send_notifications_to_email: false, + bio: 'a changed bio', + auth, + }; + + let res: Promise = fetch( + `${apiUrl(api)}/user/save_user_settings`, + { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + }, + body: wrapper(form), + } + ).then(d => d.json()); + return res; +} + +export async function getSite( + api: API, + auth: string +): Promise { + let siteUrl = `${apiUrl(api)}/site?auth=${auth}`; + + let res: GetSiteResponse = await fetch(siteUrl, { + method: 'GET', + }).then(d => d.json()); + return res; +} + export async function listPrivateMessages( api: API ): Promise { @@ -650,14 +738,11 @@ export async function followBeta(api: API): Promise { // Cache it let search = await searchForBetaCommunity(api); - - // Unfollow first - let follow = await followCommunity( - api, - true, - search.communities.filter(c => c.local == false)[0].id - ); - return follow; + let com = search.communities.filter(c => c.local == false); + if (com[0]) { + let follow = await followCommunity(api, true, com[0].id); + return follow; + } } export function wrapper(form: any): string { diff --git a/ui/src/api_tests/user.spec.ts b/ui/src/api_tests/user.spec.ts new file mode 100644 index 00000000..909f9a11 --- /dev/null +++ b/ui/src/api_tests/user.spec.ts @@ -0,0 +1,34 @@ +import { + alpha, + beta, + registerUser, + searchForUser, + saveUserSettingsBio, + getSite, +} from './shared'; + +let auth: string; +let apShortname: string; + +test('Create user', async () => { + let userRes = await registerUser(alpha); + expect(userRes.jwt).toBeDefined(); + auth = userRes.jwt; + + let site = await getSite(alpha, auth); + expect(site.my_user).toBeDefined(); + apShortname = `@${site.my_user.name}@lemmy-alpha:8540`; +}); + +test('Save user settings, check changed bio from beta', async () => { + let bio = 'a changed bio'; + let userRes = await saveUserSettingsBio(alpha, auth); + expect(userRes.jwt).toBeDefined(); + + let site = await getSite(alpha, auth); + expect(site.my_user.bio).toBe(bio); + + // Make sure beta sees this bio is changed + let search = await searchForUser(beta, apShortname); + expect(search.users[0].bio).toBe(bio); +});