2016-03-18 10:50:40 +09:00
|
|
|
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';
|
2016-03-18 10:50:40 +09:00
|
|
|
|
2016-04-05 18:05:41 +09:00
|
|
|
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;
|
2016-04-05 18:05:41 +09:00
|
|
|
|
|
|
|
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/>
|
2016-04-05 18:05:41 +09:00
|
|
|
</div>
|
|
|
|
)
|
2016-07-19 17:30:59 +09:00
|
|
|
} else if (Users.canDo(currentUser, "posts.new")) {
|
2016-03-17 18:08:03 +09:00
|
|
|
return children;
|
|
|
|
} else {
|
2016-06-10 10:25:38 +09:00
|
|
|
return <p><FormattedMessage id="users.cannot_post"/></p>;
|
2016-02-22 13:23:46 +09:00
|
|
|
}
|
2016-03-17 18:08:03 +09:00
|
|
|
};
|
2016-02-22 13:23:46 +09:00
|
|
|
|
2016-04-05 18:05:41 +09:00
|
|
|
CanCreatePost.contextTypes = {
|
|
|
|
currentUser: React.PropTypes.object
|
|
|
|
};
|
2016-02-22 13:23:46 +09:00
|
|
|
|
2016-05-22 16:42:24 +09:00
|
|
|
CanCreatePost.displayName = "CanCreatePost";
|
|
|
|
|
2016-02-22 13:23:46 +09:00
|
|
|
module.exports = CanCreatePost;
|