Skip to content

Commit

Permalink
Sending a pusher notification when accepting an invite
Browse files Browse the repository at this point in the history
  • Loading branch information
thommcgrath committed Nov 3, 2024
1 parent 76df0ed commit 006ef74
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
19 changes: 2 additions & 17 deletions Website/api/v4/classes/ProjectInvite.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,21 +103,6 @@ public function IsExpired(): bool {
return $this->expirationDate < time();
}

protected static function UserIsAdmin(User $user, string $projectId): bool {
if (BeaconCommon::IsUUID($projectId) === false) {
return false;
}

$database = BeaconCommon::Database();
$rows = $database->Query('SELECT role FROM public.project_members WHERE user_id = $1 AND project_id = $2;', $user->UserId(), $projectId);
if ($rows->RecordCount() !== 1) {
return false;
}
$role = $rows->Field('role');

return $role === ProjectMember::kRoleOwner || $role === ProjectMember::kRoleAdmin;
}

public static function GetNewObjectPermissionsForUser(User $user, ?array $newObjectProperties): int {
if (is_null($newObjectProperties) || isset($newObjectProperties['projectId']) === false) {
return DatabaseObject::kPermissionNone;
Expand All @@ -135,7 +120,7 @@ public static function GetNewObjectPermissionsForUser(User $user, ?array $newObj
return DatabaseObject::kPermissionNone;
}

if ($desiredPermissions < $member->Permissions()) {
if ($member->IsAdmin() && $desiredPermissions < $member->Permissions()) {
return DatabaseObject::kPermissionAll;
} else {
return DatabaseObject::kPermissionNone;
Expand All @@ -152,7 +137,7 @@ public function GetPermissionsForUser(User $user): int {
} catch (Exception $err) {
return DatabaseObject::kPermissionNone;
}
if ($rolePermissions < $member->Permissions()) {
if ($member->IsAdmin() && $rolePermissions < $member->Permissions()) {
return DatabaseObject::kPermissionAll;
} else {
return DatabaseObject::kPermissionNone;
Expand Down
5 changes: 4 additions & 1 deletion Website/www/account/invite.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ function RedeemCode(string $code, bool $confirmed): void {
return;
}

$project = Project::Fetch($invite->ProjectId());

if ($confirmed) {
$database = BeaconCommon::Database();
$database->BeginTransaction();
Expand All @@ -85,10 +87,11 @@ function RedeemCode(string $code, bool $confirmed): void {
}
$database->Commit();

BeaconPusher::SharedInstance()->TriggerEvent($project->PusherChannelName(), 'members-updated', $member);

echo '<p class="text-center"><span class="text-blue">Project invite accepted!</span><br>You are now a member of the project.</p>';
} else {
// Show confirmation
$project = Project::Fetch($invite->ProjectId());
echo '<form action="/account/invite" method="post"><input type="hidden" name="process" value="invite-final"><input type="hidden" name="code" value="' . htmlentities($code) . '">';
echo '<p>This invite code will add you to the project &quot;' . htmlentities($project->Title()) . '&quot;</p>';
echo '<div class="double-group"><div>&nbsp;</div><div><div class="button-group"><div><a href="/account/invite" class="button">Cancel</a></div><div><input type="submit" value="Accept Invite"></div></div></div>';
Expand Down

0 comments on commit 006ef74

Please sign in to comment.