-
Notifications
You must be signed in to change notification settings - Fork 0
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
Expanded actions for friends to allow for invitations to games, invitations to tournaments #199
Open
ishiii-s
wants to merge
25
commits into
dev
Choose a base branch
from
users/friends-actions
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
cd62f2f
Update urls.py for remove, tournament, and game paths
ishiii-s c75d6aa
Wrote invitation classes for match and tournament
ishiii-s aa4bf56
Wrote functions to remove friend, invite to game, and invite to tourn…
ishiii-s 1b4bf2d
Update Tournament and Match definitions in views.py
ishiii-s 68266dc
Update models.py to deal with circular dependencies
ishiii-s c484edb
Merge branch 'dev' into users/friends-actions
ishiii-s b485e33
Update models.py to try to fix circular imports
ishiii-s a45bf4b
Attempt to fix error for invalid model reference
ishiii-s 418205c
Remove remove friend functionality
24raniwalar bb34f6e
Forgot to remove url
24raniwalar f7bc774
Needed to migrate
24raniwalar 26278aa
Merge branch 'dev' into users/friends-actions
ishiii-s a4b7378
Fix resulting errors from resolve merge conflicts urls.py
ishiii-s 56fe98c
Merge branch 'dev' into users/friends-actions
AndrewM131 6fa6bfa
fixed merge conflicts
6b34dec
fixed linting issues
5cedea3
fixed pytest issues
2469b37
fixed merge
a330f31
fixed lint
60c3102
added try/except and pk to url
b6dc528
Merge branch 'dev' into users/friends-actions
5e0476e
fixed pk
55ead9c
working tournament invite now
a1e9f5e
Merge branch 'dev' into users/friends-actions
5849ec5
fixed accidentally modified url path
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
src/chigame/users/migrations/0004_tournamentinvitation_gameinvitation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Generated by Django 4.2.4 on 2023-12-03 02:40 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("games", "0016_update_tournaments_2"), | ||
("users", "0003_merge_20231115_1525"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="TournamentInvitation", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("accepted", models.BooleanField(default=False)), | ||
("timestamp", models.DateTimeField(auto_now_add=True)), | ||
( | ||
"receiver", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="tournament_invitations_received", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
( | ||
"sender", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="tournament_invitations_sent", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
("tournament", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="games.tournament")), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="GameInvitation", | ||
fields=[ | ||
("id", models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name="ID")), | ||
("accepted", models.BooleanField(default=False)), | ||
("timestamp", models.DateTimeField(auto_now_add=True)), | ||
("match", models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to="games.match")), | ||
( | ||
"receiver", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="game_invitations_received", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
( | ||
"sender", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="game_invitations_sent", | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Generated by Django 4.2.4 on 2023-12-05 23:48 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("users", "0004_tournamentinvitation_gameinvitation"), | ||
("users", "0005_alter_user_username"), | ||
] | ||
|
||
operations = [] |
15 changes: 15 additions & 0 deletions
15
src/chigame/users/migrations/0007_delete_gameinvitation.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Generated by Django 4.2.4 on 2023-12-06 21:54 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("users", "0006_merge_20231205_1748"), | ||
] | ||
|
||
operations = [ | ||
migrations.DeleteModel( | ||
name="GameInvitation", | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
|
||
from chigame.games.models import Lobby, Player, Tournament | ||
|
||
from .models import FriendInvitation, Notification, UserProfile | ||
from .models import FriendInvitation, Notification, TournamentInvitation, UserProfile | ||
from .tables import FriendsTable, UserTable | ||
|
||
User = get_user_model() | ||
|
@@ -185,6 +185,18 @@ def cancel_friend_invitation(request, pk): | |
|
||
|
||
@login_required | ||
def invite_to_tournament(request, pk, tournament_pk): | ||
try: | ||
sender = get_object_or_404(User, pk=request.user.id) | ||
receiver = get_object_or_404(User, pk=pk) | ||
tournament = get_object_or_404(Tournament, pk=tournament_pk) | ||
TournamentInvitation.objects.create(sender=sender, receiver=receiver, tournament=tournament) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Along with the check on user id, the invitation object should only be created if that check succeeds. |
||
messages.success(request, "Invitation to tournament sent successfully.") | ||
except Exception as e: | ||
messages.error(request, f"Error: {str(e)}") | ||
return redirect(reverse("users:user-profile", kwargs={"pk": request.user.pk})) | ||
|
||
|
||
def accept_friend_invitation(request, pk): | ||
try: | ||
friendship = FriendInvitation.objects.get(pk=pk) | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to do one more check where sender and receiver are not the same. You shouldn't be able to send an invite to yourself.