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..a0624e3 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,27 @@ 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 +@marshal_with(article_schema) +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 article \ No newline at end of file diff --git a/backend/conduit/tags/views.py b/backend/conduit/tags/views.py index 10d952e..a164c32 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,36 @@ 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 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`;