Add bio federation. (#1052)

* Re-organizing federation tests. #746 #1040

* Adding federation support for user bios. Fixes #992
This commit is contained in:
Dessalines 2020-08-04 11:06:27 -04:00 committed by GitHub
parent 6f05d28c56
commit e9e1497830
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 137 additions and 8 deletions

View file

@ -41,6 +41,7 @@ services:
- LEMMY_SETUP__SITE_NAME=lemmy-alpha - LEMMY_SETUP__SITE_NAME=lemmy-alpha
- LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999 - LEMMY_RATE_LIMIT__REGISTER=99999
- LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1 - RUST_BACKTRACE=1
- RUST_LOG=debug - RUST_LOG=debug
depends_on: depends_on:
@ -70,6 +71,7 @@ services:
- LEMMY_SETUP__SITE_NAME=lemmy-beta - LEMMY_SETUP__SITE_NAME=lemmy-beta
- LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999 - LEMMY_RATE_LIMIT__REGISTER=99999
- LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1 - RUST_BACKTRACE=1
- RUST_LOG=debug - RUST_LOG=debug
depends_on: depends_on:
@ -99,6 +101,7 @@ services:
- LEMMY_SETUP__SITE_NAME=lemmy-gamma - LEMMY_SETUP__SITE_NAME=lemmy-gamma
- LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999 - LEMMY_RATE_LIMIT__REGISTER=99999
- LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1 - RUST_BACKTRACE=1
- RUST_LOG=debug - RUST_LOG=debug
depends_on: depends_on:

View file

@ -41,6 +41,7 @@ services:
- LEMMY_SETUP__SITE_NAME=lemmy-alpha - LEMMY_SETUP__SITE_NAME=lemmy-alpha
- LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999 - LEMMY_RATE_LIMIT__REGISTER=99999
- LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1 - RUST_BACKTRACE=1
- RUST_LOG=debug - RUST_LOG=debug
depends_on: depends_on:
@ -70,6 +71,7 @@ services:
- LEMMY_SETUP__SITE_NAME=lemmy-beta - LEMMY_SETUP__SITE_NAME=lemmy-beta
- LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999 - LEMMY_RATE_LIMIT__REGISTER=99999
- LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1 - RUST_BACKTRACE=1
- RUST_LOG=debug - RUST_LOG=debug
depends_on: depends_on:
@ -99,6 +101,7 @@ services:
- LEMMY_SETUP__SITE_NAME=lemmy-gamma - LEMMY_SETUP__SITE_NAME=lemmy-gamma
- LEMMY_RATE_LIMIT__POST=99999 - LEMMY_RATE_LIMIT__POST=99999
- LEMMY_RATE_LIMIT__REGISTER=99999 - LEMMY_RATE_LIMIT__REGISTER=99999
- LEMMY_CAPTCHA__ENABLED=false
- RUST_BACKTRACE=1 - RUST_BACKTRACE=1
- RUST_LOG=debug - RUST_LOG=debug
depends_on: depends_on:

View file

@ -63,6 +63,10 @@ impl ToApub for User_ {
person.set_icon(image.into_any_base()?); 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); let mut ap_actor = ApActor::new(self.get_inbox_url()?, person);
ap_actor ap_actor
.set_outbox(self.get_outbox_url()?) .set_outbox(self.get_outbox_url()?)

View file

@ -16,6 +16,7 @@ import {
CommunityResponse, CommunityResponse,
GetFollowedCommunitiesResponse, GetFollowedCommunitiesResponse,
GetPostResponse, GetPostResponse,
RegisterForm,
CommentForm, CommentForm,
DeleteCommentForm, DeleteCommentForm,
RemoveCommentForm, RemoveCommentForm,
@ -31,6 +32,10 @@ import {
PrivateMessageResponse, PrivateMessageResponse,
PrivateMessagesResponse, PrivateMessagesResponse,
GetUserMentionsResponse, GetUserMentionsResponse,
UserSettingsForm,
SortType,
ListingType,
GetSiteResponse,
} from '../interfaces'; } from '../interfaces';
export interface API { export interface API {
@ -278,6 +283,22 @@ export async function searchForBetaCommunity(
return searchResponse; 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( export async function followCommunity(
api: API, api: API,
follow: boolean, follow: boolean,
@ -614,6 +635,73 @@ export async function deletePrivateMessage(
return deleteRes; 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( export async function listPrivateMessages(
api: API api: API
): Promise<PrivateMessagesResponse> { ): Promise<PrivateMessagesResponse> {
@ -650,14 +738,11 @@ export async function followBeta(api: API): Promise<CommunityResponse> {
// Cache it // Cache it
let search = await searchForBetaCommunity(api); let search = await searchForBetaCommunity(api);
let com = search.communities.filter(c => c.local == false);
// Unfollow first if (com[0]) {
let follow = await followCommunity( let follow = await followCommunity(api, true, com[0].id);
api,
true,
search.communities.filter(c => c.local == false)[0].id
);
return follow; return follow;
}
} }
export function wrapper(form: any): string { export function wrapper(form: any): string {

34
ui/src/api_tests/user.spec.ts vendored Normal file
View file

@ -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);
});