mirror of
https://github.com/LemmyNet/lemmy.git
synced 2024-11-30 08:11:20 +00:00
Fix issue with not being able to lock / sticky your own posts.
This commit is contained in:
parent
877d8c7e74
commit
b64fe423b8
2 changed files with 21 additions and 12 deletions
28
ui/src/components/post-listing.tsx
vendored
28
ui/src/components/post-listing.tsx
vendored
|
@ -194,14 +194,8 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
|||
</li>
|
||||
</>
|
||||
}
|
||||
{this.canMod &&
|
||||
{this.canModOnSelf &&
|
||||
<>
|
||||
<li className="list-inline-item">
|
||||
{!post.removed ?
|
||||
<span class="pointer" onClick={linkEvent(this, this.handleModRemoveShow)}><T i18nKey="remove">#</T></span> :
|
||||
<span class="pointer" onClick={linkEvent(this, this.handleModRemoveSubmit)}><T i18nKey="restore">#</T></span>
|
||||
}
|
||||
</li>
|
||||
<li className="list-inline-item">
|
||||
<span class="pointer" onClick={linkEvent(this, this.handleModLock)}>{post.locked ? i18n.t('unlock') : i18n.t('lock')}</span>
|
||||
</li>
|
||||
|
@ -213,6 +207,12 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
|||
{/* Mods can ban from community, and appoint as mods to community */}
|
||||
{this.canMod &&
|
||||
<>
|
||||
<li className="list-inline-item">
|
||||
{!post.removed ?
|
||||
<span class="pointer" onClick={linkEvent(this, this.handleModRemoveShow)}><T i18nKey="remove">#</T></span> :
|
||||
<span class="pointer" onClick={linkEvent(this, this.handleModRemoveSubmit)}><T i18nKey="restore">#</T></span>
|
||||
}
|
||||
</li>
|
||||
{!this.isMod &&
|
||||
<li className="list-inline-item">
|
||||
{!post.banned_from_community ?
|
||||
|
@ -326,14 +326,22 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
|||
return this.props.admins && isMod(this.props.admins.map(a => a.id), this.props.post.creator_id);
|
||||
}
|
||||
|
||||
get adminsThenMods(): Array<number> {
|
||||
return this.props.admins.map(a => a.id)
|
||||
.concat(this.props.moderators.map(m => m.user_id));
|
||||
}
|
||||
|
||||
get canMod(): boolean {
|
||||
|
||||
if (this.props.editable) {
|
||||
let adminsThenMods = this.props.admins.map(a => a.id)
|
||||
.concat(this.props.moderators.map(m => m.user_id));
|
||||
return canMod(UserService.Instance.user, this.adminsThenMods, this.props.post.creator_id);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
return canMod(UserService.Instance.user, adminsThenMods, this.props.post.creator_id);
|
||||
get canModOnSelf(): boolean {
|
||||
|
||||
if (this.props.editable) {
|
||||
return canMod(UserService.Instance.user, this.adminsThenMods, this.props.post.creator_id, true);
|
||||
} else return false;
|
||||
}
|
||||
|
||||
|
|
5
ui/src/utils.ts
vendored
5
ui/src/utils.ts
vendored
|
@ -82,14 +82,15 @@ export function addTypeInfo<T>(arr: Array<T>, name: string): Array<{type_: strin
|
|||
return arr.map(e => {return {type_: name, data: e}});
|
||||
}
|
||||
|
||||
export function canMod(user: User, modIds: Array<number>, creator_id: number): boolean {
|
||||
export function canMod(user: User, modIds: Array<number>, creator_id: number, onSelf: boolean = false): boolean {
|
||||
// You can do moderator actions only on the mods added after you.
|
||||
if (user) {
|
||||
let yourIndex = modIds.findIndex(id => id == user.id);
|
||||
if (yourIndex == -1) {
|
||||
return false;
|
||||
} else {
|
||||
modIds = modIds.slice(0, yourIndex+1); // +1 cause you cant mod yourself
|
||||
// onSelf +1 on mod actions not for yourself, IE ban, remove, etc
|
||||
modIds = modIds.slice(0, yourIndex+(onSelf ? 0 : 1));
|
||||
return !modIds.includes(creator_id);
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue