mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 12:21:13 +00:00
Cleaning up canMod
This commit is contained in:
parent
6d10274c8f
commit
4015f92b52
3 changed files with 31 additions and 62 deletions
|
@ -900,29 +900,19 @@ export class CommentNode extends Component<CommentNodeProps, CommentNodeState> {
|
|||
}
|
||||
|
||||
get canMod(): boolean {
|
||||
if (this.props.admins && this.props.moderators) {
|
||||
let adminsThenMods = this.props.admins
|
||||
.map(a => a.person.id)
|
||||
.concat(this.props.moderators.map(m => m.moderator.id));
|
||||
|
||||
return canMod(
|
||||
UserService.Instance.myUserInfo,
|
||||
adminsThenMods,
|
||||
this.props.node.comment_view.creator.id
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return canMod(
|
||||
UserService.Instance.myUserInfo,
|
||||
this.props.node.comment_view.creator.id,
|
||||
this.props.admins,
|
||||
this.props.moderators
|
||||
);
|
||||
}
|
||||
|
||||
get canAdmin(): boolean {
|
||||
return (
|
||||
this.props.admins &&
|
||||
canMod(
|
||||
UserService.Instance.myUserInfo,
|
||||
this.props.admins.map(a => a.person.id),
|
||||
this.props.node.comment_view.creator.id
|
||||
)
|
||||
return canMod(
|
||||
UserService.Instance.myUserInfo,
|
||||
this.props.node.comment_view.creator.id,
|
||||
this.props.admins
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -737,7 +737,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
|||
/>
|
||||
</button>
|
||||
)}
|
||||
{this.canModOnSelf && (
|
||||
{this.canMod(true) && (
|
||||
<>
|
||||
<button
|
||||
class="btn btn-link btn-animate text-muted py-0"
|
||||
|
@ -780,7 +780,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
|||
</>
|
||||
)}
|
||||
{/* Mods can ban from community, and appoint as mods to community */}
|
||||
{(this.canMod || this.canAdmin) &&
|
||||
{(this.canMod() || this.canAdmin) &&
|
||||
(!post_view.post.removed ? (
|
||||
<button
|
||||
class="btn btn-link btn-animate text-muted py-0"
|
||||
|
@ -798,7 +798,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
|||
{i18n.t("restore")}
|
||||
</button>
|
||||
))}
|
||||
{this.canMod && (
|
||||
{this.canMod() && (
|
||||
<>
|
||||
{!this.isMod &&
|
||||
(!post_view.creator_banned_from_community ? (
|
||||
|
@ -1177,47 +1177,21 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
|||
return isAdmin(this.props.admins, this.props.post_view.creator.id);
|
||||
}
|
||||
|
||||
get canMod(): boolean {
|
||||
if (this.props.admins && this.props.moderators) {
|
||||
let adminsThenMods = this.props.admins
|
||||
.map(a => a.person.id)
|
||||
.concat(this.props.moderators.map(m => m.moderator.id));
|
||||
|
||||
return canMod(
|
||||
UserService.Instance.myUserInfo,
|
||||
adminsThenMods,
|
||||
this.props.post_view.creator.id
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
get canModOnSelf(): boolean {
|
||||
if (this.props.admins && this.props.moderators) {
|
||||
let adminsThenMods = this.props.admins
|
||||
.map(a => a.person.id)
|
||||
.concat(this.props.moderators.map(m => m.moderator.id));
|
||||
|
||||
return canMod(
|
||||
UserService.Instance.myUserInfo,
|
||||
adminsThenMods,
|
||||
this.props.post_view.creator.id,
|
||||
true
|
||||
);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
canMod(onSelf = false): boolean {
|
||||
return canMod(
|
||||
UserService.Instance.myUserInfo,
|
||||
this.props.post_view.creator.id,
|
||||
this.props.admins,
|
||||
this.props.moderators,
|
||||
onSelf
|
||||
);
|
||||
}
|
||||
|
||||
get canAdmin(): boolean {
|
||||
return (
|
||||
this.props.admins &&
|
||||
canMod(
|
||||
UserService.Instance.myUserInfo,
|
||||
this.props.admins.map(a => a.person.id),
|
||||
this.props.post_view.creator.id
|
||||
)
|
||||
return canMod(
|
||||
UserService.Instance.myUserInfo,
|
||||
this.props.post_view.creator.id,
|
||||
this.props.admins
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -285,10 +285,15 @@ export function getUnixTime(text: string): number {
|
|||
|
||||
export function canMod(
|
||||
myUserInfo: MyUserInfo,
|
||||
modIds: number[],
|
||||
creator_id: number,
|
||||
admins: PersonViewSafe[] = [],
|
||||
moderators: CommunityModeratorView[] = [],
|
||||
onSelf = false
|
||||
): boolean {
|
||||
let modIds = admins
|
||||
.map(a => a.person.id)
|
||||
.concat(moderators.map(m => m.moderator.id));
|
||||
|
||||
// You can do moderator actions only on the mods added after you.
|
||||
if (myUserInfo) {
|
||||
let yourIndex = modIds.findIndex(
|
||||
|
|
Loading…
Reference in a new issue