Skip to content

Commit

Permalink
mf
Browse files Browse the repository at this point in the history
  • Loading branch information
mam10eks committed Dec 3, 2024
1 parent b26b6e1 commit e1e34d1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 25 deletions.
32 changes: 11 additions & 21 deletions application/src/tira_app/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,25 +276,15 @@ def get_vm_ids(self, request: HttpRequest, user_id=None):

return vms if len(vms) >= 1 else [Authentication.get_default_vm_id(user_id)]

def _create_discourse_vm_group(self, vm):
def _create_discourse_vm_group(self, team_name):
"""Create the vm group in the distaptor. Members of this group will be owners of the vm and
have all permissions.
:param vm: a vm dict as returned by tira_model.get_vm
{"vm_id", "user_password", "roles", "host", "admin_name", "admin_pw", "ip", "ssh", "rdp", "archived"}
have all permissions.
"""
group_bio = f"""Members of this group have access to the virtual machine {vm['vm_id']}:<br><br>
<ul>
<li>Host: {vm['host']}</li>
<li>User: {vm['vm_id']}</li>
<li>Passwort: {vm['user_password']}</li>
<li>SSH Port: {vm['ssh']}</li>
<li>RDP Port: {vm['rdp']}</li>
<li>SSH Example: <code>sshpass -p {vm['user_password']} ssh {vm['vm_id']}@{vm['host']} -p {vm['ssh']} -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no</code></li>
</ul><br><br>
Please contact us when you have questions.
"""
return self.discourse_client.create_group(f"tira_vm_{vm['vm_id']}", group_bio, 2)
group_bio = f"""Members of this team participate in shared tasks as {team_name}. <br><br>
Please do not hesitate to design your team's page accorging to your needs."""
return self.discourse_client.create_group(f"tira_vm_{team_name}", group_bio, 2)

def notify_organizers_of_new_participants(self, data, task_id):
task = model.get_task(task_id)
Expand Down Expand Up @@ -322,18 +312,18 @@ def notify_organizers_of_new_participants(self, data, task_id):
"tira_org_" + slugify(task["organizer"].lower()),
)

def create_group(self, vm):
def create_group(self, vm_id):
"""Create the vm group in the distaptor. Members of this group will be owners of the vm and
have all permissions.
:param vm: a vm dict as returned by tira_model.get_vm
:param vm_id: the name of the team.
"""
vm_group = self._create_discourse_vm_group(vm)
vm_group = self._create_discourse_vm_group(vm_id)
invite_link = self.discourse_client.create_invite_link(vm_group)
message = f"""Invite Mail: Please use this link to create your login for TIRA: {invite_link}.
After login to TIRA, you can find the credentials and usage examples for your
dedicated virtual machine {vm['vm_id']} here: https://www.tira.io/g/tira_vm_{vm['vm_id']}"""
dedicated virtual machine {vm_id} here: https://www.tira.io/g/tira_vm_{vm_id}"""

return message
return {"message": message, "invite_link": invite_link}

def create_organizer_group(self, organizer_name, user_name):
group_bio = f"""Members of this team organize shared tasks in TIRA as in shared tasks as {organizer_name}.
Expand Down
5 changes: 2 additions & 3 deletions application/src/tira_app/endpoints/admin_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,9 +577,8 @@ def admin_edit_organizer(request, organizer_id):
@check_resources_exist("json")
def admin_create_group(request, vm_id):
"""this is a rest endpoint to grant a user permissions on a vm"""
vm = model.get_vm(vm_id)
message = auth.create_group(vm)
return JsonResponse({"status": 0, "message": message})
context = auth.create_group(vm_id)
return JsonResponse({"status": 0, "context": context})


@check_conditional_permissions(restricted=True)
Expand Down
2 changes: 1 addition & 1 deletion application/src/tira_app/endpoints/v1/_anonymous.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def read_anonymous_submission(request: Request, submission_uuid: str) -> Respons
)


@api_view(["POST"])
@api_view(["POST", "GET"])
@check_permissions
def claim_submission(request: Request, vm_id: str, submission_uuid: str) -> Response:

Expand Down

0 comments on commit e1e34d1

Please sign in to comment.