Skip to content

Added org and tag routes #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: staging
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 11 additions & 2 deletions backend/conduit/articles/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,17 @@ def remove_tag(self, tag):

def add_organization(self, articles):
self.needsReview = False
self.org_articles.append(articles)
return True
if articles not in self.org_articles:
self.org_articles.append(articles)
return True
return False

def remove_organiztion(self, articles):
self.needsReview = False
if articles in self.org_articles:
self.org_articles.remove(articles)
return True
return False

def add_needReviewTag(self, tag):
self.needReviewTags.append(tag)
Expand Down
23 changes: 20 additions & 3 deletions backend/conduit/organizations/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,10 @@ def submit_article_for_review(org_slug, slug):

return article


@blueprint.route('/api/organizations/<org_slug>/articles/<slug>',
methods=('DELETE',))
@jwt_required
def reviewed_article(slug, org_slug, **kwargs):
def remove_article(slug, org_slug, **kwargs):
profile = current_user.profile
organization = Organization.query.filter_by(slug=org_slug).first()
article = Article.query.filter_by(slug=slug).first()
Expand All @@ -181,7 +180,25 @@ def reviewed_article(slug, org_slug, **kwargs):

organization.pending_articles.remove(article)
organization.save()
article.add_organization(organization)
article.remove_organization(organization)
article.save()

return '', 200

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 lines of space between each function

@blueprint.route('/api/organizations/<org_slug>/articles/<slug>',
methods=('PUT',))
@jwt_required
def add_article(slug, org_slug, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For add article, return the article that was added

profile = current_user.profile
organization = Organization.query.filter_by(slug=org_slug).first()
article = Article.query.filter_by(slug=slug).first()
if not organization.moderator(profile):
raise InvalidUsage.not_admin()
if article not in organization.pending_articles:
raise InvalidUsage.article_not_found()
organization.pending_articles.remove(article)
organization.save()
article.add_organization(organization)
article.save()

return '', 200
24 changes: 23 additions & 1 deletion backend/conduit/tags/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def invite_moderator(slug, username):
@blueprint.route('/api/tags/<slug>/articles/<articleSlug>', methods=('PUT',))
@jwt_required
@marshal_with(article_schema)
def review_article(slug, articleSlug):
def add_article(slug, articleSlug):
profile = current_user.profile
tag = Tags.query.filter_by(slug=slug).first()
if not tag:
Expand All @@ -147,12 +147,34 @@ def review_article(slug, articleSlug):
raise InvalidUsage.article_not_found()
if article.needsReview:
article.remove_needReviewTag(tag)
article.add_tag(tag)
if article.is_allTagReviewed():
article.set_needsReview(False)
article.save()
return article

@blueprint.route('/api/tags/<slug>/articles/<articleSlug>', methods=('DELETE',))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 Lines of space between each route/function

@jwt_required
@marshal_with(article_schema)
def remove_article(slug, articleSlug):
profile = current_user.profile
tag = Tags.query.filter_by(slug=slug).first()
if not tag:
raise InvalidUsage.tag_not_found()
if tag not in profile.moderated_tags:
raise InvalidUsage.not_moderator()

article = Article.query.filter_by(slug=articleSlug).first()
if not article:
raise InvalidUsage.article_not_found()
if article.needsReview:
article.remove_needReviewTag(tag)
article.remove_tag(tag)
if article.is_allTagReviewed():
article.set_needsReview(False)
article.save()
return article

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 Lines of space between each route/function

#Route to return an article filtered by tag names
@blueprint.route('/api/user/tags/articles', methods=('GET',))
@jwt_optional
Expand Down