Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion static/js/containers/ChannelModerationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ class ChannelModerationPage extends React.Component<*, *> {

try {
await dispatch(actions.channels.get(channelName))
await dispatch(actions.channelModerators.get(channelName))
await dispatch(actions.reports.get(channelName))
} catch (_) {} // eslint-disable-line no-empty
}
Expand Down
5 changes: 1 addition & 4 deletions static/js/containers/ChannelPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { actions } from "../actions"
import { setPostData, clearPostError } from "../actions/post"
import { safeBulkGet } from "../lib/maps"
import { getChannelName } from "../lib/util"
import { isModerator } from "../lib/channels"
import { getPostIds } from "../lib/posts"
import { channelURL } from "../lib/url"
import { toggleUpvote } from "../util/api_actions"
Expand Down Expand Up @@ -101,7 +100,6 @@ class ChannelPage extends React.Component<*, void> {

try {
await dispatch(actions.channels.get(channelName))
await dispatch(actions.channelModerators.get(channelName))

this.fetchPostsForChannel()
} catch (_) {} // eslint-disable-line no-empty
Expand Down Expand Up @@ -181,7 +179,6 @@ const mapStateToProps = (state, ownProps) => {
const postsForChannel = state.postsForChannel.data.get(channelName) || {}
const channel = channels.data.get(channelName)
const postIds = getPostIds(postsForChannel)
const channelModerators = state.channelModerators.data.get(channelName) || []
// NOTE: postsForChannel.postIds cannot be `postIds` because that never evals to a Nil value
const loaded = channels.error
? true
Expand All @@ -193,7 +190,7 @@ const mapStateToProps = (state, ownProps) => {
? channels.error && channels.error.errorStatusCode === 403
: false

const userIsModerator = isModerator(channelModerators, SETTINGS.username)
const userIsModerator = channel && channel.user_is_moderator

return {
...postModerationSelector(state, ownProps),
Expand Down
26 changes: 4 additions & 22 deletions static/js/containers/ChannelPage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ import { NotFound, NotAuthorized } from "../components/ErrorPages"
import ChannelPage from "./ChannelPage"
import DropdownMenu from "../components/DropdownMenu"

import {
makeChannel,
makeChannelList,
makeModerators
} from "../factories/channels"
import { makeChannel, makeChannelList } from "../factories/channels"
import { makeChannelPostList, makePost } from "../factories/posts"
import { actions } from "../actions"
import { SET_POST_DATA, CLEAR_POST_ERROR } from "../actions/post"
Expand All @@ -40,19 +36,16 @@ describe("ChannelPage", () => {
channels,
currentChannel,
otherChannel,
postList,
moderators
postList

beforeEach(() => {
channels = makeChannelList(10)
currentChannel = channels[3]
otherChannel = channels[4]
moderators = makeModerators()
postList = makeChannelPostList()
helper = new IntegrationTestHelper()
helper.getChannelStub.returns(Promise.resolve(currentChannel))
helper.getChannelsStub.returns(Promise.resolve(channels))
helper.getChannelModeratorsStub.returns(Promise.resolve(moderators))
helper.getPostsForChannelStub.returns(Promise.resolve({ posts: postList }))
helper.getReportsStub.returns(Promise.resolve(R.times(makeReportRecord, 4)))
helper.getProfileStub.returns(Promise.resolve(""))
Expand All @@ -74,8 +67,6 @@ describe("ChannelPage", () => {
actions.postsForChannel.get.successType,
actions.subscribedChannels.get.requestType,
actions.subscribedChannels.get.successType,
actions.channelModerators.get.requestType,
actions.channelModerators.get.successType,
SET_POST_DATA,
SET_CHANNEL_DATA
])
Expand All @@ -88,10 +79,9 @@ describe("ChannelPage", () => {
})

it("pin post link should just post what's necessary", async () => {
currentChannel.user_is_moderator = true

SETTINGS.username = "username"
helper.getChannelModeratorsStub.returns(
Promise.resolve(makeModerators(SETTINGS.username))
)
const post = makePost()
helper.editPostStub.returns(
Promise.resolve(
Expand All @@ -114,8 +104,6 @@ describe("ChannelPage", () => {
actions.postsForChannel.get.successType,
actions.subscribedChannels.get.requestType,
actions.subscribedChannels.get.successType,
actions.channelModerators.get.requestType,
actions.channelModerators.get.successType,
SET_POST_DATA,
SET_CHANNEL_DATA
])
Expand Down Expand Up @@ -147,8 +135,6 @@ describe("ChannelPage", () => {
actions.channels.get.successType,
actions.postsForChannel.get.requestType,
actions.postsForChannel.get.successType,
actions.channelModerators.get.requestType,
actions.channelModerators.get.successType,
SET_POST_DATA
],
() => {
Expand Down Expand Up @@ -194,8 +180,6 @@ describe("ChannelPage", () => {
actions.channels.get.successType,
actions.postsForChannel.get.requestType,
actions.postsForChannel.get.successType,
actions.channelModerators.get.requestType,
actions.channelModerators.get.successType,
EVICT_POSTS_FOR_CHANNEL
],
() => {
Expand All @@ -220,8 +204,6 @@ describe("ChannelPage", () => {
actions.postsForChannel.get.successType,
actions.subscribedChannels.get.requestType,
actions.subscribedChannels.get.successType,
actions.channelModerators.get.requestType,
actions.channelModerators.get.successType,
SET_POST_DATA,
SET_CHANNEL_DATA,
CLEAR_CHANNEL_ERROR,
Expand Down
3 changes: 1 addition & 2 deletions static/js/containers/CreatePostPage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sinon from "sinon"

import { CreatePostPage as InnerCreatePostPage } from "../containers/CreatePostPage"

import { makeModerators, makeChannelList } from "../factories/channels"
import { makeChannelList } from "../factories/channels"
import { makeCommentsResponse } from "../factories/comments"
import { makePost, makeChannelPostList } from "../factories/posts"
import { newPostURL } from "../lib/url"
Expand Down Expand Up @@ -65,7 +65,6 @@ describe("CreatePostPage", () => {
)
helper.getChannelsStub.returns(Promise.resolve(channels))
helper.getPostStub.returns(Promise.resolve(post))
helper.getChannelModeratorsStub.returns(Promise.resolve(makeModerators()))
helper.getCommentsStub.returns(Promise.resolve(commentsResponse))
helper.getEmbedlyStub.returns(
Promise.resolve({ url: post.url, response: article })
Expand Down
23 changes: 2 additions & 21 deletions static/js/containers/PostPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ import {
getCommentID,
userIsAnonymous
} from "../lib/util"
import { isModerator } from "../lib/channels"
import {
anyErrorExcept404,
anyErrorExcept404or410,
Expand All @@ -76,7 +75,6 @@ import type { Match, Location } from "react-router"
import type { FormsState } from "../flow/formTypes"
import type {
Channel,
ChannelModerators,
CommentInTree,
GenericComment,
MoreCommentsInTree,
Expand All @@ -88,7 +86,6 @@ type PostPageProps = {
dispatch: Dispatch<any>,
post: Post,
channel: Channel,
moderators: ChannelModerators,
isModerator: boolean,
focusedComment: ?CommentInTree,
showRemoveCommentDialog: boolean,
Expand Down Expand Up @@ -174,8 +171,6 @@ class PostPage extends React.Component<PostPageProps, void> {
channel,
location: { search }
} = this.props
const { moderators } = this.props

if (!postID || !channelName) {
// should not happen, this should be guaranteed by react-router
throw Error("Match error")
Expand All @@ -195,10 +190,6 @@ class PostPage extends React.Component<PostPageProps, void> {
if (!channel) {
dispatch(actions.channels.get(channelName))
}

if (!moderators) {
await dispatch(actions.channelModerators.get(channelName))
}
} catch (_) {} // eslint-disable-line no-empty
}

Expand Down Expand Up @@ -473,22 +464,13 @@ class PostPage extends React.Component<PostPageProps, void> {
}

const mapStateToProps = (state, ownProps) => {
const {
posts,
channels,
comments,
forms,
channelModerators,
ui,
embedly
} = state
const { posts, channels, comments, forms, ui, embedly } = state
const postID = getPostID(ownProps)
const channelName = getChannelName(ownProps)
const commentID = getCommentID(ownProps)
const post = posts.data.get(postID)
const channel = channels.data.get(channelName)
const commentsTree = comments.data.get(postID)
const moderators = channelModerators.data.get(channelName)
const embedlyResponse =
post && post.url ? embedly.data.get(post.url) : undefined

Expand Down Expand Up @@ -516,13 +498,12 @@ const mapStateToProps = (state, ownProps) => {
post,
channel,
commentsTree,
moderators,
loaded,
notFound,
notAuthorized,
postDropdownMenuOpen,
postShareMenuOpen,
isModerator: isModerator(moderators, SETTINGS.username),
isModerator: channel && channel.user_is_moderator,
errored:
anyErrorExcept404([posts, channels]) ||
anyErrorExcept404or410([comments]),
Expand Down
13 changes: 2 additions & 11 deletions static/js/containers/PostPage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
makeCommentsResponse,
makeMoreComments
} from "../factories/comments"
import { makeChannel, makeModerators } from "../factories/channels"
import { makeChannel } from "../factories/channels"
import { actions } from "../actions"
import { SET_POST_DATA } from "../actions/post"
import { SET_CHANNEL_DATA } from "../actions/channel"
Expand Down Expand Up @@ -51,7 +51,6 @@ describe("PostPage", function() {
post,
comments,
channel,
moderators,
twitterEmbedStub

this.timeout(5000)
Expand All @@ -61,7 +60,6 @@ describe("PostPage", function() {
const commentsResponse = makeCommentsResponse(post, 3)
comments = createCommentTree(commentsResponse)
channel = makeChannel()
moderators = makeModerators()

helper = new IntegrationTestHelper()
helper.getPostStub.returns(Promise.resolve(post))
Expand All @@ -72,7 +70,6 @@ describe("PostPage", function() {
helper.getCommentStub.returns(
Promise.resolve(R.slice(0, 1, commentsResponse))
)
helper.getChannelModeratorsStub.returns(Promise.resolve(moderators))
helper.getPostsForChannelStub.returns(
Promise.resolve({
posts: makeChannelPostList()
Expand Down Expand Up @@ -101,8 +98,6 @@ describe("PostPage", function() {
actions.subscribedChannels.get.successType,
actions.channels.get.requestType,
actions.channels.get.successType,
actions.channelModerators.get.requestType,
actions.channelModerators.get.successType,
SET_CHANNEL_DATA
]

Expand Down Expand Up @@ -313,8 +308,6 @@ describe("PostPage", function() {
actions.channels.get.requestType,
actions.channels.get.successType,
actions.postsForChannel.get.requestType,
actions.channelModerators.get.requestType,
actions.channelModerators.get.successType,
SET_SNACKBAR_MESSAGE
],
() => {
Expand All @@ -333,9 +326,7 @@ describe("PostPage", function() {

describe("as a moderator user", () => {
beforeEach(() => {
helper.getChannelModeratorsStub.returns(
Promise.resolve(makeModerators(SETTINGS.username))
)
channel.user_is_moderator = true
})

it("should remove the post", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ describe("EditChannelAppearancePage", () => {
helper = new IntegrationTestHelper()
helper.getChannelStub.returns(Promise.resolve(channel))
helper.getChannelsStub.returns(Promise.resolve([channel]))
helper.getChannelModeratorsStub.returns(Promise.resolve([]))
helper.getPostsForChannelStub.returns(
Promise.resolve({
pagination: {},
Expand Down Expand Up @@ -85,8 +84,6 @@ describe("EditChannelAppearancePage", () => {
actions.channels.patch.successType,
actions.channels.get.requestType,
actions.channels.get.successType,
actions.channelModerators.get.requestType,
actions.channelModerators.get.successType,
actions.postsForChannel.get.requestType,
actions.postsForChannel.get.successType,
FORM_END_EDIT
Expand Down
3 changes: 0 additions & 3 deletions static/js/containers/admin/EditChannelBasicPage_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ describe("EditChannelBasicPage", () => {
helper = new IntegrationTestHelper()
helper.getChannelStub.returns(Promise.resolve(channel))
helper.getChannelsStub.returns(Promise.resolve([channel]))
helper.getChannelModeratorsStub.returns(Promise.resolve([]))
helper.getPostsForChannelStub.returns(
Promise.resolve({
pagination: {},
Expand Down Expand Up @@ -90,8 +89,6 @@ describe("EditChannelBasicPage", () => {
actions.channels.patch.successType,
actions.channels.get.requestType,
actions.channels.get.successType,
actions.channelModerators.get.requestType,
actions.channelModerators.get.successType,
actions.postsForChannel.get.requestType,
actions.postsForChannel.get.successType,
FORM_END_EDIT
Expand Down
4 changes: 1 addition & 3 deletions static/js/hoc/withPostModeration.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from "../actions/ui"
import { setFocusedPost, clearFocusedPost } from "../actions/focus"
import { getChannelName } from "../lib/util"
import { isModerator } from "../lib/channels"
import { getSubscribedChannels } from "../lib/redux_selectors"
import { anyErrorExcept404 } from "../util/rest"
import {
Expand Down Expand Up @@ -195,9 +194,8 @@ export const postModerationSelector = (state: Object, ownProps: Object) => {
const { channels, reports, ui, focus, forms } = state
const channelName = getChannelName(ownProps)
const channel = channels.data.get(channelName)
const channelModerators = state.channelModerators.data.get(channelName) || []

const userIsModerator = isModerator(channelModerators, SETTINGS.username)
const userIsModerator = channel && channel.user_is_moderator

const loaded =
channels.error || reports.error ? true : channels.loaded && reports.loaded
Expand Down
11 changes: 1 addition & 10 deletions static/js/lib/channels.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
//@flow
import R from "ramda"

import type {
Channel,
ChannelForm,
ChannelModerators
} from "../flow/discussionTypes"
import type { Channel, ChannelForm } from "../flow/discussionTypes"

export const CHANNEL_TYPE_PUBLIC = "public"
export const CHANNEL_TYPE_RESTRICTED = "restricted"
Expand Down Expand Up @@ -38,11 +34,6 @@ export const editChannelForm = (channel: Channel): ChannelForm =>
channel
)

export const isModerator = (
moderators: ChannelModerators,
username: ?string
): boolean => R.any(R.propEq("moderator_name", username), moderators || [])

export const userCanPost = (channel: Channel) =>
channel.channel_type === CHANNEL_TYPE_PUBLIC ||
channel.user_is_moderator ||
Expand Down
Loading