-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Election Day: Allow application to be private.
TYPE: Feature LINK: OGC-1678
- Loading branch information
Showing
41 changed files
with
436 additions
and
213 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
|
||
from onegov.core.security import Private | ||
from onegov.core.security import Public | ||
from onegov.core.security.permissions import Intent | ||
from onegov.core.security.rules import has_permission_logged_in | ||
from onegov.core.security.rules import has_permission_not_logged_in | ||
from onegov.election_day import ElectionDayApp | ||
|
||
from typing import TYPE_CHECKING | ||
if TYPE_CHECKING: | ||
from morepath.authentication import Identity | ||
|
||
|
||
class MaybePublic(Intent): | ||
""" The general public is allowed to do this, if not otherwise defined | ||
in the principal. """ | ||
|
||
|
||
@ElectionDayApp.permission_rule( | ||
model=object, | ||
permission=MaybePublic, | ||
identity=None | ||
) | ||
def has_permission_maybe_public_not_logged_in( | ||
app: ElectionDayApp, | ||
identity: None, | ||
model: object, | ||
permission: object | ||
) -> bool: | ||
|
||
if getattr(app.principal, 'private', False): | ||
return has_permission_not_logged_in(app, identity, model, Private) | ||
|
||
return has_permission_not_logged_in(app, identity, model, Public) | ||
|
||
|
||
@ElectionDayApp.permission_rule( | ||
model=object, | ||
permission=MaybePublic | ||
) | ||
def has_permission_maybe_public_logged_in( | ||
app: ElectionDayApp, | ||
identity: 'Identity', | ||
model: object, | ||
permission: MaybePublic | ||
) -> bool: | ||
|
||
if getattr(app.principal, 'private', False): | ||
return has_permission_logged_in(app, identity, model, Private) | ||
|
||
return has_permission_logged_in(app, identity, model, Public) |
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
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.