Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/cn-develop' into cn-uat
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Nov 9, 2023
2 parents 1405799 + 413b136 commit 6eb8265
Show file tree
Hide file tree
Showing 12 changed files with 262 additions and 95 deletions.
166 changes: 83 additions & 83 deletions client/package-lock.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion server/cp/mgmt_api/companies.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
from bson.objectid import ObjectId
from flask import request, current_app as app
from cp.mgmt_api.utils import validate_product_refs

import newsroom
import superdesk
from newsroom.companies import CompaniesResource, CompaniesService
from newsroom.companies.views import get_errors_company
from newsroom.products.products import ProductsResource
from newsroom.products.views import get_product_ref
from newsroom.utils import find_one
import superdesk
from superdesk.errors import SuperdeskApiError


Expand Down Expand Up @@ -42,13 +43,17 @@ def on_create(self, docs):
raise SuperdeskApiError.badRequestError(
message=message, payload=message
)
if doc.get("products"):
validate_product_refs(doc["products"])

def on_created(self, docs):
super().on_created(docs)
for doc in docs:
app.cache.set(str(doc["_id"]), doc)

def on_update(self, updates, original):
if updates.get("products"):
validate_product_refs(updates["products"])
super().on_update(updates, original)
app.cache.delete(str(original["_id"]))

Expand Down
16 changes: 12 additions & 4 deletions server/cp/mgmt_api/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
import superdesk

from bson.objectid import ObjectId
from flask import current_app as app
from newsroom.users import UsersResource, UsersService
from superdesk.errors import SuperdeskApiError
from flask import current_app as app

from cp.mgmt_api.utils import validate_product_refs


class CPUsersResource(newsroom.Resource):
Expand All @@ -20,6 +22,10 @@ def init_app(app):


class CPUsersService(UsersService):
def check_permissions(self, doc, updates=None):
"""Avoid testing if user has permissions."""
pass

def on_create(self, docs):
super().on_create(docs)
for doc in docs:
Expand All @@ -32,7 +38,9 @@ def on_create(self, docs):
raise SuperdeskApiError.badRequestError(message=message, payload=message)
if doc.get('company'):
doc['company'] = ObjectId(doc.get('company'))
if doc.get("products"):
validate_product_refs(doc["products"])

def check_permissions(self, doc, updates=None):
"""Avoid testing if user has permissions."""
pass
def on_update(self, updates, original):
if updates.get("products"):
validate_product_refs(updates["products"])
14 changes: 14 additions & 0 deletions server/cp/mgmt_api/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import superdesk


def validate_product_refs(products):
products_service = superdesk.get_resource_service("products")
for product_spec in products:
product = products_service.find_one(req=None, _id=product_spec["_id"])
assert product is not None and product["product_type"] == product_spec.get(
"section"
), (
f"invalid product type for product {product_spec['_id']}, should be {product['product_type']}"
if product
else f"unknown product {product_spec['_id']}"
)
3 changes: 2 additions & 1 deletion server/data/ui_config.json
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,14 @@
},
{
"_id": "agenda",
"init_version": 7,
"init_version": 8,
"multi_select_topics": false,
"open_coverage_content_in_same_page": true,
"enable_global_topics": true,
"subnav": {
"filters": [
"item_type",
"location",
"coverage_type",
"coverage_status"
]
Expand Down
60 changes: 59 additions & 1 deletion server/features/mgmt_api_companies.feature
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,62 @@ Feature: Management API - Companies
]
}
"""


Scenario: Validate company products section
Given "products"
"""
[
{"name": "test", "query": "test", "product_type": "agenda"}
]
"""

When we post to "/companies"
"""
{
"name": "zzz company",
"contact_name": "zzz company",
"contact_email": "[email protected]",
"phone": "99999999",
"products": [
{"_id": "#products._id#", "section": "wire"}
]
}
"""
Then we get error 400
"""
{"code": 400, "message": "invalid product type for product #products._id#, should be agenda"}
"""

When we post to "/companies"
"""
{
"name": "zzz company",
"contact_name": "zzz company",
"contact_email": "[email protected]",
"phone": "99999999",
"products": [
{"_id": "#products._id#", "section": "agenda"}
]
}
"""
Then we get response code 201

When we patch "/companies/#companies._id#"
"""
{
"products": [
{"_id": "#products._id#", "section": "wire"}
]
}
"""
Then we get error 400

When we patch "/companies/#companies._id#"
"""
{
"products": [
{"_id": "#products._id#", "section": "agenda"}
]
}
"""
Then we get response code 200
6 changes: 3 additions & 3 deletions server/features/mgmt_api_products.feature
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Feature: Management API - Products
"name": "A fishy Product",
"description": "a product for those interested in fish",
"query": "fish",
"product_type": "news_api"
"product_type": "agenda"
}]
"""
Then we get response code 201
Expand Down Expand Up @@ -52,7 +52,7 @@ Feature: Management API - Products
"name": "A fishy Product",
"description": "new description",
"query": "fish",
"product_type": "news_api",
"product_type": "agenda",
"seats": 5
}
]}
Expand All @@ -62,7 +62,7 @@ Feature: Management API - Products
Then we get existing resource
"""
{"products": [
{"_id": "#products._id#", "section": "news_api", "seats": 5}
{"_id": "#products._id#", "section": "agenda", "seats": 5}
]}
"""

Expand Down
71 changes: 71 additions & 0 deletions server/features/mgmt_api_users.feature
Original file line number Diff line number Diff line change
Expand Up @@ -110,3 +110,74 @@ Feature: Management API - Users
"""
When we delete latest
Then we get ok response

Scenario: Validate product type
Scenario: Create a user
Given empty "users"
And "products"
"""
[
{"name": "test", "query": "test", "product_type": "agenda"}
]
"""
And "companies"
"""
[{"name": "zzz company"}]
"""

When we post to "/users"
"""
{
"first_name": "John",
"last_name": "Cena",
"email": "[email protected]",
"company": "#companies._id#",
"sections": {
"agenda": true
},
"products": [
{"_id": "#products._id#", "section": "wire"}
]
}
"""
Then we get error 400
"""
{"code": 400, "message": "invalid product type for product #products._id#, should be agenda"}
"""

When we post to "/users"
"""
{
"first_name": "John",
"last_name": "Cena",
"email": "[email protected]",
"company": "#companies._id#",
"sections": {
"agenda": true
},
"products": [
{"section": "agenda", "_id": "#products._id#"}
]
}
"""
Then we get response code 201

When we patch "/users/#users._id#"
"""
{
"products": [
{"section": "wire", "_id": "#products._id#"}
]
}
"""
Then we get error 400

When we patch "/users/#users._id#"
"""
{
"products": [
{"section": "agenda", "_id": "#products._id#"}
]
}
"""
Then we get response code 200
4 changes: 4 additions & 0 deletions server/theme/login.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ <h5 class="mb-0">{{ gettext("Login") }}</h5>
{% endif %}

<div class="card-footer bg-white border-0 small">
{% if get_locale() == "fr_CA" %}
<a href="https://www.thecanadianpress.com/comment-vous-aider/sinscrire-a-nouvellespro/?lang=fr" class="nh-button nh-button--secondary w-100 mb-4 mt-2">{{ gettext("Sign up") }}</a>
{% else %}
<a href="https://www.thecanadianpress.com/contact/pr-signup" class="nh-button nh-button--secondary w-100 mb-4 mt-2">{{ gettext("Sign up") }}</a>
{% endif %}
<p>
{{ gettext('Forgot your password?') }}
<a href="mailto:[email protected]?subject={{ gettext('Please reset my password for NewsPro') }}">{{ gettext('Contact Us') }}</a>
Expand Down
8 changes: 7 additions & 1 deletion server/theme/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ components:

ProductType:
type: string
default: 'wire'
example: wire
enum:
- wire
- agenda
Expand Down Expand Up @@ -790,6 +790,9 @@ components:
$ref: '#/components/schemas/ProductType'
_id:
$ref: '#/components/schemas/ObjectId'
required:
- _id
- section

required:
- first_name
Expand Down Expand Up @@ -865,6 +868,9 @@ components:
seats:
type: number
example: 5
required:
- _id
- section

required:
- name
Expand Down
Binary file modified server/translations/fr_CA/LC_MESSAGES/messages.mo
Binary file not shown.
2 changes: 1 addition & 1 deletion server/translations/fr_CA/LC_MESSAGES/messages.po
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ msgstr "Réinitialiser le mot de passe"

#: theme/cp_reset_password.html:24
msgid "Send Password Reset Email"
msgstr "Envoyer un courriel de réinitialisation de mot de passe"
msgstr "Envoyer un courriel de réinitialisation"

#: theme/cp_reset_password_confirmation.html:18
msgid "An email was sent to your inbox. Please follow the instructions there."
Expand Down

0 comments on commit 6eb8265

Please sign in to comment.