description: None,
category_id: 1,
creator_id: inserted_user.id,
- removed: false,
+ removed: None,
updated: None
};
url: None,
body: None,
community_id: inserted_community.id,
- removed: false,
- locked: false,
+ removed: None,
+ locked: None,
updated: None
};
description: None,
category_id: 1,
creator_id: inserted_user.id,
- removed: false,
+ removed: None,
updated: None
};
url: None,
body: None,
community_id: inserted_community.id,
- removed: false,
- locked: false,
+ removed: None,
+ locked: None,
updated: None
};
pub description: Option<String>,
pub category_id: i32,
pub creator_id: i32,
- pub removed: bool,
+ pub removed: Option<bool>,
pub updated: Option<chrono::NaiveDateTime>
}
title: "nada".to_owned(),
description: None,
category_id: 1,
- removed: false,
+ removed: None,
updated: None,
};
description: None,
category_id: 1,
creator_id: inserted_user.id,
- removed: false,
+ removed: None,
updated: None
};
body: None,
creator_id: inserted_user.id,
community_id: inserted_community.id,
- removed: false,
- locked: false,
+ removed: None,
+ locked: None,
updated: None
};
pub body: Option<String>,
pub creator_id: i32,
pub community_id: i32,
- pub removed: bool,
- pub locked: bool,
+ pub removed: Option<bool>,
+ pub locked: Option<bool>,
pub updated: Option<chrono::NaiveDateTime>
}
description: None,
category_id: 1,
creator_id: inserted_user.id,
- removed: false,
+ removed: None,
updated: None
};
body: None,
creator_id: inserted_user.id,
community_id: inserted_community.id,
- removed: false,
- locked: false,
+ removed: None,
+ locked: None,
updated: None
};
description: None,
creator_id: inserted_user.id,
category_id: 1,
- removed: false,
+ removed: None,
updated: None
};
body: None,
creator_id: inserted_user.id,
community_id: inserted_community.id,
- removed: false,
- locked: false,
+ removed: None,
+ locked: None,
updated: None
};
name: String,
url: Option<String>,
body: Option<String>,
- removed: bool,
- locked: bool,
+ removed: Option<bool>,
+ locked: Option<bool>,
reason: Option<String>,
auth: String
}
title: String,
description: Option<String>,
category_id: i32,
- removed: bool,
+ removed: Option<bool>,
reason: Option<String>,
expires: Option<i64>,
auth: String
}
// When you create a community, make sure the user becomes a moderator and a follower
-
let community_form = CommunityForm {
name: self.name.to_owned(),
title: self.title.to_owned(),
description: self.description.to_owned(),
category_id: self.category_id,
creator_id: user_id,
- removed: false,
+ removed: None,
updated: None,
};
body: self.body.to_owned(),
community_id: self.community_id,
creator_id: user_id,
- removed: false,
- locked: false,
+ removed: None,
+ locked: None,
updated: None
};
let user_id = claims.id;
- // Verify its the creator or a mod
- let mut editors: Vec<i32> = CommunityModeratorView::for_community(&conn, self.community_id)
+ // Verify its the creator or a mod or admin
+ let mut editors: Vec<i32> = vec![self.creator_id];
+ editors.append(
+ &mut CommunityModeratorView::for_community(&conn, self.community_id)
.unwrap()
.into_iter()
.map(|m| m.user_id)
- .collect();
- editors.push(self.creator_id);
+ .collect()
+ );
+ editors.append(
+ &mut UserView::admins(&conn)
+ .unwrap()
+ .into_iter()
+ .map(|a| a.id)
+ .collect()
+ );
if !editors.contains(&user_id) {
- return self.error("Not allowed to edit comment.");
+ return self.error("Not allowed to edit post.");
}
// Check for a community ban
};
// Mod tables
- if self.removed {
+ if let Some(removed) = self.removed.to_owned() {
let form = ModRemovePostForm {
mod_user_id: user_id,
post_id: self.edit_id,
- removed: Some(self.removed),
+ removed: Some(removed),
reason: self.reason.to_owned(),
};
ModRemovePost::create(&conn, &form).unwrap();
}
- if self.locked {
+ if let Some(locked) = self.locked.to_owned() {
let form = ModLockPostForm {
mod_user_id: user_id,
post_id: self.edit_id,
- locked: Some(self.locked),
+ locked: Some(locked),
};
ModLockPost::create(&conn, &form).unwrap();
}
};
// Mod tables
- if self.removed {
+ if let Some(removed) = self.removed.to_owned() {
let expires = match self.expires {
Some(time) => Some(naive_from_unix(time)),
None => None
let form = ModRemoveCommunityForm {
mod_user_id: user_id,
community_id: self.edit_id,
- removed: Some(self.removed),
+ removed: Some(removed),
reason: self.reason.to_owned(),
expires: expires
};
}
get isMod(): boolean {
- return isMod(this.props.moderators.map(m => m.user_id), this.props.node.comment.creator_id);
+ return this.props.moderators && isMod(this.props.moderators.map(m => m.user_id), this.props.node.comment.creator_id);
}
get isAdmin(): boolean {
- return isMod(this.props.admins.map(a => a.id), this.props.node.comment.creator_id);
+ return this.props.admins && isMod(this.props.admins.map(a => a.id), this.props.node.comment.creator_id);
}
get canAdmin(): boolean {
- return canMod(UserService.Instance.user, this.props.admins.map(a => a.id), this.props.node.comment.creator_id);
+ return this.props.admins && canMod(UserService.Instance.user, this.props.admins.map(a => a.id), this.props.node.comment.creator_id);
}
handleReplyClick(i: CommentNode) {
creator_id: i.props.node.comment.creator_id,
post_id: i.props.node.comment.post_id,
parent_id: i.props.node.comment.parent_id,
- removed: i.props.node.comment.removed,
auth: null
};
WebSocketService.Instance.editComment(deleteForm);
import { Component, linkEvent } from 'inferno';
import { Link } from 'inferno-router';
import { WebSocketService, UserService } from '../services';
-import { Post, CreatePostLikeForm, PostForm as PostFormI, SavePostForm } from '../interfaces';
+import { Post, CreatePostLikeForm, PostForm as PostFormI, SavePostForm, CommunityUser, UserView } from '../interfaces';
import { MomentTime } from './moment-time';
import { PostForm } from './post-form';
-import { mdToHtml } from '../utils';
+import { mdToHtml, canMod, isMod } from '../utils';
interface PostListingState {
showEdit: boolean;
showCommunity?: boolean;
showBody?: boolean;
viewOnly?: boolean;
+ moderators?: Array<CommunityUser>;
+ admins?: Array<UserView>;
}
export class PostListing extends Component<PostListingProps, PostListingState> {
<li className="list-inline-item">
<span>by </span>
<Link className="text-info" to={`/user/${post.creator_id}`}>{post.creator_name}</Link>
+ {this.isMod &&
+ <span className="mx-1 badge badge-secondary">mod</span>
+ }
+ {this.isAdmin &&
+ <span className="mx-1 badge badge-secondary">admin</span>
+ }
{this.props.showCommunity &&
<span>
<span> to </span>
</li>
</>
}
- {this.props.post.am_mod &&
+ {this.canMod &&
<span>
<li className="list-inline-item">
{!this.props.post.removed ?
return UserService.Instance.user && this.props.post.creator_id == UserService.Instance.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, adminsThenMods, this.props.post.creator_id);
+
+ } else return false;
+ }
+
+ get isMod(): boolean {
+ return this.props.moderators && isMod(this.props.moderators.map(m => m.user_id), this.props.post.creator_id);
+ }
+
+ get isAdmin(): boolean {
+ return this.props.admins && isMod(this.props.admins.map(a => a.id), this.props.post.creator_id);
+ }
+
+ get canAdmin(): boolean {
+ return this.props.admins && canMod(UserService.Instance.user, this.props.admins.map(a => a.id), this.props.post.creator_id);
+ }
+
handlePostLike(i: PostListing) {
let form: CreatePostLikeForm = {
url: '',
edit_id: i.props.post.id,
creator_id: i.props.post.creator_id,
- removed: !i.props.post.removed,
- locked: !i.props.post.locked,
auth: null
};
WebSocketService.Instance.editPost(deleteForm);
edit_id: i.props.post.id,
creator_id: i.props.post.creator_id,
removed: !i.props.post.removed,
- locked: !i.props.post.locked,
reason: i.state.removeReason,
auth: null,
};
community_id: i.props.post.community_id,
edit_id: i.props.post.id,
creator_id: i.props.post.creator_id,
- removed: !i.props.post.removed,
locked: !i.props.post.locked,
auth: null,
};
<h5><svg class="icon icon-spinner spin"><use xlinkHref="#icon-spinner"></use></svg></h5> :
<div class="row">
<div class="col-12 col-md-8 col-lg-7 mb-3">
- <PostListing post={this.state.post} showBody showCommunity editable />
+ <PostListing
+ post={this.state.post}
+ showBody
+ showCommunity
+ editable
+ moderators={this.state.moderators}
+ admins={this.state.admins}
+ />
<div className="mb-2" />
<CommentForm postId={this.state.post.id} disabled={this.state.post.locked} />
{this.sortRadios()}
updated?: number;
edit_id?: number;
creator_id: number;
- removed: boolean;
- locked: boolean;
+ removed?: boolean;
+ locked?: boolean;
reason?: string;
auth: string;
}
parent_id?: number;
edit_id?: number;
creator_id: number;
- removed: boolean;
+ removed?: boolean;
reason?: string;
auth: string;
}