Skip to content

Commit

Permalink
Merge pull request #44 from AERPAW-Platform-Control/version-1.0.0
Browse files Browse the repository at this point in the history
Version 1.0.0
  • Loading branch information
mjstealey authored Jan 24, 2023
2 parents 6fd1e48 + 652f7b8 commit 8a5aa55
Show file tree
Hide file tree
Showing 29 changed files with 673 additions and 175 deletions.
250 changes: 128 additions & 122 deletions portal/apps/experiments/api/experiment_utils.py

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions portal/apps/experiments/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from portal.apps.projects.models import AerpawProject
from portal.apps.resources.api.serializers import ResourceSerializerDetail
from portal.apps.resources.models import AerpawResource
from portal.apps.user_messages.user_messages import generate_user_messages_from_experiment_membership
from portal.apps.users.models import AerpawUser

# constants
Expand Down Expand Up @@ -518,10 +519,18 @@ def membership(self, request, *args, **kwargs):
membership.experiment = experiment
membership.user = user
membership.save()
# add experiment members message
generate_user_messages_from_experiment_membership(
request=request, experiment=experiment, experiment_members=experiment_members_added,
add=True)
for pk in experiment_members_removed:
membership = UserExperiment.objects.get(
experiment__id=experiment.id, user__id=pk)
membership.delete()
# remove experiment members message
generate_user_messages_from_experiment_membership(
request=request, experiment=experiment, experiment_members=experiment_members_removed,
add=False)
# End of PUT, PATCH section - All reqeust types return membership
serializer = ExperimentSerializerDetail(experiment)
du = dict(serializer.data)
Expand Down
55 changes: 42 additions & 13 deletions portal/apps/experiments/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,30 +21,54 @@ def check_initiate_development(user: AerpawUser, experiment: AerpawExperiment):
return True


def check_submit_to_sandbox():
def check_submit_to_sandbox(user: AerpawUser):
# TODO: define checks for submit to sandbox
# user has one or more public keys
if not PublicCredentials.objects.filter(
owner=user,
is_deleted=False
).exists():
return False
return False


def check_submit_to_emulation():
def check_submit_to_emulation(user: AerpawUser):
# TODO: define checks for submit to emulation
# user has one or more public keys
if not PublicCredentials.objects.filter(
owner=user,
is_deleted=False
).exists():
return False
return False


def check_submit_to_testbed(experiment: AerpawExperiment):
def check_submit_to_testbed(user: AerpawUser, experiment: AerpawExperiment):
"""
Experiment has completed at least one development cycle
Experiment has completed at least one successful development cycle at any point in time
- TODO: consider checking for most recent development session being successful
"""
# TODO: define checks for submit to testbed
session_obj = ExperimentSession.objects.filter(
# experiment has one or more resources
if not experiment.resources.exists():
return False
# user has one or more public keys
if not PublicCredentials.objects.filter(
owner=user,
is_deleted=False
).exists():
return False
# experiment has completed at least one successful development cycle
if not ExperimentSession.objects.filter(
experiment_id=experiment.id,
session_type=ExperimentSession.SessionType.DEVELOPMENT.value,
end_date_time__isnull=False
).order_by('-created').first()
if session_obj:
return True
else:
start_date_time__isnull=False,
started_by__isnull=False,
end_date_time__isnull=False,
ended_by__isnull=False
).order_by('-created').exists():
return False
return True


def get_dashboard_buttons(request, experiment_id: int) -> dict:
Expand Down Expand Up @@ -82,6 +106,11 @@ def get_dashboard_buttons(request, experiment_id: int) -> dict:
user = request.user
experiment = AerpawExperiment.objects.get(id=experiment_id)

# ensure user is a member of the experiment, or the creator of the experiment
if not experiment.is_member(user=user) and not experiment.is_creator(user=user):
# user is not a member and not the creator - return all buttons set to False
return buttons

# is_retired or is_deleted
if experiment.is_retired or experiment.is_deleted:
return buttons
Expand All @@ -105,11 +134,11 @@ def get_dashboard_buttons(request, experiment_id: int) -> dict:
# initiate development
buttons['b_dev_init'] = check_initiate_development(user=user, experiment=experiment)
# submit to sandbox
buttons['b_sandbox_submit'] = check_submit_to_sandbox()
buttons['b_sandbox_submit'] = check_submit_to_sandbox(user=user)
# submit to emulation
buttons['b_emu_submit'] = check_submit_to_emulation()
buttons['b_emu_submit'] = check_submit_to_emulation(user=user)
# submit to testbed
buttons['b_testbed_submit'] = check_submit_to_testbed(experiment=experiment)
buttons['b_testbed_submit'] = check_submit_to_testbed(user=user, experiment=experiment)
# SAVING_DEVELOPMENT - n/a
elif experiment.experiment_state == AerpawExperiment.ExperimentState.SAVING_DEVELOPMENT:
pass
Expand Down
2 changes: 1 addition & 1 deletion portal/apps/profiles/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
from rest_framework.request import QueryDict, Request

from portal.apps.credentials.api.viewsets import CredentialViewSet
from portal.apps.profiles.api.viewsets import UserProfileViewSet
from portal.apps.user_messages.api.viewsets import UserMessageViewSet
from portal.apps.user_requests.api.viewsets import UserRequestViewSet
from portal.apps.user_requests.models import AerpawUserRequest
from portal.apps.users.api.viewsets import UserViewSet
from portal.apps.users.models import AerpawRolesEnum, AerpawUser
from portal.server.download_utils import download_db_credential_public_key, download_db_user_tokens
from portal.server.settings import DEBUG
from portal.apps.profiles.api.viewsets import UserProfileViewSet


@csrf_exempt
Expand Down
17 changes: 17 additions & 0 deletions portal/apps/projects/api/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from portal.apps.experiments.models import AerpawExperiment
from portal.apps.projects.api.serializers import ProjectSerializerDetail, ProjectSerializerList, UserProjectSerializer
from portal.apps.projects.models import AerpawProject, UserProject
from portal.apps.user_messages.user_messages import generate_user_messages_from_project_membership
from portal.apps.users.models import AerpawUser

# constants
Expand Down Expand Up @@ -398,10 +399,18 @@ def membership(self, request, *args, **kwargs):
membership.project_role = UserProject.RoleType.PROJECT_MEMBER
membership.user = user
membership.save()
# add project members message
generate_user_messages_from_project_membership(
request=request, project=project, project_members=project_members_added,
add=True, membership_type='Member')
for pk in project_members_removed:
membership = UserProject.objects.get(
project__id=project.id, user__id=pk, project_role=UserProject.RoleType.PROJECT_MEMBER)
membership.delete()
# remove project members message
generate_user_messages_from_project_membership(
request=request, project=project, project_members=project_members_removed,
add=False, membership_type='Member')
if request.data.get('project_owners') or isinstance(request.data.get('project_owners'), list):
project_owners = request.data.get('project_owners')
if isinstance(project_owners, list) and all([isinstance(item, int) for item in project_owners]):
Expand All @@ -422,10 +431,18 @@ def membership(self, request, *args, **kwargs):
membership.project_role = UserProject.RoleType.PROJECT_OWNER
membership.user = user
membership.save()
# add project owners message
generate_user_messages_from_project_membership(
request=request, project=project, project_members=project_owners_added,
add=True, membership_type='Owner')
for pk in project_owners_removed:
membership = UserProject.objects.get(
project__id=project.id, user__id=pk, project_role=UserProject.RoleType.PROJECT_OWNER)
membership.delete()
# remove project owners message
generate_user_messages_from_project_membership(
request=request, project=project, project_members=project_owners_removed,
add=False, membership_type='Owner')
# End of PUT, PATCH section - All reqeust types return membership
serializer = ProjectSerializerDetail(project)
du = dict(serializer.data)
Expand Down
4 changes: 2 additions & 2 deletions portal/apps/projects/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@ class Meta:

class ProjectMembershipForm(forms.ModelForm):
project_members = forms.ModelMultipleChoiceField(
queryset=AerpawUser.objects.all().order_by('display_name'),
queryset=AerpawUser.objects.filter(groups__in=[1]).order_by('display_name'),
widget=FilteredSelectMultiple('Members', is_stacked=False),
required=False
)

project_owners = forms.ModelMultipleChoiceField(
queryset=AerpawUser.objects.all().order_by('display_name'),
queryset=AerpawUser.objects.filter(groups__in=[1]).order_by('display_name'),
widget=FilteredSelectMultiple('Owners', is_stacked=False),
required=False
)
Expand Down
Loading

0 comments on commit 8a5aa55

Please sign in to comment.