Skip to content

Commit

Permalink
feat: Support the new quota action options in LimeSurvey 6.6.7+
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon committed Nov 12, 2024
1 parent 58d7ac5 commit 5dfa228
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 10 deletions.
33 changes: 24 additions & 9 deletions docs/_ext/limesurvey_future.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@
if t.TYPE_CHECKING:
from sphinx.application import Sphinx

__all__ = ["ReleasedFeature", "UnreleasedFeature", "setup"]
__all__ = [
"ReleasedAttribute",
"ReleasedFeature",
"ReleasedParameter",
"UnreleasedFeature",
"UnreleasedParameter",
"setup",
]


class UnreleasedFeature(Directive):
Expand All @@ -21,7 +28,7 @@ class UnreleasedFeature(Directive):
"""

required_arguments = 1
message = "This method is only supported in LimeSurvey >= {next_version}."
message = "This method is only supported in LimeSurvey {next_version} and above."
admonition_type = nodes.warning

def run(self) -> list[nodes.Node]:
Expand All @@ -38,9 +45,7 @@ class UnreleasedParameter(Directive):
"""

required_arguments = 2
message = (
"The parameter {parameter} is only supported in LimeSurvey >= {next_version}."
)
message = "The parameter {parameter} is only supported in LimeSurvey {next_version} and above." # noqa: E501
admonition_type = nodes.warning

def run(self) -> list[nodes.Node]:
Expand All @@ -55,7 +60,7 @@ class ReleasedFeature(UnreleasedFeature):
Adds a note to features only available after some release of LimeSurvey.
"""

message = "This method is only supported in LimeSurvey >= {next_version}."
message = "This method is only supported in LimeSurvey {next_version} and above."
admonition_type = nodes.note


Expand All @@ -66,17 +71,27 @@ class ReleasedParameter(UnreleasedParameter):
LimeSurvey.
"""

message = (
"The parameter {parameter} is only supported in LimeSurvey >= {next_version}."
)
message = "The parameter {parameter} is only supported in LimeSurvey {next_version} and above." # noqa: E501
admonition_type = nodes.note


class ReleasedAttribute(ReleasedFeature):
"""A directive for released attributes.
Adds a note to class attributes that are only available after some release of
LimeSurvey.
"""

message = "The attribute is only supported in LimeSurvey {next_version} and above."
admonition_type = nodes.warning


def setup(app: Sphinx) -> dict[str, t.Any]:
app.add_directive("future", UnreleasedFeature)
app.add_directive("futureparam", UnreleasedParameter)
app.add_directive("minlimesurvey", ReleasedFeature)
app.add_directive("minlimesurveyparam", ReleasedParameter)
app.add_directive("minlimesurveyattribute", ReleasedAttribute)

return {
"version": "0.1",
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@
"RPC method %s",
),
"ls_manual": (
"https://manual.limesurvey.org/%s",
"https://limesurvey.org/manual/%s",
"%s",
),
"ls_tag": (
Expand Down
15 changes: 15 additions & 0 deletions src/citric/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ def add_quota(
Calls :rpc_method:`add_quota`.
You can read more about quotas in the
:ls_manual:`LimeSurvey manual <Survey_quotas>`.
Args:
survey_id: ID of the survey to add the quota to.
name: Name of the quota.
Expand Down Expand Up @@ -590,6 +593,9 @@ def delete_quota(self, quota_id: int) -> types.OperationStatus:
Calls :rpc_method:`delete_quota`.
You can read more about quotas in the
:ls_manual:`LimeSurvey manual <Survey_quotas>`.
Args:
quota_id: ID of the quota to delete.
Expand Down Expand Up @@ -973,6 +979,9 @@ def get_quota_properties(
Calls :rpc_method:`get_quota_properties`.
You can read more about quotas in the
:ls_manual:`LimeSurvey manual <Survey_quotas>`.
Args:
quota_id: ID of the quota to get properties for.
settings: Properties to get, default to all.
Expand Down Expand Up @@ -1459,6 +1468,9 @@ def list_quotas(self, survey_id: int) -> list[types.QuotaListElement]:
Calls :rpc_method:`list_quotas`.
You can read more about quotas in the
:ls_manual:`LimeSurvey manual <Survey_quotas>`.
Args:
survey_id: ID of the survey to get quotas for.
Expand Down Expand Up @@ -1601,6 +1613,9 @@ def set_quota_properties(
Calls :rpc_method:`set_quota_properties`.
You can read more about quotas in the
:ls_manual:`LimeSurvey manual <Survey_quotas>`.
Args:
quota_id: Quota ID.
properties: Properties to set.
Expand Down
20 changes: 20 additions & 0 deletions src/citric/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,25 @@ class QuotaAction(StringEnum):
"""Quota action."""

TERMINATE = "terminate"
"""Terminate after related visible question was submitted."""

CONFIRM_TERMINATE = "confirm_terminate"
"""Soft terminate after related visible question was submitted, answer will be
editable."""

TERMINATE_VISIBLE_HIDDEN = "terminate_visible_hidden"
"""Terminate after related visible and hidden questions were submitted.
.. versionadded:: NEXT_VERSION
.. minlimesurveyattribute:: 6.6.7
"""

TERMINATE_PAGES = "terminate_pages"
"""Terminate after all page submissions.
.. versionadded:: NEXT_VERSION
.. minlimesurveyattribute:: 6.6.7
"""

@property
def integer_value(self) -> int:
Expand All @@ -114,6 +132,8 @@ def integer_value(self) -> int:
mapping = {
self.TERMINATE: 1,
self.CONFIRM_TERMINATE: 2,
self.TERMINATE_VISIBLE_HIDDEN: 3,
self.TERMINATE_PAGES: 4,
}
return mapping[self]

Expand Down
16 changes: 16 additions & 0 deletions tests/integration/test_rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from __future__ import annotations

import contextlib
import csv
import io
import json
Expand Down Expand Up @@ -422,6 +423,21 @@ def test_quota(
with pytest.raises(LimeSurveyStatusError, match="Error: Invalid quota ID"):
client.get_quota_properties(quota_id)

# New (6.6.7+) quota options
context = (
contextlib.nullcontext()
if server_version >= semver.VersionInfo.parse("6.6.7")
else pytest.raises(
LimeSurveyStatusError,
match="Error: Invalid quota action",
)
)
action = enums.QuotaAction.TERMINATE_VISIBLE_HIDDEN
with context:
quota_id = client.add_quota(survey_id, "Test Quota", 100, action=action)
props = client.get_quota_properties(quota_id)
assert int(props["action"]) == action.integer_value


@pytest.mark.integration_test
def test_activate_survey(client: citric.Client, survey_id: int):
Expand Down

0 comments on commit 5dfa228

Please sign in to comment.