Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
thalia
concrexit
Commits
92b9696a
Verified
Commit
92b9696a
authored
Apr 03, 2019
by
Sébastiaan Versteeg
Browse files
Add command to minimise registrations data
parent
1bafbc2b
Changes
9
Hide whitespace changes
Inline
Side-by-side
docs/registrations.management.commands.rst
0 → 100644
View file @
92b9696a
registrations.management.commands package
=========================================
.. automodule:: registrations.management.commands
:members:
:undoc-members:
:show-inheritance:
Submodules
----------
registrations.management.commands.minimiseregistrations module
--------------------------------------------------------------
.. automodule:: registrations.management.commands.minimiseregistrations
:members:
:undoc-members:
:show-inheritance:
docs/registrations.management.rst
0 → 100644
View file @
92b9696a
registrations.management package
================================
.. automodule:: registrations.management
:members:
:undoc-members:
:show-inheritance:
Subpackages
-----------
.. toctree::
registrations.management.commands
docs/registrations.rst
View file @
92b9696a
...
...
@@ -6,6 +6,13 @@ registrations package
:undoc-members:
:show-inheritance:
Subpackages
-----------
.. toctree::
registrations.management
Submodules
----------
...
...
website/registrations/management/__init__.py
0 → 100644
View file @
92b9696a
website/registrations/management/commands/__init__.py
0 → 100644
View file @
92b9696a
website/registrations/management/commands/minimiseregistrations.py
0 → 100644
View file @
92b9696a
from
django.core.management
import
BaseCommand
from
registrations
import
services
class
Command
(
BaseCommand
):
def
add_arguments
(
self
,
parser
):
parser
.
add_argument
(
'--dry-run'
,
action
=
'store_true'
,
dest
=
'dry-run'
,
default
=
False
,
help
=
'Dry run instead of saving data'
,
)
def
handle
(
self
,
*
args
,
**
options
):
services
.
execute_data_minimisation
(
options
[
'dry-run'
])
website/registrations/services.py
View file @
92b9696a
...
...
@@ -415,3 +415,22 @@ def process_payment(payment):
entry
.
membership
=
membership
entry
.
status
=
Entry
.
STATUS_COMPLETED
entry
.
save
()
def
execute_data_minimisation
(
dry_run
=
False
):
"""
Delete completed or rejected registrations that were modified
at least 31 days ago
:param dry_run: does not really remove data if True
:return: number of removed registrations
"""
deletion_period
=
timezone
.
now
().
date
()
-
timezone
.
timedelta
(
days
=
31
)
objects
=
(
Entry
.
objects
.
filter
((
Q
(
status
=
Entry
.
STATUS_COMPLETED
)
|
Q
(
status
=
Entry
.
STATUS_REJECTED
))
&
Q
(
updated_at__lt
=
deletion_period
)))
if
dry_run
:
return
objects
.
count
()
return
objects
.
delete
()[
0
]
website/registrations/tests/test_management.py
0 → 100644
View file @
92b9696a
from
unittest
import
mock
from
unittest.mock
import
MagicMock
from
django.test
import
TestCase
from
registrations.management.commands.minimiseregistrations
import
Command
class
ManagementMinimiseTest
(
TestCase
):
def
test_add_argument
(
self
):
mockParser
=
MagicMock
()
Command
().
add_arguments
(
mockParser
)
mockParser
.
add_argument
.
assert_called_with
(
'--dry-run'
,
action
=
'store_true'
,
default
=
False
,
dest
=
'dry-run'
,
help
=
'Dry run instead of saving data'
)
@
mock
.
patch
(
'registrations.services.execute_data_minimisation'
)
def
test_handle
(
self
,
execute_data_minimisation
):
Command
().
handle
({},
**
{
'dry-run'
:
False
})
execute_data_minimisation
.
assert_called_with
(
False
)
Command
().
handle
({},
**
{
'dry-run'
:
True
})
execute_data_minimisation
.
assert_called_with
(
True
)
website/registrations/tests/test_services.py
View file @
92b9696a
...
...
@@ -569,3 +569,39 @@ class ServicesTest(TestCase):
for
payment
in
Payment
.
objects
.
filter
(
pk__in
=
[
p1
.
pk
,
p2
.
pk
]):
services
.
process_payment
(
payment
)
self
.
assertFalse
(
create_membership
.
called
)
@
freeze_time
(
'2019-01-01'
)
def
test_execute_data_minimisation
(
self
):
with
self
.
subTest
(
'No processed entries'
):
self
.
assertEqual
(
services
.
execute_data_minimisation
(),
0
)
with
freeze_time
(
'2018-09-01'
):
self
.
e0
.
status
=
Entry
.
STATUS_COMPLETED
self
.
e0
.
save
()
with
self
.
subTest
(
'Has processed entries when completed'
):
self
.
assertEqual
(
services
.
execute_data_minimisation
(),
1
)
with
freeze_time
(
'2018-09-01'
):
self
.
e0
.
status
=
Entry
.
STATUS_REJECTED
self
.
e0
.
save
()
with
self
.
subTest
(
'Has processed entries when rejected'
):
self
.
assertEqual
(
services
.
execute_data_minimisation
(),
1
)
with
freeze_time
(
'2018-09-01'
):
self
.
e0
.
status
=
Entry
.
STATUS_COMPLETED
self
.
e0
.
save
()
with
self
.
subTest
(
'Has processed entries when '
'rejected with dry-run'
):
self
.
assertEqual
(
services
.
execute_data_minimisation
(
True
),
1
)
self
.
e0
.
status
=
Entry
.
STATUS_COMPLETED
self
.
e0
.
save
()
with
self
.
subTest
(
'No processed entries when inside 31 days'
):
self
.
assertEqual
(
services
.
execute_data_minimisation
(),
0
)
self
.
e0
.
status
=
Entry
.
STATUS_REVIEW
self
.
e0
.
save
()
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment