</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>
{/* 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 ?
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;
}
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 {