Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement access request link expiration setting #1392

Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,10 @@
"accept_conditions_text": {
"description": "Custom description for access conditions to be displayed rather than the default text.",
"type": ["string", "null"]
},
"secret_link_expiration": {
"description": "The default amount of days before secret link expires.",
"type": ["number", "null"]
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
},
"accept_conditions_text": {
"type": "text"
},
"secret_link_expiration": {
"type": "integer"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
},
"accept_conditions_text": {
"type": "text"
},
"secret_link_expiration": {
"type": "integer"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
},
"accept_conditions_text": {
"type": "text"
},
"secret_link_expiration": {
"type": "integer"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
},
"accept_conditions_text": {
"type": "text"
},
"secret_link_expiration": {
"type": "integer"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
},
"accept_conditions_text": {
"type": "text"
},
"secret_link_expiration": {
"type": "integer"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@
},
"accept_conditions_text": {
"type": "text"
},
"secret_link_expiration": {
"type": "integer"
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,23 @@ def __init__(self, settings_dict):
self.allow_user_requests = settings_dict.get("allow_user_requests", False)
self.allow_guest_requests = settings_dict.get("allow_guest_requests", False)
self.accept_conditions_text = settings_dict.get("accept_conditions_text", None)
self.secret_link_expiration = settings_dict.get("secret_link_expiration", None)

def dump(self):
"""Dump the record as dictionary."""
return {
"allow_user_requests": self.allow_user_requests,
"allow_guest_requests": self.allow_guest_requests,
"accept_conditions_text": self.accept_conditions_text,
"secret_link_expiration": self.secret_link_expiration,
}

def __repr__(self):
"""Return repr(self)."""
return "<{} requests: {}/{}, text: {}>".format(
return "<{} requests: {}/{}, text: {}, secret link expiration: {}>".format(
type(self).__name__,
self.allow_guest_requests,
self.allow_user_requests,
self.accept_conditions_text,
self.secret_link_expiration,
)
16 changes: 15 additions & 1 deletion invenio_rdm_records/services/schemas/parent/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from datetime import timezone

from marshmallow import Schema, fields, validate
from marshmallow import Schema, fields, pre_load, validate
from marshmallow_utils.fields import (
ISODateString,
SanitizedHTML,
Expand Down Expand Up @@ -71,6 +71,20 @@ class AccessSettingsSchema(Schema):
allow_guest_requests = fields.Boolean()

accept_conditions_text = SanitizedHTML(allow_none=True)
secret_link_expiration = fields.Integer(
anikachurilova marked this conversation as resolved.
Show resolved Hide resolved
validate=validate.Range(max=365), allow_none=True
)

@pre_load
def translate_expiration_date(self, data, **kwargs):
"""Translate secret_link_expiration from ui dropdown value."""
expiration_days = data["secret_link_expiration"]
if expiration_days == 0:
data["secret_link_expiration"] = None
else:
data["secret_link_expiration"] = expiration_days

return data


class ParentAccessSchema(Schema, FieldPermissionsMixin):
Expand Down
Loading