mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-22 06:36:14 +00:00
Add bio federation. (#1052)
* Re-organizing federation tests. #746 #1040 * Adding federation support for user bios. Fixes #992
This commit is contained in:
parent
6f05d28c56
commit
e9e1497830
3
docker/federation/docker-compose.yml
vendored
3
docker/federation/docker-compose.yml
vendored
|
@ -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:
|
||||
|
|
3
docker/travis/docker-compose.yml
vendored
3
docker/travis/docker-compose.yml
vendored
|
@ -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:
|
||||
|
|
|
@ -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()?)
|
||||
|
|
101
ui/src/api_tests/shared.ts
vendored
101
ui/src/api_tests/shared.ts
vendored
|
@ -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 {
|
||||
|
|
34
ui/src/api_tests/user.spec.ts
vendored
Normal file
34
ui/src/api_tests/user.spec.ts
vendored
Normal 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);
|
||||
});
|
Loading…
Reference in a new issue