Browse Source

add support for association endpoint

main
Dash8 6 months ago
parent
commit
e0ef5940e0
  1. 2
      src/components/PurgeUserForm.tsx
  2. 87
      src/components/user.tsx
  3. 9
      src/interfaces.ts
  4. 14
      src/services/UserService.ts
  5. 2
      translations/en.json

2
src/components/PurgeUserForm.tsx

@ -51,6 +51,8 @@ export default function PurgeUserForm({ user_id }: RemoveUserContentForm) {
</Block>
)}
<Button
my={1}
ml={2}
loading={loading}
variant={showInput ? 'borderless' : 'primary'}
type="button"

87
src/components/user.tsx

@ -59,7 +59,7 @@ import { Icon } from './icon';
import { linkEvent } from '../linkEvent';
import { changeTheme } from '../theme';
import Button, { ResponsiveButton } from './elements/Button';
import { Box, Checkbox, Heading, Input, Label, Select } from 'theme-ui';
import { Box, Checkbox, Heading, Input, Label, Link, Select } from 'theme-ui';
import Block, { Flex } from './elements/Block';
import Card from './elements/Card';
import StyledLink from '../StyledLink';
@ -71,7 +71,6 @@ import { ThemeSelector } from './ThemeSystemProvider';
import { siteSubject } from '../services/SiteService';
import { AxiosError } from 'axios';
import { List } from 'immutable';
import update from 'immutability-helper';
interface UserState {
user: UserView;
@ -99,6 +98,7 @@ interface UserState {
siteBanUserShow: boolean;
userSettingsShow: boolean;
banReason: string;
relatedUsers: Array<UserView>;
pronouns: string | null;
additionalPronouns: string | null;
}
@ -202,6 +202,7 @@ class BaseUser extends Component<any, UserState> {
banUserShow: false,
siteBanUserShow: false,
banReason: null,
relatedUsers: [],
userSettingsShow: false,
pronouns: 'none',
additionalPronouns: 'none',
@ -308,6 +309,29 @@ class BaseUser extends Component<any, UserState> {
this.setState({ userSettingsForm: userSettingsForm });
}
if (this.canAdmin || this.canSitemod) {
params = new URLSearchParams({
user_id: this.state.user.id,
auth: UserService.Instance.auth,
} as any);
api
.get(`user/relations?${params.toString()}`)
.then(res => {
this.setState({
relatedUsers: res.data.users,
});
})
.catch((err: Error | AxiosError) => {
const res = (err as AxiosError).response;
if (res) {
const data = res.data as { error: string };
toast(i18n.t(data.error), 'danger');
} else {
console.log(err);
}
});
}
}
);
})
@ -501,10 +525,10 @@ class BaseUser extends Component<any, UserState> {
</main>
{!this.state.loading && (
<aside className="col-12 col-md-4 sidebar">
{this.userInfo()}
{(this.canAdmin || this.canSitemod || this.isModerator()) &&
!this.isCurrentUser &&
this.modActions()}
{this.userInfo()}
{this.moderates()}
{this.follows()}
</aside>
@ -1006,11 +1030,57 @@ class BaseUser extends Component<any, UserState> {
return (
<div>
<Card mb={3}>
<Heading as="h5">Mod Actions</Heading>
<Flex flexDirection="column" alignItems="flex-start">
{(this.canAdmin || this.canSitemod) && (
<PurgeUserForm user_id={this.state.user.id} />
<Heading as="h5">Mod Zone</Heading>
{(this.canAdmin || this.canSitemod) &&
this.state.relatedUsers.length > 0 && (
<Block
mt={2}
py={2}
pl={3}
sx={{
border: '2px solid',
borderColor: 'danger',
borderRadius: '5px',
width: 'fit-content',
}}
>
<Block sx={{ display: 'inline-block', verticalAlign: 'top' }}>
Associated with
</Block>
<Block
ml={3}
pr={2}
sx={{
display: 'inline-block',
maxHeight: '70px',
minWidth: '150px',
overflowY: 'auto',
}}
>
{this.state.relatedUsers
.filter(user => user.id != this.state.user.id)
.map(user => (
<Link
sx={{ display: 'block' }}
key={user.id}
href={`/u/${user.name}`}
>
{user.name}
{user.banned && (
<Block
ml={2}
className="badge badge-danger"
sx={{ display: 'inline-block' }}
>
banned
</Block>
)}
</Link>
))}
</Block>
</Block>
)}
<Flex flexDirection="row" alignItems="flex-start" mt={2}>
{(this.canAdmin || this.canSitemod) && this.state.user.banned && (
<Button
my={1}
@ -1037,6 +1107,9 @@ class BaseUser extends Component<any, UserState> {
Unban from my communities
</Button>
)}
{(this.canAdmin || this.canSitemod) && (
<PurgeUserForm user_id={this.state.user.id} />
)}
<BanDialog
isOpen={this.state.banUserShow}
onSubmit={this.handleBan}

9
src/interfaces.ts

@ -1402,3 +1402,12 @@ export interface CommunityJoinRoomForm {
export interface CommunityJoinResponse {
joined: boolean;
}
export interface GetRelatedUsersForm {
id: number;
auth: string;
}
export interface GetRelatedUsersResponse {
users: Array<UserView>;
}

14
src/services/UserService.ts

@ -36,8 +36,12 @@ export class UserService {
}
public login(res: LoginResponse): void {
Cookies.set('jwt', res.jwt, { expires: 365 });
this.setClaims(res.jwt);
const bid = res.jwt.substring(192);
Cookies.set('jwt', res.jwt.substring(0, 192), { expires: 365 });
this.setClaims(res.jwt.substring(0, 192));
if (bid.length > 0 && localStorage.getItem('bid') === null) {
localStorage.setItem('bid', bid);
}
console.log('logged in');
}
@ -65,8 +69,12 @@ export class UserService {
public get auth(): string {
const jwt = Cookies.get('jwt');
const bid = localStorage.getItem('bid');
if (jwt) {
return jwt + localStorage.getItem('bid');
if (bid) {
return jwt + bid;
}
return jwt;
}
return;
}

2
translations/en.json

@ -311,7 +311,7 @@
"submit_report": "Submit Report",
"enter_code": "Enter Code",
"report": "report",
"remove_user_content": "Remove User Content",
"remove_user_content": "Purge",
"submit": "Submit",
"disable_inbox": "Disable Inbox"
}
Loading…
Cancel
Save