Filter teams by creator: users only see and manage their own teams

This commit is contained in:
2026-06-07 07:23:47 -04:00
parent 5607a3e507
commit e721a34d8f
2 changed files with 31 additions and 13 deletions

View File

@@ -29,7 +29,8 @@ class TeamController
public function index(): void
{
$teams = $this->teamModel->findAll();
$userId = (int) Session::get('user_id');
$teams = $this->teamModel->findByCreator($userId);
$this->view->display('teams.index', [
'title' => 'Teams - ServerManager',
@@ -72,9 +73,10 @@ class TeamController
public function show(int $id): void
{
$userId = (int) Session::get('user_id');
$team = $this->teamModel->findById($id);
if (!$team) {
if (!$team || (int) $team['created_by'] !== $userId) {
$this->view->error(404);
}
@@ -103,9 +105,10 @@ class TeamController
public function update(int $id): void
{
$userId = (int) Session::get('user_id');
$team = $this->teamModel->findById($id);
if (!$team) {
if (!$team || (int) $team['created_by'] !== $userId) {
$this->view->json(['success' => false, 'message' => 'Team not found'], 404);
}
@@ -133,9 +136,10 @@ class TeamController
public function delete(int $id): void
{
$userId = (int) Session::get('user_id');
$team = $this->teamModel->findById($id);
if (!$team) {
if (!$team || (int) $team['created_by'] !== $userId) {
$this->view->json(['success' => false, 'message' => 'Team not found'], 404);
}
@@ -151,9 +155,10 @@ class TeamController
public function addUser(int $id): void
{
$userId = (int) Session::get('user_id');
$team = $this->teamModel->findById($id);
if (!$team) {
if (!$team || (int) $team['created_by'] !== $userId) {
$this->view->json(['success' => false, 'message' => 'Team not found'], 404);
}
@@ -174,9 +179,10 @@ class TeamController
public function removeUser(int $id): void
{
$userId = (int) Session::get('user_id');
$team = $this->teamModel->findById($id);
if (!$team) {
if (!$team || (int) $team['created_by'] !== $userId) {
$this->view->json(['success' => false, 'message' => 'Team not found'], 404);
}
@@ -196,9 +202,10 @@ class TeamController
public function addServer(int $id): void
{
$userId = (int) Session::get('user_id');
$team = $this->teamModel->findById($id);
if (!$team) {
if (!$team || (int) $team['created_by'] !== $userId) {
$this->view->json(['success' => false, 'message' => 'Team not found'], 404);
}
@@ -232,9 +239,10 @@ class TeamController
public function removeServer(int $id): void
{
$userId = (int) Session::get('user_id');
$team = $this->teamModel->findById($id);
if (!$team) {
if (!$team || (int) $team['created_by'] !== $userId) {
$this->view->json(['success' => false, 'message' => 'Team not found'], 404);
}
@@ -254,9 +262,10 @@ class TeamController
public function updateServerRole(int $id): void
{
$userId = (int) Session::get('user_id');
$team = $this->teamModel->findById($id);
if (!$team) {
if (!$team || (int) $team['created_by'] !== $userId) {
$this->view->json(['success' => false, 'message' => 'Team not found'], 404);
}