def mutate(root, args, context, info): discussion_id = context.matchdict['discussion_id'] discussion = models.Discussion.get(discussion_id) user_id = context.authenticated_userid or Everyone post_id = args.get('post_id') post_id = int(Node.from_global_id(post_id)[1]) post = models.Content.get(post_id) permissions = get_permissions(user_id, discussion_id) allowed = SentimentOfPost.user_can_cls( user_id, CrudPermissions.CREATE, permissions) if not allowed: raise HTTPUnauthorized() sentiment_type = args.get('type') if SentimentTypes.LIKE.name == sentiment_type: sentiment = LikeSentimentOfPost( post=post, discussion=discussion, actor_id=user_id) elif SentimentTypes.DISAGREE.name == sentiment_type: sentiment = DisagreeSentimentOfPost( post=post, discussion=discussion, actor_id=user_id) elif SentimentTypes.DONT_UNDERSTAND.name == sentiment_type: sentiment = DontUnderstandSentimentOfPost( post=post, discussion=discussion, actor_id=user_id) elif SentimentTypes.MORE_INFO.name == sentiment_type: sentiment = MoreInfoSentimentOfPost( post=post, discussion=discussion, actor_id=user_id) sentiment = sentiment.handle_duplication( permissions=permissions, user_id=user_id) sentiment.db.add(sentiment) sentiment.db.flush() return AddSentiment(post=post)
def resolve_total_sentiments(self, args, context, info): discussion_id = context.matchdict['discussion_id'] discussion = models.Discussion.get(discussion_id) query = discussion.db.query(models.SentimentOfPost).filter( models.SentimentOfPost.tombstone_condition(), models.Content.tombstone_condition(), models.Post.id == models.Content.id, models.Post.publication_state.in_(countable_publication_states), *SentimentOfPost.get_discussion_conditions(discussion_id)) return query.count()
def resolve_total_sentiments(self, args, context, info): discussion_id = context.matchdict['discussion_id'] discussion = models.Discussion.get(discussion_id) query = discussion.db.query(models.SentimentOfPost).filter( models.SentimentOfPost.tombstone_condition(), models.Content.tombstone_condition(), models.Post.id == models.Content.id, models.Post.publication_state.in_(countable_publication_states), *SentimentOfPost.get_discussion_conditions(discussion_id) ) return query.count()
def mutate(root, args, context, info): discussion_id = context.matchdict['discussion_id'] user_id = context.authenticated_userid or Everyone post_id = args.get('post_id') post_id = int(Node.from_global_id(post_id)[1]) post = models.Post.get(post_id) permissions = get_permissions(user_id, discussion_id) allowed = SentimentOfPost.user_can_cls(user_id, CrudPermissions.DELETE, permissions) if not allowed or (allowed == IF_OWNED and user_id == Everyone): raise HTTPUnauthorized() post.my_sentiment.tombstone_date = datetime.utcnow() post.db.flush() return DeleteSentiment(post=post)