Skip to content

Commit

Permalink
remove get_unused_files action, add actino doc
Browse files Browse the repository at this point in the history
  • Loading branch information
mutantsan committed Jan 27, 2024
1 parent a47ce75 commit f5291a6
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 6 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,16 @@ the file, which config options will be applied, etc. Default value is

Returns: `True`


* `files_get_unused_files`

List of all `file`s, that are not used for N days.

Parameters:
* `threshold: Optional[int]`: threshold in days, default `180`.

Returns: `True`

## Config settings

# Allowed size for uploaded file in MB.
Expand Down
2 changes: 1 addition & 1 deletion ckanext/files/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def remove_unused_files(delete: bool, threshold: int):
else files_conf.get_unused_threshold()
)

files = tk.get_action("files_file_get_unused_files")(
files = tk.get_action("files_get_unused_files")(
{"ignore_auth": True}, {"threshold": threshold}
)

Expand Down
4 changes: 2 additions & 2 deletions ckanext/files/logic/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,9 @@ def _remove_file_from_filesystem(file_path: str) -> bool:
@action
@tk.side_effect_free
@validate(schema.file_get_unused_files)
def file_get_unused_files(context, data_dict):
def get_unused_files(context, data_dict):
"""Return a list of unused file based on a configured threshold"""
tk.check_access("files_file_get_unused_files", context, data_dict)
tk.check_access("files_get_unused_files", context, data_dict)

threshold = datetime.datetime.utcnow() - datetime.timedelta(
days=data_dict["threshold"]
Expand Down
2 changes: 1 addition & 1 deletion ckanext/files/logic/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ def file_show(context, data_dict):


@auth
def file_get_unused_files(context, data_dict):
def get_unused_files(context, data_dict):
{"success": False}
4 changes: 2 additions & 2 deletions ckanext/files/tests/logic/test_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ def test_show_updates_last_access(self, random_file):
@pytest.mark.usefixtures("with_plugins")
class TestGetUnusedFiles:
def test_no_unused_files(self, random_file):
assert not call_action("files_file_get_unused_files")
assert not call_action("files_get_unused_files")

@pytest.mark.ckan_config("ckanext.files.unused_threshold", 0)
def test_configure_default_threshold(self, random_file, ckan_config):
assert call_action("files_file_get_unused_files")
assert call_action("files_get_unused_files")

0 comments on commit f5291a6

Please sign in to comment.