-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat/integ tests notifications (#1597)
### Feature or Bugfix <!-- please choose --> - Feature ### Detail - Integration Tests Notifications ### Relates - #1220 ### Security Please answer the questions below briefly where applicable, or write `N/A`. Based on [OWASP 10](https://owasp.org/Top10/en/). - Does this PR introduce or modify any input fields or queries - this includes fetching data from storage outside the application (e.g. a database, an S3 bucket)? - Is the input sanitized? - What precautions are you taking before deserializing the data you consume? - Is injection prevented by parametrizing queries? - Have you ensured no `eval` or similar functions are used? - Does this PR introduce any functionality or component that requires authorization? - How have you ensured it respects the existing AuthN/AuthZ mechanisms? - Are you logging failed auth attempts? - Are you using or adding any cryptographic features? - Do you use a standard proven implementations? - Are the used keys controlled by the customer? Where are they stored? - Are you introducing any new policies/roles/users? - Have you used the least-privilege principle? How? By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. --------- Co-authored-by: Sofia Sazonova <[email protected]> Co-authored-by: dlpzx <[email protected]>
- Loading branch information
1 parent
938ca42
commit 1b195df
Showing
15 changed files
with
191 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
backend/dataall/modules/notifications/services/notification_service.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
""" | ||
A service layer for Notifications | ||
""" | ||
|
||
import logging | ||
from dataall.base.db import exceptions | ||
|
||
from dataall.base.context import get_context | ||
from dataall.modules.notifications.db import notification_models as models | ||
from functools import wraps | ||
|
||
from dataall.modules.notifications.db.notification_repositories import NotificationRepository | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class NotificationAccess: | ||
@staticmethod | ||
def check_recipient(uri): | ||
context = get_context() | ||
with context.db_engine.scoped_session() as session: | ||
notification = NotificationRepository.get_notification(session=session, uri=uri) | ||
return notification and (notification.recipient in context.groups + [context.username]) | ||
|
||
@staticmethod | ||
def is_recipient(f): | ||
@wraps(f) | ||
def wrapper(*args, **kwds): | ||
uri = kwds.get('notificationUri') | ||
if not uri: | ||
raise KeyError(f"{f.__name__} doesn't have parameter uri.") | ||
|
||
if NotificationAccess.check_recipient(uri): | ||
return f(*args, **kwds) | ||
else: | ||
raise exceptions.UnauthorizedOperation( | ||
action='UPDATE NOTIFICATION', | ||
message=f'User {get_context().username} is not the recipient user/group of the notification {uri}', | ||
) | ||
|
||
return wrapper | ||
|
||
|
||
class NotificationService: | ||
""" | ||
Encapsulate the logic of interactions with notifications. | ||
""" | ||
|
||
@staticmethod | ||
def list_my_notifications(filter: dict = {}): | ||
"""List existed user notifications. Filters only required notifications by the filter param""" | ||
context = get_context() | ||
|
||
with context.db_engine.scoped_session() as session: | ||
return NotificationRepository.paginated_notifications( | ||
session=session, username=context.username, groups=context.groups, filter=filter | ||
) | ||
|
||
@staticmethod | ||
@NotificationAccess.is_recipient | ||
def mark_as_read(notificationUri: str): | ||
with get_context().db_engine.scoped_session() as session: | ||
return NotificationRepository.read_notification(session=session, notificationUri=notificationUri) | ||
|
||
@staticmethod | ||
def count_unread_notifications(): | ||
context = get_context() | ||
with context.db_engine.scoped_session() as session: | ||
return NotificationRepository.count_unread_notifications( | ||
session=session, username=context.username, groups=context.groups | ||
) |
12 changes: 0 additions & 12 deletions
12
frontend/src/services/graphql/Notification/archiveNotification.js
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
frontend/src/services/graphql/Notification/countDeletedNotifications.js
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
frontend/src/services/graphql/Notification/countReadNotifications.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
export * from './archiveNotification'; | ||
export * from './countDeletedNotifications'; | ||
export * from './countReadNotifications'; | ||
export * from './countUnreadNotifications'; | ||
export * from './listNotifications'; | ||
export * from './markAsRead'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.