mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-22 20:31: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 {
|
get canMod(): boolean {
|
||||||
if (this.props.admins && this.props.moderators) {
|
return canMod(
|
||||||
let adminsThenMods = this.props.admins
|
UserService.Instance.myUserInfo,
|
||||||
.map(a => a.person.id)
|
this.props.node.comment_view.creator.id,
|
||||||
.concat(this.props.moderators.map(m => m.moderator.id));
|
this.props.admins,
|
||||||
|
this.props.moderators
|
||||||
return canMod(
|
);
|
||||||
UserService.Instance.myUserInfo,
|
|
||||||
adminsThenMods,
|
|
||||||
this.props.node.comment_view.creator.id
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get canAdmin(): boolean {
|
get canAdmin(): boolean {
|
||||||
return (
|
return canMod(
|
||||||
this.props.admins &&
|
UserService.Instance.myUserInfo,
|
||||||
canMod(
|
this.props.node.comment_view.creator.id,
|
||||||
UserService.Instance.myUserInfo,
|
this.props.admins
|
||||||
this.props.admins.map(a => a.person.id),
|
|
||||||
this.props.node.comment_view.creator.id
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -737,7 +737,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
)}
|
)}
|
||||||
{this.canModOnSelf && (
|
{this.canMod(true) && (
|
||||||
<>
|
<>
|
||||||
<button
|
<button
|
||||||
class="btn btn-link btn-animate text-muted py-0"
|
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 */}
|
{/* Mods can ban from community, and appoint as mods to community */}
|
||||||
{(this.canMod || this.canAdmin) &&
|
{(this.canMod() || this.canAdmin) &&
|
||||||
(!post_view.post.removed ? (
|
(!post_view.post.removed ? (
|
||||||
<button
|
<button
|
||||||
class="btn btn-link btn-animate text-muted py-0"
|
class="btn btn-link btn-animate text-muted py-0"
|
||||||
|
@ -798,7 +798,7 @@ export class PostListing extends Component<PostListingProps, PostListingState> {
|
||||||
{i18n.t("restore")}
|
{i18n.t("restore")}
|
||||||
</button>
|
</button>
|
||||||
))}
|
))}
|
||||||
{this.canMod && (
|
{this.canMod() && (
|
||||||
<>
|
<>
|
||||||
{!this.isMod &&
|
{!this.isMod &&
|
||||||
(!post_view.creator_banned_from_community ? (
|
(!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);
|
return isAdmin(this.props.admins, this.props.post_view.creator.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
get canMod(): boolean {
|
canMod(onSelf = false): boolean {
|
||||||
if (this.props.admins && this.props.moderators) {
|
return canMod(
|
||||||
let adminsThenMods = this.props.admins
|
UserService.Instance.myUserInfo,
|
||||||
.map(a => a.person.id)
|
this.props.post_view.creator.id,
|
||||||
.concat(this.props.moderators.map(m => m.moderator.id));
|
this.props.admins,
|
||||||
|
this.props.moderators,
|
||||||
return canMod(
|
onSelf
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get canAdmin(): boolean {
|
get canAdmin(): boolean {
|
||||||
return (
|
return canMod(
|
||||||
this.props.admins &&
|
UserService.Instance.myUserInfo,
|
||||||
canMod(
|
this.props.post_view.creator.id,
|
||||||
UserService.Instance.myUserInfo,
|
this.props.admins
|
||||||
this.props.admins.map(a => a.person.id),
|
|
||||||
this.props.post_view.creator.id
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -285,10 +285,15 @@ export function getUnixTime(text: string): number {
|
||||||
|
|
||||||
export function canMod(
|
export function canMod(
|
||||||
myUserInfo: MyUserInfo,
|
myUserInfo: MyUserInfo,
|
||||||
modIds: number[],
|
|
||||||
creator_id: number,
|
creator_id: number,
|
||||||
|
admins: PersonViewSafe[] = [],
|
||||||
|
moderators: CommunityModeratorView[] = [],
|
||||||
onSelf = false
|
onSelf = false
|
||||||
): boolean {
|
): 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.
|
// You can do moderator actions only on the mods added after you.
|
||||||
if (myUserInfo) {
|
if (myUserInfo) {
|
||||||
let yourIndex = modIds.findIndex(
|
let yourIndex = modIds.findIndex(
|
||||||
|
|
Loading…
Reference in a new issue