Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions invenio_communities/communities/dumpers/featured.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
#
# This file is part of Invenio.
# Copyright (C) 2022 Graz University of Technology.
# Copyright (C) 2022-2024 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -12,7 +12,7 @@
search body.
"""

from datetime import datetime
from datetime import datetime, timezone

from invenio_records.dumpers import SearchDumperExt

Expand All @@ -28,7 +28,7 @@ def __init__(self, key="featured"):

def dump(self, record, data):
"""Dump featured entries."""
now_ = datetime.utcnow()
now_ = datetime.now(timezone.utc)
future_entries = (
CommunityFeatured.query.filter(
CommunityFeatured.community_id == record.id,
Expand Down
13 changes: 6 additions & 7 deletions invenio_communities/communities/records/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,19 @@
#
# This file is part of Invenio.
# Copyright (C) 2016-2021 CERN.
# Copyright (C) 2022 Graz University of Technology.
# Copyright (C) 2022-2024 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Community database models."""

from datetime import datetime
from datetime import datetime, timezone

from invenio_db import db
from invenio_files_rest.models import Bucket
from invenio_records.models import RecordMetadataBase, Timestamp
from invenio_records.models import RecordMetadataBase
from invenio_records_resources.records import FileRecordModelMixin
from sqlalchemy.dialects import mysql
from sqlalchemy.types import String
from sqlalchemy_utils.types import ChoiceType, UUIDType

Expand Down Expand Up @@ -48,7 +47,7 @@ class CommunityFileMetadata(db.Model, RecordMetadataBase, FileRecordModelMixin):
__tablename__ = "communities_files"


class CommunityFeatured(db.Model, Timestamp):
class CommunityFeatured(db.Model, db.Timestamp):
"""Featured community entry."""

__tablename__ = "communities_featured"
Expand All @@ -58,7 +57,7 @@ class CommunityFeatured(db.Model, Timestamp):
UUIDType, db.ForeignKey(CommunityMetadata.id), nullable=False
)
start_date = db.Column(
db.DateTime().with_variant(mysql.DATETIME(fsp=6), "mysql"),
db.UTCDateTime(),
nullable=False,
default=datetime.utcnow,
default=lambda: datetime.now(timezone.utc),
)
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 TU Wien.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio-Communities is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

"""Systemfield for managing tombstone information of a community."""

from datetime import datetime
from datetime import datetime, timezone

from invenio_records.systemfields import SystemField
from invenio_requests.resolvers.registry import ResolverRegistry
Expand Down Expand Up @@ -90,7 +91,7 @@ def removal_date(self):
def removal_date(self, value):
"""Set the removal date."""
if value is None:
value = datetime.utcnow()
value = datetime.now(timezone.utc)

if isinstance(value, datetime):
value = value.isoformat()
Expand Down
2 changes: 1 addition & 1 deletion invenio_communities/communities/resources/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#
# This file is part of Invenio.
# Copyright (C) 2022 CERN.
# Copyright (C) 2025 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -22,5 +23,4 @@ def __init__(self):
format_serializer_cls=JSONSerializer,
object_schema_cls=UICommunitySchema,
list_schema_cls=BaseListSchema,
schema_context={"object_key": "ui"},
)
3 changes: 3 additions & 0 deletions invenio_communities/communities/resources/ui_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# This file is part of Invenio.
# Copyright (C) 2022-2024 CERN.
# Copyright (C) 2023 TU Wien.
# Copyright (C) 2025 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -93,6 +94,8 @@ class FundingSchema(Schema):
class UICommunitySchema(BaseObjectSchema):
"""Schema for dumping extra information of the community for the UI."""

object_key = "ui"

type = fields.Nested(VocabularyL10Schema, attribute="metadata.type")

funding = fields.List(
Expand Down
9 changes: 5 additions & 4 deletions invenio_communities/fixtures/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
#
# This file is part of Invenio.
# Copyright (C) 2016-2021 CERN.
# Copyright (C) 2022 Graz University of Technology.
# Copyright (C) 2022-2025 Graz University of Technology.
#
# Invenio is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Celery tasks for fixtures."""

from datetime import datetime

from datetime import datetime, timezone
from uuid import UUID

from celery import shared_task
Expand Down Expand Up @@ -39,7 +40,7 @@ def create_demo_community(data, logo_path=None, feature=False):
service.update_logo(system_identity, community.id, filestream)

if feature:
featured_data = {"start_date": datetime.utcnow().isoformat()}
featured_data = {"start_date": datetime.now(timezone.utc).isoformat()}
service.featured_create(system_identity, community.id, featured_data)
if "id" in data:
uuid = data["id"]
Expand All @@ -54,7 +55,7 @@ def create_demo_community(data, logo_path=None, feature=False):
def reindex_featured_entries():
"""Reindexes records having at least one future entry which is now in the past."""
service = current_communities.service
now = datetime.utcnow().isoformat()
now = datetime.now(timezone.utc).isoformat()

@unit_of_work()
def reindex_community(hit, uow=None):
Expand Down
13 changes: 7 additions & 6 deletions invenio_communities/members/services/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copyright (C) 2022 Northwestern University.
# Copyright (C) 2022 CERN.
# Copyright (C) 2023 Graz University of Technology.
# Copyright (C) 2023-2025 Graz University of Technology.
#
# Invenio-Communities is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -18,6 +18,7 @@
current_users_service,
)
from marshmallow import Schema, ValidationError, fields, validate, validates_schema
from marshmallow_utils.context import context_schema
from marshmallow_utils.fields import SanitizedUnicode, TZDateTime

from .fields import RoleField
Expand Down Expand Up @@ -123,7 +124,7 @@ def get_user_member(self, user):
name = profile.get("full_name") or user.get("username") or _("Untitled")
description = profile.get("affiliations") or ""
fake_user_obj = SimpleNamespace(id=user["id"])
current_identity = self.context["identity"]
current_identity = context_schema.get()["identity"]
avatar = current_users_service.links_item_tpl.expand(
current_identity, fake_user_obj
)["avatar"]
Expand All @@ -139,7 +140,7 @@ def get_user_member(self, user):
def get_group_member(self, group):
"""Get a group member."""
fake_group_obj = SimpleNamespace(id=group["id"])
current_identity = self.context["identity"]
current_identity = context_schema.get()["identity"]
avatar = current_groups_service.links_item_tpl.expand(
current_identity, fake_group_obj
)["avatar"]
Expand Down Expand Up @@ -168,7 +169,7 @@ class MemberDumpSchema(PublicDumpSchema):
def is_self(self, obj):
"""Get permission."""
if "is_self" not in self.context:
current_identity = self.context["identity"]
current_identity = context_schema.get()["identity"]
self.context["is_self"] = (
obj.user_id is not None
and current_identity.id is not None
Expand All @@ -182,7 +183,7 @@ def get_current_user(self, obj):

def get_permissions(self, obj):
"""Get permission."""
permission_check = self.context["field_permission_check"]
permission_check = context_schema.get()["field_permission_check"]

# Does not take CommunitySelfMember into account because no "member" is
# passed to the permission check.
Expand Down Expand Up @@ -214,7 +215,7 @@ def get_permissions(self, obj):
# Only owners and managers can list invitations, and thus only the
# request status is necessary to determine if the identity can cancel.
is_open = obj["request"]["status"] == "submitted"
permission_check = self.context["field_permission_check"]
permission_check = context_schema.get()["field_permission_check"]

return {
"can_cancel": is_open,
Expand Down
4 changes: 2 additions & 2 deletions invenio_communities/members/services/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# Copyright (C) 2022 Northwestern University.
# Copyright (C) 2022-2024 CERN.
# Copyright (C) 2022-2023 Graz University of Technology.
# Copyright (C) 2022-2024 Graz University of Technology.
#
# Invenio-Communities is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.
Expand Down Expand Up @@ -54,7 +54,7 @@
def invite_expires_at():
"""Get the invitation expiration date."""
return (
datetime.utcnow().replace(tzinfo=timezone.utc)
datetime.now(timezone.utc)
+ current_app.config["COMMUNITIES_INVITATIONS_EXPIRES_IN"]
)

Expand Down
8 changes: 4 additions & 4 deletions tests/communities/test_components.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022 Graz University of Technology.
# Copyright (C) 2022-2024 Graz University of Technology.
#
# Invenio-Communities is free software; you can redistribute it and/or modify
# it under the terms of the MIT License; see LICENSE file for more details.

"""Test components."""

from copy import deepcopy
from datetime import datetime
from datetime import datetime, timezone

import pytest
from invenio_access.permissions import system_identity
Expand All @@ -30,7 +30,7 @@ def comm(community_service, minimal_community, owner, location):
"""Create minimal public community."""
c = deepcopy(minimal_community)
c["slug"] = "public-{slug}".format(
slug=str(datetime.utcnow().timestamp()).replace(".", "-")
slug=str(datetime.now(timezone.utc).timestamp()).replace(".", "-")
)
community = community_service.create(data=c, identity=owner.identity)
owner.refresh()
Expand All @@ -43,7 +43,7 @@ def comm_restricted(community_service, minimal_community, owner, location):
c = deepcopy(minimal_community)
c["access"]["visibility"] = "restricted"
c["slug"] = "restricted-{slug}".format(
slug=str(datetime.utcnow().timestamp()).replace(".", "-")
slug=str(datetime.now(timezone.utc).timestamp()).replace(".", "-")
)
community = community_service.create(data=c, identity=owner.identity)
owner.refresh()
Expand Down
Loading
Loading