Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/uat' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
petrjasek committed Oct 16, 2023
2 parents c0373c2 + ddab87b commit 838dda2
Show file tree
Hide file tree
Showing 18 changed files with 257 additions and 52 deletions.
8 changes: 7 additions & 1 deletion client/src/login.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,13 @@ auth.onAuthStateChanged((user) => {
return;
}

user.getIdToken(params.get('token_error') === '1').then(sendTokenToServer);
user.getIdToken(params.get('token_error') === '1')
.then(
sendTokenToServer,
() => { // on error we sign out the user and let him login again
signOut(auth);
},
);
}
});

Expand Down
6 changes: 3 additions & 3 deletions client/src/reset-password.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { auth } from './auth'
import { sendPasswordResetEmail } from 'firebase/auth';
import { sendPasswordResetEmail, signOut } from 'firebase/auth';

const form = document.getElementById('reset-password-form');
const url = new URL(window.nextUrl);
const params = new URLSearchParams(url.search);
const sendButton = document.getElementById('send-email');
const emailSentCheckbox = document.getElementById('email_sent_checkbox');

Expand All @@ -16,6 +14,8 @@ form.onsubmit = (event) => {

const data = new FormData(form);
const email = data.get("email");
const url = new URL(window.nextUrl);
const params = new URLSearchParams();

params.append("email", email);
url.search = params;
Expand Down
4 changes: 4 additions & 0 deletions server/cp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

import logging

HEADLINE2 = "headline_extended"
CORRECTION = "correction"

logging.basicConfig(level=logging.INFO)
8 changes: 6 additions & 2 deletions server/cp/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def token():
try:
claims = google.oauth2.id_token.verify_firebase_token(
token,
audience="cp-identity",
audience="cp-identity-dev" if "cp-dev" in flask.request.base_url else "cp-identity",
request=firebase_request_adapter,
)
except ValueError as err:
Expand All @@ -50,7 +50,11 @@ def logout():

@blueprint.route("/cp_reset_password_done")
def reset_password_confirmation():
return flask.render_template("cp_reset_password_confirmation.html")
flask.flash(
gettext("A reset password token has been sent to your email address."),
"success",
)
return flask.redirect(flask.url_for("auth.login"))


@blueprint.route("/cp_reset_password", methods=["GET", "POST"])
Expand Down
26 changes: 18 additions & 8 deletions server/cp/cem.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
import logging
import requests

from typing import Literal
from flask import current_app as app


logger = logging.getLogger(__name__)
session = requests.Session()


def send_notification(_type, user):
def send_notification(_type, user, id_key: Literal["_id", "email"] = "_id"):
url = app.config.get("CEM_URL", "")
apikey = app.config.get("CEM_APIKEY", "")
if not url or not apikey:
return
headers = {"x-api-key": apikey}
payload = {
"type": _type,
"object_id": str(user["_id"]),
"object_id": str(user[id_key]),
"platform": app.config.get("CEM_PLATFORM"),
}
if user.get("company"):
payload["company"] = str(user["company"])
session.patch(
url,
timeout=5,
json=payload,
headers=headers,
)
try:
session.patch(
url,
json=payload,
headers=headers,
timeout=int(app.config.get("CEM_TIMEOUT", 10)),
verify=bool(app.config.get("CEM_VERIFY_TLS", True)),
)
except requests.exceptions.RequestException as err:
logger.error(err)
return
logger.info("Notification sent to CEM")
Empty file added server/cp/commands/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions server/cp/commands/fix_language.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

import time

from superdesk import get_resource_service
from newsroom.commands.manager import manager


@manager.command
def fix_language(resource="items", limit=50, sleep_secs=2):
service = get_resource_service(resource)

source = {"query": {"terms": {"language": ["en-CA", "en-US", "fr-CA"]}}, "size": 100}

for i in range(int(limit)):
items = service.search(source)
if not items.count():
break
for item in items:
updates = {"language": item["language"].split("-")[0]}
service.system_update(item["_id"], updates, item)
print(".", end="", flush=True)
time.sleep(int(sleep_secs))
print(".")
2 changes: 1 addition & 1 deletion server/cp/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def copy_correction_to_body_html(item):

def on_user_created(sender, user, **kwargs):
if user_auth_is_gip(user):
send_notification("new user", user)
send_notification("new", user, id_key="email")


def on_user_updated(sender, user, updates=None, **kwargs):
Expand Down
12 changes: 6 additions & 6 deletions server/data/email_templates.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,20 @@
}
}, {
"_id": "agenda_updated_email",
"init_version": 4,
"init_version": 5,
"subject": {
"default": "{{ agenda.name or agenda.headline or agenda.slugline | safe }} -{{ ' Coverage' if coverage_modified else '' }} updated",
"default": "{{ (agenda.name or agenda.headline or agenda.slugline) | safe }} -{{ ' Coverage' if coverage_modified else '' }} updated",
"translations": {
"fr_ca": "{{ agenda.name or agenda.headline or agenda.slugline | safe }} - {% if coverage_modified %}Couverture mise à jour{% else %}Événement mis à jour{% endif %}"
"fr_ca": "{{ (agenda.name or agenda.headline or agenda.slugline) | safe }} - {% if coverage_modified %}Couverture mise à jour{% else %}Événement mis à jour{% endif %}"
}
}
}, {
"_id": "coverage_request_email",
"init_version": 2,
"init_version": 3,
"subject": {
"default": "Coverage inquiry: {{ item.name or item.slugline | safe }}",
"default": "Coverage inquiry: {{ (item.name or item.slugline) | safe }}",
"translations": {
"fr_ca": "Requête de couverture: {{ item.name or item.slugline | safe }}"
"fr_ca": "Requête de couverture: {{ (item.name or item.slugline) | safe }}"
}
}
}, {
Expand Down
2 changes: 2 additions & 0 deletions server/manage.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from newsroom.commands import * # noqa
from newsroom.commands.manager import manager

from cp.commands.fix_language import fix_language # noqa


if __name__ == "__main__":
manager.run()
1 change: 0 additions & 1 deletion server/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ flask==1.1.2
# flask-script
# flask-webpack
# flask-wtf
# newsroom-core
# raven
# sentry-sdk
# superdesk-core
Expand Down
9 changes: 6 additions & 3 deletions server/settings.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import pathlib
from flask_babel import lazy_gettext
from superdesk.default_settings import strtobool
from newsroom.web.default_settings import (
env,
CLIENT_CONFIG,
Expand Down Expand Up @@ -251,7 +252,7 @@

# saml auth
SAML_LABEL = env("SAML_LABEL", "SSO")
SAML_COMPANY = env("SAML_COMPANY", "CP")
SAML_COMPANY = env("SAML_COMPANY", "The Canadian Press")
SAML_BASE_PATH = pathlib.Path(env("SAML_PATH", SERVER_PATH.joinpath("saml")))
SAML_PATH_MAP = {
"localhost": "localhost",
Expand All @@ -272,8 +273,10 @@
CEM_URL = os.environ.get("CEM_URL", "")
CEM_APIKEY = os.environ.get("CEM_APIKEY", "")
CEM_PLATFORM = os.environ.get("CEM_PLATFORM", "NewsPro")

DEFAULT_ALLOW_COMPANIES_TO_MANAGE_PRODUCTS = True
CEM_VERIFY_TLS = strtobool(os.environ.get("CEM_VERIFY_TLS", "off"))
CEM_TIMEOUT = int(os.environ.get("CEM_TIMEOUT") or 10)

AGENDA_SECTION = lazy_gettext("Calendar")
SAVED_SECTION = lazy_gettext("Bookmarks")

DEFAULT_ALLOW_COMPANIES_TO_MANAGE_PRODUCTS = True
5 changes: 2 additions & 3 deletions server/tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,8 @@ def test_cem_notification_on_user_changes(app):
),
matchers.json_params_matcher(
{
"object_id": str(user["_id"]),
"company": str(company_id),
"type": "new user",
"object_id": str(user["email"]),
"type": "new",
"platform": "Test",
}
),
Expand Down
52 changes: 52 additions & 0 deletions server/theme/copy_agenda_item.fr_ca.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
{%- if item.name %}{{ item.name }}
{% endif %}
{%- if item.dates %}Dates: {{ item.dates.start | datetime_short }} - {{ item.dates.end | datetime_short }}
{% endif %}
{%- if location %}Endroit: {{ location }}
{% endif %}
{%- if item.ednote %}Note de la rédaction: {{ item.ednote }}
{% endif %}
{%- if item.definition_short %}Description: {{ item.definition_short | plain_text }}
{% endif -%}
{%- if item.invitation_details %}Détails de l'invitation: {{ item.invitation_details | plain_text }}
{% endif -%}
{%- if item.registration_details %}Détails de l'inscription: {{ item.registration_details | plain_text }}
{% endif -%}
{%- if contacts | length is gt 0 %}

Contacts
{%- for contact in contacts %}
Nom: {{ contact.name }}
{% if contact.organisation %}Organisation: {{ contact.organisation }}
{% endif %}
{%- if contact.email %}Courriel: {{ contact.email }}
{% endif %}
{%- if contact.phone %}Téléphone: {{ contact.phone }}
{% endif %}
{%- if contact.mobile %}Mobile: {{ contact.mobile }}
{% endif %}
{%- endfor %}
{%- endif %}
{%- if calendars %}

Calendriers: {{ calendars }}
{% endif -%}
{%- if item.planning_items | length is gt 0 -%}
{%- for plan in item.planning_items %}

Élément de couverture
{%- if plan.description_text %}
Description: {{ plan.description_text | plain_text }}
{% endif -%}
{%- for coverage in plan.coverages %}
{% if coverage.planning.g2_content_type %}Type de couverture: {{ coverage.planning.g2_content_type }}
{% endif %}
{%- if coverage.planning.scheduled %}Programmé: {{ coverage.planning.scheduled | datetime_short }}
{% endif %}
{%- if coverage.workflow_status %}Statut: {{ coverage.workflow_status }}
{% endif -%}
{%- if coverage.planning.description_text %}Description: {{ coverage.planning.description_text }}
{% endif -%}
{%- endfor -%}
{%- endfor -%}
{%- endif -%}
8 changes: 8 additions & 0 deletions server/theme/copy_wire_item.fr_ca.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{ item.versioncreated | datetime_short }}
{% if item.slugline %}{{ get_slugline(item, True) }}{% endif %}
{% if item.headline %}{{ item.headline }}{% endif %}
{% if item.byline %}Par: {{ item.byline }}{% endif %}
{% if item.located %}Endroit: {{ item.located }}{% endif %}
{% if item.source %}Source: {{ item.source }}{% endif %}

{% if item.body_text %}{{ item.body_text }}{% elif item.body_html %}{{ item.body_html | plain_text }}{% endif %}
51 changes: 51 additions & 0 deletions server/theme/request_token.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{% extends "layout_wire.html" %}

{% block contentMain %}

<div class="container py-5">
<div class="row">
<div class="col-md-12">
<div class="row">
<div class="col-md-6 mx-auto">
<div class="card bg-white">
<div class="card-header">
<h3 class="mb-0">{{ gettext("Password Reset") }}</h3>
</div>
<div class="card-body">
<form class="form" role="form" id="formToken" method="post">

{{ form.csrf_token }}

{% include "form_alerts.html" %}

<div class="form-group">
<label for="email">{{ form.email.label.text }}</label>
{{ form.email(class="form-control", id="email", required="true") }}
</div>

{% if token_type=='validate' %}
<button type="submit" id="reset-btn" class="btn btn-outline-primary ms-3 float-end">{{ gettext("Validate") }}</button>
{% else %}
<button type="submit" id="reset-btn" class="btn btn-outline-primary ms-3 float-end">{{ gettext("Reset Password") }}</button>
{% endif %}
</form>
</div>
</div>
</div>
</div>
</div>
</div>
{% include "login_messages.html" %}

<script>
{% if request.args.get("url") %}
window.nextUrl = "{{ request.args.get("url") }}";
{% else %}
window.nextUrl = "{{ url_for("auth.login", _external=True) }}";
{% endif %}
window.externalSuccessUrl = "{{ url_for("cp.auth.reset_password_confirmation", _external=True) }}";
</script>

{{ javascript_tag('reset_password') | safe }}
</div>
{% endblock %}
Binary file modified server/translations/fr_CA/LC_MESSAGES/messages.mo
Binary file not shown.
Loading

0 comments on commit 838dda2

Please sign in to comment.