Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
devketanpro committed Dec 25, 2024
2 parents d6817f7 + b38227c commit deb8f64
Show file tree
Hide file tree
Showing 28 changed files with 209 additions and 171 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ updates:
directory: "/" # Location of package manifests
schedule:
interval: "weekly"

- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "weekly"
67 changes: 0 additions & 67 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

12 changes: 6 additions & 6 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install black~=23.0
Expand All @@ -16,8 +16,8 @@ jobs:
flake8:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install flake8
Expand All @@ -26,8 +26,8 @@ jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install -Ur mypy-requirements.txt
Expand Down
24 changes: 12 additions & 12 deletions .github/workflows/nose-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ jobs:
python-version: ['3.8', '3.10', '3.12']

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -31,8 +31,8 @@ jobs:
python-version: ['3.8', '3.10', '3.12']

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -47,9 +47,9 @@ jobs:
python-version: ['3.8', '3.10', '3.12']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -68,9 +68,9 @@ jobs:
python-version: ['3.8', '3.10', '3.12']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -91,9 +91,9 @@ jobs:
python-version: ['3.8', '3.10', '3.12']

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand All @@ -114,9 +114,9 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- uses: actions/setup-python@v4
- uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

Expand Down
25 changes: 18 additions & 7 deletions apps/archive/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

from typing import List
import flask
import logging
import datetime
Expand Down Expand Up @@ -274,6 +275,7 @@ class ArchiveVersionsResource(Resource):
privileges = {"PATCH": "archive"}
collation = False
versioning = False
notifications = False
mongo_indexes = {
"guid": ([("guid", 1)], {"background": True}),
"_id_document_1": ([("_id_document", 1)], {"background": True}),
Expand Down Expand Up @@ -1328,9 +1330,12 @@ def get_items_chain(self, item):
def get_item_translated_from(item):
_item = item
for _i in range(50):
try:
item = self.find_one(req={}, _id=item["translated_from"])
except Exception:
if item and item.get("translated_from"):
next_item = self.find_one(req={}, _id=item["translated_from"])
if not next_item:
break
item = next_item
else:
break
else:
logger.error(
Expand All @@ -1339,18 +1344,22 @@ def get_item_translated_from(item):
return item

item = get_item_translated_from(item)
if not item:
return []
# add item + translations
items_chain = [item]
items_chain += self.get_item_translations(item)

for _i in range(50):
try:
item = self.find_one(req={}, _id=item["rewrite_of"])
if not item:
break
# prepend translations + update
items_chain = [item, *self.get_item_translations(item), *items_chain]
except Exception:
except KeyError:
# `item` is not an update, but it can be a translation
if "translated_from" in item:
if item and item.get("translated_from"):
translation_item = item
item = get_item_translated_from(item)
# add item + translations
Expand All @@ -1372,15 +1381,17 @@ def get_item_translated_from(item):
logger.error("Failed to retrieve the whole items chain for item {}".format(item.get("_id")))
return items_chain

def get_item_translations(self, item):
def get_item_translations(self, item) -> List[str]:
"""
Get list of item's translations.
:param item: item
:type item: dict
:return: list of dicts
:rtype: list
"""
translation_items = []
translation_items: List[str] = []
if not item or not item.get("translations"):
return translation_items

for translation_item_id in item.get("translations", []):
translation_item = self.find_one(req={}, _id=translation_item_id)
Expand Down
1 change: 1 addition & 0 deletions apps/archive_history/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class ArchiveHistoryResource(Resource):
endpoint_name = "archive_history"
resource_methods = ["GET"]
item_methods = ["GET"]
notifications = False
schema = {
"item_id": {"type": "string"},
"user_id": Resource.rel("users", True),
Expand Down
14 changes: 9 additions & 5 deletions apps/auth/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,17 @@ def on_deleted(self, doc):
:param doc: A deleted auth doc AKA a session
:return:
"""
# Clear the session data when session has ended
flask.session.pop("session_token", None)
is_last_session = False
if flask.request:
# Clear the session data when session has ended
flask.session.pop("session_token", None)
sessions = self.get(req=None, lookup={"user": doc["user"]})
is_last_session = not sessions.count()

# notify that the session has ended
sessions = self.get(req=None, lookup={"user": doc["user"]})
app.on_session_end(doc["user"], doc["_id"], is_last_session=not sessions.count())
self.set_user_last_activity(doc["user"], done=True)
app.on_session_end(doc["user"], doc["_id"], is_last_session=is_last_session)
if is_last_session:
self.set_user_last_activity(doc["user"], done=True)

def is_authorized(self, **kwargs) -> bool:
"""
Expand Down
6 changes: 3 additions & 3 deletions apps/auth/session_purge.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def remove_expired_sessions(self):
expiration_time = utcnow() - timedelta(minutes=expiry_minutes)
logger.info("Deleting session not updated since {}".format(expiration_time))
query = {"_updated": {"$lte": date_to_str(expiration_time)}}
sessions = auth_service.get(req=None, lookup=query)
for session in sessions:
auth_service.delete({"_id": str(session["_id"])})
sessions = list(auth_service.get(req=None, lookup=query))
if sessions:
auth_service.delete_docs(sessions)
self._update_online_users()

def _update_online_users(self):
Expand Down
9 changes: 5 additions & 4 deletions apps/item_lock/components/item_lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def lock(self, item_filter, user_id, session_id, action):
# unlock the lock :)
unlock(lock_id, remove=True)

def unlock(self, item_filter, user_id, session_id, etag):
def unlock(self, item_filter, user_id, session_id, etag, force=False):
item_model = get_model(ItemModel)
item = item_model.find_one(item_filter)

Expand All @@ -134,7 +134,7 @@ def unlock(self, item_filter, user_id, session_id, etag):

can_user_unlock, error_message = self.can_unlock(item, user_id)

if can_user_unlock:
if can_user_unlock or force:
self.app.on_item_unlock(item, user_id)
updates = {}

Expand Down Expand Up @@ -172,10 +172,11 @@ def unlock(self, item_filter, user_id, session_id, etag):

def unlock_session(self, user_id, session_id, is_last_session):
item_model = get_model(ItemModel)
items = item_model.find({LOCK_SESSION: str(session_id)} if not is_last_session else {LOCK_USER: str(user_id)})
lookup = {LOCK_SESSION: str(session_id)} if not is_last_session else {LOCK_USER: str(user_id)}
items = item_model.find(lookup)

for item in items:
self.unlock({"_id": item["_id"]}, user_id, session_id, None)
self.unlock({"_id": item["_id"]}, user_id, session_id, None, force=True)

def can_lock(self, item, user_id, session_id):
"""
Expand Down
9 changes: 9 additions & 0 deletions apps/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,15 @@ class PreferencesResource(Resource):
category=lazy_gettext("archive"),
)

superdesk.register_default_user_preference(
"application:theme",
{
"type": "string",
"allowed": ["light-ui", "dark-ui"],
"theme": "light-ui",
},
)

superdesk.register_default_user_preference(
"singleline:view",
{
Expand Down
1 change: 1 addition & 0 deletions content_api/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
CLIENT_URL,
DEBUG,
URN_DOMAIN,
PROXY_MEDIA_STORAGE_CHECK_EXISTS,
)

CONTENTAPI_INSTALLED_APPS = [
Expand Down
2 changes: 2 additions & 0 deletions content_api/items/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,11 @@ class ItemsResource(Resource):
versioning = True
mongo_prefix = MONGO_PREFIX
elastic_prefix = ELASTIC_PREFIX
notifications = False


class InternalItemsResource(ItemsResource):
internal = True
mongo_indexes = {}
versioning = False
notifications = False
1 change: 1 addition & 0 deletions content_api/items_versions/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ class ItemsVersionsResource(Resource):
resource_methods = ["GET"]
internal_resource = True
mongo_prefix = MONGO_PREFIX
notifications = False
3 changes: 1 addition & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,14 @@ pep8
pyflakes
pydocstyle<7.0
httmock==1.4.0
watchdog==4.0.1
wooper==0.4.4
requests-mock==1.12.1
responses
pytest
pytest-env
python3-saml>=1.9,<1.17
typing_extensions>=3.7.4
moto[sqs]==5.0.18
moto[sqs]==5.0.23
pyexiv2>=2.12.0,<2.13; sys_platform == 'linux'

-e .
Expand Down
Loading

0 comments on commit deb8f64

Please sign in to comment.