Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Alsijil
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Alsijil
Commits
72480a2e
Commit
72480a2e
authored
11 months ago
by
Hangzhi Yu
Browse files
Options
Downloads
Patches
Plain Diff
Add check for allowed time range preference when creating docs from dummy
parent
18ec1a4f
Loading
Loading
2 merge requests
!352
Draft: Resolve "Add dialog with each lesson's students"
,
!350
Resolve "Add simple course book list"
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
aleksis/apps/alsijil/schema/documentation.py
+42
-22
42 additions, 22 deletions
aleksis/apps/alsijil/schema/documentation.py
with
42 additions
and
22 deletions
aleksis/apps/alsijil/schema/documentation.py
+
42
−
22
View file @
72480a2e
from
datetime
import
datetime
,
timezone
from
django.core.exceptions
import
PermissionDenied
from
django.utils.timezone
import
localdate
,
localtime
import
graphene
from
graphene_django.types
import
DjangoObjectType
...
...
@@ -22,6 +23,7 @@ from aleksis.core.schema.base import (
PermissionBatchPatchMixin
,
PermissionsTypeMixin
,
)
from
aleksis.core.util.core_helpers
import
get_site_preferences
from
..models
import
Documentation
...
...
@@ -170,32 +172,50 @@ class DocumentationBatchCreateOrUpdateMutation(graphene.Mutation):
# Sadly, we can't use the update_or_create method since create_defaults
# is only introduced in Django 5.0
if
_id
.
startswith
(
"
DUMMY
"
):
dummy
,
lesson_event_id
,
datetime_start
,
datetime_end
=
_id
.
split
(
"
;
"
)
dummy
,
lesson_event_id
,
datetime_start
_iso
,
datetime_end
_iso
=
_id
.
split
(
"
;
"
)
lesson_event
=
LessonEvent
.
objects
.
get
(
id
=
lesson_event_id
)
if
not
info
.
context
.
user
.
has_perm
(
datetime_start
=
datetime
.
fromisoformat
(
datetime_start_iso
).
astimezone
(
lesson_event
.
timezone
)
datetime_end
=
datetime
.
fromisoformat
(
datetime_end_iso
).
astimezone
(
lesson_event
.
timezone
)
if
info
.
context
.
user
.
has_perm
(
"
alsijil.add_documentation_for_lesson_event_rule
"
,
lesson_event
)
and
(
get_site_preferences
()[
"
alsijil__allow_edit_future_documentations
"
]
==
"
all
"
or
(
get_site_preferences
()[
"
alsijil__allow_edit_future_documentations
"
]
==
"
current_day
"
and
datetime_start
.
date
()
<=
localdate
()
)
or
(
get_site_preferences
()[
"
alsijil__allow_edit_future_documentations
"
]
==
"
current_time
"
and
datetime_start
<=
localtime
()
)
):
raise
PermissionDenied
()
# Timezone removal is necessary due to ISO style offsets are no valid timezones.
# Instead, we take the timezone from the lesson_event and save it in a dedicated field.
obj
=
Documentation
.
objects
.
create
(
datetime_start
=
datetime
.
fromisoformat
(
datetime_start
).
astimezone
(
lesson_event
.
timezone
),
datetime_end
=
datetime
.
fromisoformat
(
datetime_end
).
astimezone
(
lesson_event
.
timezone
),
lesson_event
=
lesson_event
,
course
=
lesson_event
.
course
,
subject
=
lesson_event
.
subject
,
topic
=
doc
.
topic
or
""
,
homework
=
doc
.
homework
or
""
,
group_note
=
doc
.
group_note
or
""
,
)
if
doc
.
teachers
is
not
None
:
obj
.
teachers
.
add
(
*
doc
.
teachers
)
else
:
obj
.
teachers
.
set
(
lesson_event
.
teachers
.
all
())
obj
.
save
()
return
obj
# Timezone removal is necessary due to ISO style offsets are no valid timezones.
# Instead, we take the timezone from the lesson_event and save it in a dedicated field.
obj
=
Documentation
.
objects
.
create
(
datetime_start
=
datetime_start
,
datetime_end
=
datetime_end
,
lesson_event
=
lesson_event
,
course
=
lesson_event
.
course
,
subject
=
lesson_event
.
subject
,
topic
=
doc
.
topic
or
""
,
homework
=
doc
.
homework
or
""
,
group_note
=
doc
.
group_note
or
""
,
)
if
doc
.
teachers
is
not
None
:
obj
.
teachers
.
add
(
*
doc
.
teachers
)
else
:
obj
.
teachers
.
set
(
lesson_event
.
teachers
.
all
())
obj
.
save
()
return
obj
raise
PermissionDenied
()
else
:
obj
=
Documentation
.
objects
.
get
(
id
=
_id
)
...
...
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