Vulcan/packages/nova-base-components/lib/permissions/CanCreatePost.jsx

32 lines
819 B
React
Raw Normal View History

import React, { PropTypes, Component } from 'react';
2016-06-10 10:25:38 +09:00
import { FormattedMessage } from 'react-intl';
2016-06-23 15:00:58 +09:00
import Users from 'meteor/nova:users';
const CanCreatePost = (props, context) => {
const currentUser = context.currentUser;
const children = props.children;
2016-04-19 16:14:41 +09:00
const UsersAccountForm = Telescope.components.UsersAccountForm;
if (!currentUser){
return (
2016-05-22 21:56:17 +09:00
<div className="log-in-message">
2016-06-10 10:25:38 +09:00
<h3><FormattedMessage id="users.please_log_in"/></h3>
2016-04-19 16:14:41 +09:00
<UsersAccountForm/>
</div>
)
2016-07-19 17:30:59 +09:00
} else if (Users.canDo(currentUser, "posts.new")) {
return children;
} else {
2016-06-10 10:25:38 +09:00
return <p><FormattedMessage id="users.cannot_post"/></p>;
}
};
CanCreatePost.contextTypes = {
currentUser: React.PropTypes.object
};
CanCreatePost.displayName = "CanCreatePost";
module.exports = CanCreatePost;