]> Untitled Git - lemmy.git/commitdiff
Add bio federation. (#1052)
authorDessalines <dessalines@users.noreply.github.com>
Tue, 4 Aug 2020 15:06:27 +0000 (11:06 -0400)
committerGitHub <noreply@github.com>
Tue, 4 Aug 2020 15:06:27 +0000 (11:06 -0400)
* Re-organizing federation tests. #746 #1040

* Adding federation support for user bios. Fixes #992

docker/federation/docker-compose.yml
docker/travis/docker-compose.yml
server/src/apub/user.rs
ui/src/api_tests/shared.ts
ui/src/api_tests/user.spec.ts [new file with mode: 0644]

index 4e087d10441017a0c52c94d020d09641fe58e181..a3d0cf4313780077235735365ff89a37e23134d1 100644 (file)
@@ -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:
index 03b3a7ecff23ac1a6855aaf45efc60cce99a79ec..7314e495d09bd5c9f6057412d4094f62db8ae67e 100644 (file)
@@ -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:
index 54e4552fddd5f81f397000b25d79c2a24b8e728f..2922006d56b9c0288474c2abea9824f859066504 100644 (file)
@@ -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()?)
index 08c4ff23e7310866a767ea13f65e3963f2d39efe..3e66837888f16f5d02fd771c27027a38260209f6 100644 (file)
@@ -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<SearchResponse> {
+  // 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<LoginResponse> {
+  let registerForm: RegisterForm = {
+    username,
+    password: 'test',
+    password_verify: 'test',
+    admin: false,
+    show_nsfw: true,
+  };
+
+  let registerRes: Promise<LoginResponse> = 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<LoginResponse> {
+  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<LoginResponse> = 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<GetSiteResponse> {
+  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<PrivateMessagesResponse> {
@@ -650,14 +738,11 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
 
   // 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 (file)
index 0000000..909f9a1
--- /dev/null
@@ -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);
+});