Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odevzdávací Systém MO
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Martin Mareš
Odevzdávací Systém MO
Commits
079e4589
Commit
079e4589
authored
4 years ago
by
Martin Mareš
Browse files
Options
Downloads
Patches
Plain Diff
Rights: Opraveno kešování práv
parent
7f15aeec
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
mo/rights.py
+15
-14
15 additions, 14 deletions
mo/rights.py
with
15 additions
and
14 deletions
mo/rights.py
+
15
−
14
View file @
079e4589
...
...
@@ -155,6 +155,11 @@ class Rights:
ris
=
"
"
.
join
([
r
.
name
for
r
in
self
.
rights
])
return
f
"
Rights(uid=
{
self
.
user
.
user_id
}
is_admin=
{
self
.
user
.
is_admin
}
roles=<
{
ros
}
> rights=<
{
ris
}
>)
"
def
_clone_from
(
self
,
src
:
'
Rights
'
):
self
.
user
=
src
.
user
self
.
user_roles
=
src
.
user_roles
self
.
rights
=
src
.
rights
def
have_right
(
self
,
right
:
Right
)
->
bool
:
if
self
.
user
.
is_admin
:
return
True
...
...
@@ -303,20 +308,18 @@ class Gatekeeper:
def
rights_for
(
self
,
place
:
Optional
[
db
.
Place
]
=
None
,
year
:
Optional
[
int
]
=
None
,
cat
:
Optional
[
str
]
=
None
,
seq
:
Optional
[
int
]
=
None
,
min_role
:
Optional
[
db
.
RoleType
]
=
None
,
to_rights
:
Optional
[
Rights
]
=
None
)
->
Rights
:
min_role
:
Optional
[
db
.
RoleType
]
=
None
)
->
Rights
:
"""
Posbírá role a práva, která se vztahují k danému místu (možno i tranzitivně) a soutěži.
Pokud place=None, omezení role na místo se nebere v úvahu.
Pokud year==None, vyhovují role s libovolným ročníkem; pokud year=0, vyhovují jen ty s neuvedeným ročníkem.
Podobně cat a seq.
Pokud min_role!=None, tak se uvažují jen role, které jsou v hierarchii alespoň na úrovni min_role.
Pokud to_rights!=None, tak vyplní existující objekt typu Rights.
"""
Pokud min_role!=None, tak se uvažují jen role, které jsou v hierarchii alespoň na úrovni min_role.
"""
cache_key
=
(
place
.
place_id
if
place
is
not
None
else
None
,
year
,
cat
,
seq
,
min_role
)
#
if cache_key in self.rights_cache:
#
return self.rights_cache[cache_key]
if
cache_key
in
self
.
rights_cache
:
return
self
.
rights_cache
[
cache_key
]
rights
=
to_rights
or
Rights
()
rights
=
Rights
()
rights
.
user
=
self
.
user
rights
.
user_roles
=
[]
rights
.
rights
=
set
()
...
...
@@ -354,29 +357,27 @@ class Gatekeeper:
place
=
db
.
get_root_place
()
rights
=
RoundRights
()
rights
.
round
=
round
self
.
rights_for
(
rights
.
_clone_from
(
self
.
rights_for
(
place
=
place
,
year
=
round
.
year
,
cat
=
round
.
category
,
seq
=
round
.
seq
,
to_rights
=
rights
,
)
))
return
rights
def
rights_for_contest
(
self
,
contest
:
db
.
Contest
,
site
:
Optional
[
db
.
Place
]
=
None
)
->
ContestRights
:
rights
=
ContestRights
()
rights
.
contest
=
contest
self
.
rights_for
(
rights
.
_clone_from
(
self
.
rights_for
(
place
=
site
or
contest
.
place
,
year
=
contest
.
round
.
year
,
cat
=
contest
.
round
.
category
,
seq
=
contest
.
round
.
seq
,
to_rights
=
rights
,
)
))
return
rights
def
can_set_role
(
self
,
role
:
db
.
UserRole
):
# We will use
get
_for but we need to slightly modify its behavior. Can
# We will use
rights
_for but we need to slightly modify its behavior. Can
# set role with * year only if current user has role with * year, thus we
# need to pass year=0 for * year (cat and seq similarly).
rights
=
self
.
rights_for
(
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment