Skip to content

Commit

Permalink
check privilege translations via mypy (#2129)
Browse files Browse the repository at this point in the history
* check privilege translations via mypy

* rename privilege

SDESK-5766

* make mypy validate all init_app

and fix errors there

* black

* fix sams mypy error
  • Loading branch information
petrjasek authored Feb 25, 2021
1 parent 06e86f0 commit c7a46b6
Show file tree
Hide file tree
Showing 127 changed files with 635 additions and 220 deletions.
47 changes: 31 additions & 16 deletions apps/archive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"""Media archive module"""

import logging
from typing import Any

import superdesk
from superdesk.celery_app import celery
Expand All @@ -38,15 +39,15 @@
from apps.common.models.io.eve_proxy import EveProxy
from .archive_rewrite import ArchiveRewriteResource, ArchiveRewriteService
from .news import NewsResource, NewsService
from flask_babel import _
from flask_babel import _, lazy_gettext

logger = logging.getLogger(__name__)


def init_app(app):
def init_app(app) -> None:

endpoint_name = "ingest"
service = AppIngestService(endpoint_name, backend=superdesk.get_backend())
service: Any = AppIngestService(endpoint_name, backend=superdesk.get_backend())
IngestResource(endpoint_name, app=app, service=service)

endpoint_name = "archive_versions"
Expand Down Expand Up @@ -106,24 +107,38 @@ def init_app(app):
register_model(ItemAutosaveModel(EveProxy(superdesk.get_backend())))

superdesk.privilege(
name="monitoring_view", label=_("Monitoring view"), description=_("Access to Monitoring view in left toolbar")
name="monitoring_view",
label=lazy_gettext("Monitoring view"),
description=lazy_gettext("Access to Monitoring view in left toolbar"),
)
superdesk.privilege(name="archive", label=_("Create content"), description=_("Create and save content"))
superdesk.privilege(name="ingest", label=_("Ingest"), description=_("Access to ingest sources management"))
superdesk.privilege(name="spike", label=_("Spike"), description=_("Spike/delete items"))
superdesk.privilege(name="spike_read", label=_("Spike view"), description=_("View spiked content"))
superdesk.privilege(name="unspike", label=_("Unspike"), description=_("Unspike/undelete content"))
superdesk.privilege(name="metadata_uniquename", label=_("Edit Unique Name"), description=_("Edit unique name"))
superdesk.privilege(name="hold", label=_("Hold"), description=_("Hold content"))
superdesk.privilege(name="restore", label=_("Restore"), description=_("Restore content"))
superdesk.privilege(name="rewrite", label=_("Update"), description=_("Create an update"))
superdesk.privilege(
name="unlock", label=_("Unlock content"), description=_("Unlock locked content by another user")
name="archive", label=lazy_gettext("Create content"), description=lazy_gettext("Create and save content")
)
superdesk.privilege(
name="ingest", label=lazy_gettext("Ingest"), description=lazy_gettext("Access to ingest sources management")
)
superdesk.privilege(name="spike", label=lazy_gettext("Spike"), description=lazy_gettext("Spike/delete items"))
superdesk.privilege(
name="spike_read", label=lazy_gettext("Spike view"), description=lazy_gettext("View spiked content")
)
superdesk.privilege(
name="unspike", label=lazy_gettext("Unspike"), description=lazy_gettext("Unspike/undelete content")
)
superdesk.privilege(
name="metadata_uniquename", label=lazy_gettext("Edit Unique Name"), description=lazy_gettext("Edit unique name")
)
superdesk.privilege(name="hold", label=lazy_gettext("Hold"), description=lazy_gettext("Hold content"))
superdesk.privilege(name="restore", label=lazy_gettext("Restore"), description=lazy_gettext("Restore content"))
superdesk.privilege(name="rewrite", label=lazy_gettext("Update"), description=lazy_gettext("Create an update"))
superdesk.privilege(
name="unlock",
label=lazy_gettext("Unlock content"),
description=lazy_gettext("Unlock locked content by another user"),
)
superdesk.privilege(
name="mark_for_user",
label=_("Mark items for users"),
description=_("User can mark or unmark items for other users"),
label=lazy_gettext("Mark items for users"),
description=lazy_gettext("User can mark or unmark items for other users"),
)

superdesk.intrinsic_privilege(ArchiveUnlockResource.endpoint_name, method=["POST"])
Expand Down
2 changes: 1 addition & 1 deletion apps/archive/autocomplete.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def get(self, req, lookup):
return ListCursor(docs)


def init_app(_app):
def init_app(_app) -> None:
_app.client_config.update({"archive_autocomplete": _app.config.get(SETTING_ENABLED, False)})

if _app.config.get(SETTING_ENABLED) and not _app.config.get(SETTING_HOURS) and not _app.config.get(SETTING_DAYS):
Expand Down
5 changes: 3 additions & 2 deletions apps/archive/item_comments.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 Any
import superdesk
from superdesk.resource import Resource
from superdesk.services import BaseService
Expand Down Expand Up @@ -49,9 +50,9 @@ def get(self, req, lookup):
return super().get(req, lookup)


def init_app(app):
def init_app(app) -> None:
endpoint_name = "item_comments"
service = ItemCommentsService(endpoint_name, backend=superdesk.get_backend())
service: Any = ItemCommentsService(endpoint_name, backend=superdesk.get_backend())
ItemCommentsResource(endpoint_name, app=app, service=service)

endpoint_name = "content_item_comments"
Expand Down
8 changes: 6 additions & 2 deletions apps/archive_broadcast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,22 @@
# at https://www.sourcefabric.org/superdesk/license

import logging

from flask_babel import lazy_gettext
import superdesk
from .broadcast import ArchiveBroadcastResource, ArchiveBroadcastService, ARCHIVE_BROADCAST_NAME

logger = logging.getLogger(__name__)


def init_app(app):
def init_app(app) -> None:

endpoint_name = ARCHIVE_BROADCAST_NAME
service = ArchiveBroadcastService(endpoint_name, backend=superdesk.get_backend())
ArchiveBroadcastResource(endpoint_name, app=app, service=service)

superdesk.privilege(
name=ARCHIVE_BROADCAST_NAME, label="Broadcast", description="Allows user to create broadcast content."
name=ARCHIVE_BROADCAST_NAME,
label=lazy_gettext("Broadcast"),
description=lazy_gettext("Allows user to create broadcast content."),
)
2 changes: 1 addition & 1 deletion apps/archive_history/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
log = logging.getLogger(__name__)


def init_app(app):
def init_app(app) -> None:
endpoint_name = "archive_history"

service = ArchiveHistoryService(endpoint_name, backend=get_backend())
Expand Down
2 changes: 1 addition & 1 deletion apps/archived/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from apps.archived.archived import ArchivedResource, ArchivedService


def init_app(app):
def init_app(app) -> None:

endpoint_name = "archived"
service = ArchivedService(endpoint_name, backend=superdesk.get_backend())
Expand Down
8 changes: 6 additions & 2 deletions apps/archived/archived.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
from superdesk.resource import Resource
from superdesk.utc import utcnow
from apps.publish.content import KillPublishService, TakeDownPublishService
from flask_babel import _
from flask_babel import _, lazy_gettext

logger = logging.getLogger(__name__)
PACKAGE_TYPE = "package_type"
Expand Down Expand Up @@ -409,4 +409,8 @@ def _get_package_refs(self, package):
return refs


superdesk.privilege(name="archived", label="Archive Management", description="User can remove items from the archived")
superdesk.privilege(
name="archived",
label=lazy_gettext("Archive Management"),
description=lazy_gettext("User can remove items from the archived"),
)
2 changes: 1 addition & 1 deletion apps/auth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
logger = logging.getLogger(__name__)


def init_app(app):
def init_app(app) -> None:
app.auth = SuperdeskTokenAuth() # Overwrite the app default auth

endpoint_name = "auth_users"
Expand Down
5 changes: 3 additions & 2 deletions apps/auth/db/__init__.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 Any
from apps.auth import AuthResource
from .reset_password import ResetPasswordService, ResetPasswordResource, ActiveTokensResource
import superdesk
Expand All @@ -17,9 +18,9 @@
from apps.auth.db.change_password import ChangePasswordService, ChangePasswordResource


def init_app(app):
def init_app(app) -> None:
endpoint_name = "auth_db"
service = DbAuthService("auth", backend=superdesk.get_backend())
service: Any = DbAuthService("auth", backend=superdesk.get_backend())
AuthResource(endpoint_name, app=app, service=service)

endpoint_name = "reset_user_password"
Expand Down
2 changes: 1 addition & 1 deletion apps/auth/oidc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
logger = logging.getLogger(__name__)


def init_app(app):
def init_app(app) -> None:
endpoint_name = "auth_oidc"
if app.config["OIDC_ENABLED"] and not app.config["SECRET_KEY"]:
logger.warn("SECRET_KEY is not set")
Expand Down
2 changes: 1 addition & 1 deletion apps/auth/xmpp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .auth import XMPPAuthResource, XMPPAuthService


def init_app(app):
def init_app(app) -> None:
endpoint_name = "auth_xmpp"
service = XMPPAuthService("auth", backend=superdesk.get_backend())
XMPPAuthResource(endpoint_name, app=app, service=service)
Expand Down
2 changes: 1 addition & 1 deletion apps/client_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def on_fetched(self, docs):
docs["config"] = getattr(app, "client_config", {})


def init_app(app):
def init_app(app) -> None:
superdesk.register_resource("client_config", ClientConfigResource, ClientConfigService, _app=app)
app.client_config.update(
{
Expand Down
2 changes: 1 addition & 1 deletion apps/comments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from .inline_comments import handle_inline_mentions


def init_app(app):
def init_app(app) -> None:
endpoint_name = "comments"
service = CommentsService(endpoint_name, backend=superdesk.get_backend())
CommentsResource(endpoint_name, app=app, service=service)
Expand Down
7 changes: 5 additions & 2 deletions apps/concept_items/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@

import superdesk

from flask_babel import lazy_gettext
from .resource import ConceptItemsResource, CONCEPT_ITEMS_PRIVELEGE
from .service import ConceptItemsService


def init_app(app):
def init_app(app) -> None:
endpoint_name = "concept_items"
service = ConceptItemsService(endpoint_name, backend=superdesk.get_backend())
ConceptItemsResource(endpoint_name, app=app, service=service)

superdesk.privilege(
name=CONCEPT_ITEMS_PRIVELEGE, label="Concept items management", description="User can manage concept items."
name=CONCEPT_ITEMS_PRIVELEGE,
label=lazy_gettext("Knowledge base management"),
description=lazy_gettext("User can manage knowledge base."),
)

# let everyone create concepts (SDESK-4959)
Expand Down
15 changes: 11 additions & 4 deletions apps/contacts/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,26 @@
# at https://www.sourcefabric.org/superdesk/license

import logging
from typing import Any

from flask_babel import lazy_gettext
import superdesk
from .service import ContactsService, OrganisationService
from .resource import ContactsResource, CONTACTS_PRIVILEDGE, VIEW_CONTACTS, OrganisationSearchResource

logger = logging.getLogger(__name__)


def init_app(app):
def init_app(app) -> None:
endpoint_name = "contacts"
service = ContactsService(endpoint_name, backend=superdesk.get_backend())
service: Any = ContactsService(endpoint_name, backend=superdesk.get_backend())
ContactsResource(endpoint_name, app=app, service=service)
superdesk.privilege(name=CONTACTS_PRIVILEDGE, label="Contacts Management", description="Manage Contacts")
superdesk.privilege(name=VIEW_CONTACTS, label="Contacts View Rights", description="View Contacts")
superdesk.privilege(
name=CONTACTS_PRIVILEDGE, label=lazy_gettext("Contacts Management"), description=lazy_gettext("Manage Contacts")
)
superdesk.privilege(
name=VIEW_CONTACTS, label=lazy_gettext("Contacts View Rights"), description=lazy_gettext("View Contacts")
)

service = OrganisationService(endpoint_name, backend=superdesk.get_backend())
endpoint_name = "contacts organisations"
Expand Down
12 changes: 9 additions & 3 deletions apps/content_filters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

from typing import Any
from flask_babel import lazy_gettext
import superdesk
from superdesk import get_backend

Expand All @@ -24,9 +26,9 @@
from apps.content_filters.content_filter.content_filter_test import ContentFilterTestResource, ContentFilterTestService


def init_app(app):
def init_app(app) -> None:
endpoint_name = "filter_conditions"
service = FilterConditionService(endpoint_name, backend=get_backend())
service: Any = FilterConditionService(endpoint_name, backend=get_backend())
FilterConditionResource(endpoint_name, app=app, service=service)

endpoint_name = "filter_condition_parameters"
Expand All @@ -41,4 +43,8 @@ def init_app(app):
service = ContentFilterTestService(endpoint_name, backend=superdesk.get_backend())
ContentFilterTestResource(endpoint_name, app=app, service=service)

superdesk.privilege(name="content_filters", label="Content Filters", description="User can manage content filters")
superdesk.privilege(
name="content_filters",
label=lazy_gettext("Content Filters"),
description=lazy_gettext("User can manage content filters"),
)
9 changes: 7 additions & 2 deletions apps/content_types/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
from flask_babel import lazy_gettext
import superdesk
from .content_types import ContentTypesResource, ContentTypesService, CONTENT_TYPE_PRIVILEGE
from .content_types import apply_schema # noqa


def init_app(app):
def init_app(app) -> None:
endpoint_name = "content_types"
service = ContentTypesService(endpoint_name, backend=superdesk.get_backend())
ContentTypesResource(endpoint_name, app=app, service=service)
superdesk.privilege(name=CONTENT_TYPE_PRIVILEGE, label="Content Profile", description="Manage content profiles")
superdesk.privilege(
name=CONTENT_TYPE_PRIVILEGE,
label=lazy_gettext("Content Profile"),
description=lazy_gettext("Manage content profiles"),
)
7 changes: 5 additions & 2 deletions apps/desk_routing.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from flask_babel import lazy_gettext
import superdesk

from superdesk.notification import push_notification
Expand Down Expand Up @@ -52,7 +53,7 @@ def remove_marks(self, desk_id):
push_content_notification([item])


def init_app(app):
def init_app(app) -> None:
app.config["DOMAIN"]["desks"]["schema"].update(
{
"is_closed": {"type": "boolean"},
Expand All @@ -69,4 +70,6 @@ def init_app(app):

superdesk.register_resource("closed_desks", ClosedDeskResource, ClosedDeskService, _app=app)

superdesk.privilege(name=PRIVILEGE, label="Desk routing", description="User can configure desk routing")
superdesk.privilege(
name=PRIVILEGE, label=lazy_gettext("Desk routing"), description=lazy_gettext("User can configure desk routing")
)
14 changes: 9 additions & 5 deletions apps/desks.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from superdesk.metadata.item import FAMILY_ID, ITEM_STATE, CONTENT_STATE
from eve.utils import ParsedRequest
from superdesk.utils import ListCursor
from flask_babel import _
from flask_babel import _, lazy_gettext


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -85,9 +85,9 @@ class DeskTypes(SuperdeskBaseEnum):
}


def init_app(app):
def init_app(app) -> None:
endpoint_name = "desks"
service = DesksService(endpoint_name, backend=superdesk.get_backend())
service: Any = DesksService(endpoint_name, backend=superdesk.get_backend())
DesksResource(endpoint_name, app=app, service=service)
endpoint_name = "user_desks"
service = UserDesksService(endpoint_name, backend=superdesk.get_backend())
Expand All @@ -100,8 +100,12 @@ def init_app(app):
OverviewResource(endpoint_name, app=app, service=service)


superdesk.privilege(name="desks", label="Desk Management", description="User can manage desks.")
superdesk.privilege(name="masterdesk", label="Master Desk", description="User can access master desk.")
superdesk.privilege(
name="desks", label=lazy_gettext("Desk Management"), description=lazy_gettext("User can manage desks.")
)
superdesk.privilege(
name="masterdesk", label=lazy_gettext("Master Desk"), description=lazy_gettext("User can access master desk.")
)


class DesksResource(Resource):
Expand Down
Loading

0 comments on commit c7a46b6

Please sign in to comment.