-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
356 additions
and
52 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
Empty file.
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,42 @@ | ||
from invenio_records_resources.references.entity_resolvers import EntityProxy | ||
from invenio_records_resources.references.entity_resolvers.base import EntityResolver | ||
from flask_principal import Need | ||
|
||
|
||
class AutoApprover: | ||
def __init__(self, value: bool): | ||
self.value = value | ||
|
||
|
||
class AutoApproveProxy(EntityProxy): | ||
def _resolve(self) -> AutoApprover: | ||
value = self._parse_ref_dict_id() | ||
return AutoApprover(value) | ||
|
||
def get_needs(self, ctx=None) -> list[Need]: | ||
return [] # granttokens calls this | ||
|
||
def pick_resolved_fields(self, identity, resolved_dict) -> dict: | ||
return {"auto_approve": resolved_dict["id"]} | ||
|
||
|
||
class AutoApproveResolver(EntityResolver): | ||
type_id = "auto_approve" | ||
|
||
def __init__(self): | ||
self.type_key = self.type_id | ||
super().__init__( | ||
"auto_approve", | ||
) | ||
|
||
def matches_reference_dict(self, ref_dict): | ||
return self._parse_ref_dict_type(ref_dict) == self.type_id | ||
|
||
def _reference_entity(self, entity): | ||
return {self.type_key: str(entity.value)} | ||
|
||
def matches_entity(self, entity): | ||
return isinstance(entity, AutoApprover) | ||
|
||
def _get_entity_proxy(self, ref_dict): | ||
return AutoApproveProxy(self, ref_dict) |
Oops, something went wrong.