Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TA: Re-implement team invitations in API #377

Open
Jayden876212 opened this issue Jul 4, 2024 · 0 comments
Open

TA: Re-implement team invitations in API #377

Jayden876212 opened this issue Jul 4, 2024 · 0 comments
Labels
backend API or backend work feature: teams structure feature New business value from new capabilities frontend UI or frontend work

Comments

@Jayden876212
Copy link
Collaborator

Invitations

URL Patterns (in urls.py)

    path("teams/join/apply/<int:id>/<str:response>", invites.joining_team_request, name="joining_team_request"),
    path("teams/invite/", invites.view_invites, name="view_invites"),
    path("teams/invite/<int:team_id>/<int:user_id>/<str:role>", invites.team_invite, name="team_invite"),

Code (in invites.py)

@login_required
def team_invite(request, team_id, user_id, role):
    find_team = Team.objects.get(id=team_id)
    find_user = User.objects.get(id=user_id)
    find_role = Role.objects.get(role=role)

    test = Relationship.objects.filter(team=find_team)

    # Boolean determines if viewer is in this team trying to invite others
    user_acceptable = False
    for rel in test:
        if rel.user == request.user and str(rel.role) == "Owner":
            user_acceptable = True
            break

    if str(request.user.id) != str(user_id) and user_acceptable:
        Relationship.objects.create(
            user=find_user,
            team=find_team,
            role=find_role,
            status=Status.objects.get(status="Invited"),
        )
        return redirect(f"/teams/calendar/{find_team.id}")
    # Else user is manipulating the URL making non-allowed invites - (Therefore doesn't create a relationship)

    return redirect("dashboard")


@login_required
def view_invites(request):
    all_invites = Relationship.objects.filter(
        user=request.user, status=Status.objects.get(status="Invited")
    )
    return render(request, "teams/invites.html", {"invites": all_invites})

Description

The invite button currently does nothing:

image
image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend API or backend work feature: teams structure feature New business value from new capabilities frontend UI or frontend work
Projects
None yet
Development

No branches or pull requests

1 participant