From a58fc792cb9cc38eac5cf01560e91c0bec48e9c1 Mon Sep 17 00:00:00 2001 From: Brandon Zhang Date: Thu, 9 Jul 2020 17:47:18 -0400 Subject: [PATCH 1/2] Added org and tag routes --- backend/conduit/articles/models.py | 13 +++++++++++-- backend/conduit/organizations/views.py | 23 ++++++++++++++++++++--- backend/conduit/tags/views.py | 24 +++++++++++++++++++++++- 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/backend/conduit/articles/models.py b/backend/conduit/articles/models.py index 9b668dc..a281c75 100644 --- a/backend/conduit/articles/models.py +++ b/backend/conduit/articles/models.py @@ -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) diff --git a/backend/conduit/organizations/views.py b/backend/conduit/organizations/views.py index e84c5c4..63866fb 100644 --- a/backend/conduit/organizations/views.py +++ b/backend/conduit/organizations/views.py @@ -164,11 +164,10 @@ def submit_article_for_review(org_slug, slug): return article - @blueprint.route('/api/organizations//articles/', 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() @@ -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 + +@blueprint.route('/api/organizations//articles/', + methods=('PUT',)) +@jwt_required +def add_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() + 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 \ No newline at end of file diff --git a/backend/conduit/tags/views.py b/backend/conduit/tags/views.py index 10d952e..a232c75 100644 --- a/backend/conduit/tags/views.py +++ b/backend/conduit/tags/views.py @@ -134,7 +134,7 @@ def invite_moderator(slug, username): @blueprint.route('/api/tags//articles/', 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: @@ -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//articles/', methods=('DELETE',)) +@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 + #Route to return an article filtered by tag names @blueprint.route('/api/user/tags/articles', methods=('GET',)) @jwt_optional From 3ce66971c76e038edafb95c7810734d7153ae1cb Mon Sep 17 00:00:00 2001 From: Brandon Zhang Date: Tue, 14 Jul 2020 12:15:22 -0400 Subject: [PATCH 2/2] Edited some styling changes --- backend/conduit/organizations/views.py | 4 +++- backend/conduit/tags/views.py | 2 ++ lib/utils/constant.ts | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/backend/conduit/organizations/views.py b/backend/conduit/organizations/views.py index 63866fb..a0624e3 100644 --- a/backend/conduit/organizations/views.py +++ b/backend/conduit/organizations/views.py @@ -185,9 +185,11 @@ def remove_article(slug, org_slug, **kwargs): return '', 200 + @blueprint.route('/api/organizations//articles/', methods=('PUT',)) @jwt_required +@marshal_with(article_schema) def add_article(slug, org_slug, **kwargs): profile = current_user.profile organization = Organization.query.filter_by(slug=org_slug).first() @@ -201,4 +203,4 @@ def add_article(slug, org_slug, **kwargs): article.add_organization(organization) article.save() - return '', 200 \ No newline at end of file + return article \ No newline at end of file diff --git a/backend/conduit/tags/views.py b/backend/conduit/tags/views.py index a232c75..a164c32 100644 --- a/backend/conduit/tags/views.py +++ b/backend/conduit/tags/views.py @@ -153,6 +153,7 @@ def add_article(slug, articleSlug): article.save() return article + @blueprint.route('/api/tags//articles/', methods=('DELETE',)) @jwt_required @marshal_with(article_schema) @@ -175,6 +176,7 @@ def remove_article(slug, articleSlug): article.save() return article + #Route to return an article filtered by tag names @blueprint.route('/api/user/tags/articles', methods=('GET',)) @jwt_optional diff --git a/lib/utils/constant.ts b/lib/utils/constant.ts index e24c371..3927144 100644 --- a/lib/utils/constant.ts +++ b/lib/utils/constant.ts @@ -2,10 +2,10 @@ // export const SERVER_BASE_URL = `https://conduit.productionready.io/api`; // Local backend url -// export const SERVER_BASE_URL = `http://127.0.0.1:5000/api`; +export const SERVER_BASE_URL = `http://127.0.0.1:5000/api`; // Staging url -export const SERVER_BASE_URL = `https://bit-devs-staging.herokuapp.com/api`; +// export const SERVER_BASE_URL = `https://bit-devs-staging.herokuapp.com/api`; // Production url. ONLY USE IN PRODUCTION // export const SERVER_BASE_URL = `https://bit-devs.herokuapp.com/api`;