Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Debian New Member Process
nm.debian.org
Commits
fc4ac972
Commit
fc4ac972
authored
May 31, 2016
by
Enrico Zini
Browse files
Started testing permissions of new-style processes
parent
b895c2ff
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
backend/unittest.py
View file @
fc4ac972
...
@@ -319,21 +319,21 @@ class ExpectedSets(dict):
...
@@ -319,21 +319,21 @@ class ExpectedSets(dict):
res
.
setdefault
(
k
,
set
()).
update
(
v
)
res
.
setdefault
(
k
,
set
()).
update
(
v
)
return
res
return
res
def
assertEqual
(
self
,
visitor
,
got
):
def
assertEqual
(
self
,
testcase
,
visitor
,
got
):
got
=
set
(
got
)
got
=
set
(
got
)
wanted
=
self
.
get
(
visitor
,
set
())
wanted
=
self
.
get
(
visitor
,
set
())
if
got
==
wanted
:
return
if
got
==
wanted
:
return
extra
=
got
-
wanted
extra
=
got
-
wanted
missing
=
wanted
-
got
missing
=
wanted
-
got
msgs
=
[]
msgs
=
[]
if
missing
:
msgs
.
append
(
self
.
action
_msg
.
format
(
problem
=
"misses"
,
mismatch
=
", "
.
join
(
sorted
(
missing
))))
if
missing
:
msgs
.
append
(
self
.
issue
_msg
.
format
(
problem
=
"misses"
,
mismatch
=
", "
.
join
(
sorted
(
missing
))))
if
extra
:
msgs
.
append
(
self
.
action
_msg
.
format
(
problem
=
"has extra"
,
mismatch
=
", "
.
join
(
sorted
(
extra
))))
if
extra
:
msgs
.
append
(
self
.
issue
_msg
.
format
(
problem
=
"has extra"
,
mismatch
=
", "
.
join
(
sorted
(
extra
))))
se
lf
.
fail
(
self
.
action_msg
.
format
(
visitor
=
visitor
)
+
" "
+
" and "
.
join
(
msgs
))
testca
se
.
fail
(
self
.
action_msg
.
format
(
visitor
=
visitor
)
+
" "
+
" and "
.
join
(
msgs
))
def
assertEmpty
(
self
,
visitor
,
got
):
def
assertEmpty
(
self
,
testcase
,
visitor
,
got
):
extra
=
set
(
got
)
extra
=
set
(
got
)
if
not
extra
:
return
if
not
extra
:
return
se
lf
.
fail
(
self
.
action_msg
.
format
(
visitor
=
visitor
)
+
" "
+
self
.
action
_msg
.
format
(
problem
=
"has"
,
mismatch
=
", "
.
join
(
sorted
(
extra
))))
testca
se
.
fail
(
self
.
action_msg
.
format
(
visitor
=
visitor
)
+
" "
+
self
.
issue
_msg
.
format
(
problem
=
"has"
,
mismatch
=
", "
.
join
(
sorted
(
extra
))))
class
ExpectedPerms
(
object
):
class
ExpectedPerms
(
object
):
...
...
process/models.py
View file @
fc4ac972
...
@@ -45,10 +45,8 @@ class ProcessVisitorPermissions(bmodels.PersonVisitorPermissions):
...
@@ -45,10 +45,8 @@ class ProcessVisitorPermissions(bmodels.PersonVisitorPermissions):
if
self
.
visitor
.
is_admin
:
return
True
if
self
.
visitor
.
is_admin
:
return
True
# The person themselves
# The person themselves
if
self
.
visitor
.
pk
==
self
.
person
.
pk
:
return
True
if
self
.
visitor
.
pk
==
self
.
person
.
pk
:
return
True
# Any AM
# Any active AM
if
self
.
visitor
.
am_or_none
:
return
True
if
self
.
visitor
.
is_active_am
:
return
True
# The advocates
# TODO return self.process.advocates.filter(pk=self.visitor.pk).exists()
return
False
return
False
def
_compute_perms
(
self
):
def
_compute_perms
(
self
):
...
@@ -62,9 +60,37 @@ class RequirementVisitorPermissions(ProcessVisitorPermissions):
...
@@ -62,9 +60,37 @@ class RequirementVisitorPermissions(ProcessVisitorPermissions):
super
(
RequirementVisitorPermissions
,
self
).
__init__
(
requirement
.
process
,
visitor
)
super
(
RequirementVisitorPermissions
,
self
).
__init__
(
requirement
.
process
,
visitor
)
self
.
requirement
=
requirement
self
.
requirement
=
requirement
@
cached_property
def
_can_edit_statements
(
self
):
if
self
.
visitor
is
None
:
return
False
if
self
.
visitor
.
is_admin
:
return
True
if
self
.
requirement
.
type
==
"intent"
:
return
self
.
visitor
==
self
.
person
elif
self
.
requirement
.
type
==
"sc_dmup"
:
return
self
.
visitor
==
self
.
person
elif
self
.
requirement
.
type
==
"advocate"
:
if
self
.
process
.
applying_for
==
const
.
STATUS_DC_GA
:
return
self
.
visitor
.
status
in
(
const
.
STATUS_DM
,
const
.
STATUS_DM_GA
,
const
.
STATUS_DD_NU
,
const
.
STATUS_DD_U
)
elif
self
.
process
.
applying_for
==
const
.
STATUS_DM
:
return
self
.
visitor
.
status
in
(
const
.
STATUS_DD_NU
,
const
.
STATUS_DD_U
)
elif
self
.
process
.
applying_for
==
const
.
STATUS_DM_GA
:
return
self
.
visitor
==
self
.
person
or
self
.
visitor
.
status
in
(
const
.
STATUS_DD_NU
,
const
.
STATUS_DD_U
)
elif
self
.
process
.
applying_for
==
const
.
STATUS_DD_NU
:
return
self
.
visitor
.
status
in
(
const
.
STATUS_DD_NU
,
const
.
STATUS_DD_U
)
elif
self
.
process
.
applying_for
==
const
.
STATUS_DD_U
:
return
self
.
visitor
.
status
in
(
const
.
STATUS_DD_NU
,
const
.
STATUS_DD_U
)
return
False
elif
self
.
requirement
.
type
==
"am_ok"
:
a
=
self
.
process
.
current_am_assignment
if
a
is
None
:
return
False
return
a
.
am
.
person
==
self
.
visitor
return
False
def
_compute_perms
(
self
):
def
_compute_perms
(
self
):
res
=
super
(
RequirementVisitorPermissions
,
self
).
_compute_perms
()
res
=
super
(
RequirementVisitorPermissions
,
self
).
_compute_perms
()
#
if self._can_
view_email: res.add("view_mbox
")
if
self
.
_can_
edit_statements
:
res
.
add
(
"edit_statements
"
)
return
res
return
res
...
...
process/tests/test_perms.py
0 → 100644
View file @
fc4ac972
This diff is collapsed.
Click to expand it.
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