Verified Commit 69554be8 authored by Peter Stanko's avatar Peter Stanko
Browse files

When you can create submissions again

parent 5cafc511
Pipeline #17288 passed with stage
in 11 minutes and 10 seconds
......@@ -166,8 +166,8 @@ class UserProjectsList(CustomResource):
user = self.find.user(uid)
# authorization
self.permissions().require.sysadmin_or_self(uid)
projects = self.rest.users(user).find_all_projects_for_user()
return SCHEMAS.dump('projects', projects)
projects_dump = self.rest.users(user).dump_projects_with_wait()
return projects_dump
@users_namespace.route('/<string:uid>/groups')
......
......@@ -165,7 +165,7 @@ class ProjectService(GeneralService):
raise errors.SubmissionDiffTimeError(self.project, diff_time, user=user)
return True
def get_latest_submission(self, user, ignore_cancel: bool=False) -> Submission:
def get_latest_submission(self, user, ignore_cancel: bool = False) -> Submission:
query = Submission.query.filter(
(Submission.user == user) & (Submission.project == self.project))
if ignore_cancel:
......@@ -190,3 +190,11 @@ class ProjectService(GeneralService):
""" Sends a request to Storage to update the project's test_files to the newest version.
"""
tasks.update_project_test_files.delay(self.project.course.id, self.project.id)
def calculate_wait_time(self, user: User) -> datetime.datetime:
latest_submission = self.get_latest_submission(user, ignore_cancel=True)
if not latest_submission:
return time.current_time()
latest_time = latest_submission.created_at
delta = datetime.timedelta(minutes=30)
return latest_time + delta
......@@ -2,10 +2,11 @@
Users service
"""
from typing import List, Optional
from typing import List, Optional, Union
from portal import ldap_wrapper, logger
from portal.database.models import Course, Group, Project, Review, Role, Submission, User
from portal.rest.schemas import SCHEMAS
from portal.service import emails
from portal.service.errors import IncorrectCredentialsError, PortalAPIError
from portal.service.general import GeneralService
......@@ -246,4 +247,16 @@ class UserService(GeneralService):
return submissions
def find_all_projects_for_user(self):
return self.user.get_all_projects()
all_projects = self.user.get_all_projects()
return all_projects
def dump_projects_with_wait(self):
all_projects = self.find_all_projects_for_user()
projects_dump = []
for project in all_projects:
dump = SCHEMAS.dump('project', project)
dump['next_time'] = \
self._rest_service.projects(project).calculate_wait_time(self.user).isoformat()
projects_dump.append(dump)
return projects_dump
......@@ -270,8 +270,7 @@ def test_read_groups_filter_course(client):
user = User.query.filter_by(username="student2").first()
groups = [
group for group in user.groups if group.course.codename == "testcourse1"]
response = rest_tools.make_request(client, f"/users/{user.id}/groups?course=testcourse1",
method='get')
response = rest_tools.make_request(client, f"/users/{user.id}/groups?course=testcourse1")
assert_response(response)
......@@ -296,3 +295,13 @@ def test_user_reviews(client):
assert len(user_reviews) == len(reviews)
# the test is incomplete - only print
print(f"user_reviews: {user_reviews}")
def test_user_projects(client):
user = User.query.filter_by(username="student2").first()
response = rest_tools.make_request(client, f"/users/{user.id}/projects")
assert_response(response)
user_projects = rest_tools.extract_data(response)
for proj in user_projects:
assert proj['next_time']
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment