Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,17 @@ public function __construct(PlanningProgressController $progressCalculator)
public function index()
{
$user = auth()->user();
$projects_relation = $user->projects;


// Buscar todos os projetos do usuário
$all_projects = $user->projects;

// Filtrar apenas projetos com status 'accepted' ou null
$projects_relation = $all_projects->filter(function($project) {
$pivotStatus = $project->pivot->status ?? null;
return $pivotStatus === 'accepted' || $pivotStatus === null;
});

// Buscar projetos onde o usuário é o proprietário
$projects = Project::where('id_user', $user->id)->get();
$merged_projects = $projects_relation->merge($projects);

Expand Down Expand Up @@ -89,7 +98,7 @@ public function store(ProjectStoreRequest $request)
$activity = "Created the project ".$project->title;
ActivityLogHelper::insertActivityLog($activity, 1, $project->id_project, $user->id);

$project->users()->attach($project->id_project, ['id_user' => $user->id, 'level' => 1]);
$project->users()->attach($project->id_project, ['id_user' => $user->id, 'level' => 1, 'status' => 'accepted']);

return redirect('/projects');
}
Expand Down Expand Up @@ -217,7 +226,7 @@ public function destroy_member(string $idProject, $idMember)
public function add_member(string $idProject)
{
$project = Project::findOrFail($idProject);
$users_relation = $project->users()->get();
$users_relation = $project->users()->withPivot('level', 'status', 'invitation_token')->get();
$user = Auth::user();

if (!$project->userHasLevel($user, '1')) {
Expand Down Expand Up @@ -322,10 +331,11 @@ public function acceptInvitation($idProject, Request $request)
{
$token = $request->query('token');

// Busca o registro na tabela 'members'
// Verifica se o token é válido e pertence ao projeto
$invitation = DB::table('members')
->where('invitation_token', $token)
->where('id_project', $idProject)
->where('status', 'pending') // Adicionar verificação de status pendente
->first();

if (!$invitation) {
Expand Down
24 changes: 21 additions & 3 deletions app/Models/Project.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,20 @@ public function generalScores()

public function setUserLevel(User $user)
{
$this->user_level = $this->users()
$member = $this->users()
->where('users.id', $user->id)
->first();

if ($member) {
$status = $member->pivot->status ?? null;
if ($status === 'accepted' || $status === null) {
$this->user_level = $member;
} else {
$this->user_level = null;
}
} else {
$this->user_level = null;
}
}

private function insertSearchStringGenerics($idProject)
Expand Down Expand Up @@ -244,10 +255,17 @@ public function copyPlanningFrom(Project $sourceProject)

public function userHasLevel(User $user, string $level): bool
{
return $this->users()
$member = $this->users()
->wherePivot('id_user', $user->id)
->wherePivot('level', $level)
->exists();
->first();

if (!$member) {
return false;
}

$status = $member->pivot->status ?? null;
return $status === 'accepted' || $status === null;
}

public function markAsFinished()
Expand Down
3 changes: 2 additions & 1 deletion app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ class User extends Authenticatable
// Relacionamento com projetos através da tabela `members`
public function projects()
{
return $this->belongsToMany(Project::class, 'members', 'id_user', 'id_project');
return $this->belongsToMany(Project::class, 'members', 'id_user', 'id_project')
->withPivot('level', 'status', 'invitation_token');
}

// Relacionamento com projetos com nível de acesso específico (usando o campo `level`)
Expand Down
1 change: 0 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
|
*/

'locale' => 'en',
'locale' => 'pt_BR',

/*
Expand Down
6 changes: 5 additions & 1 deletion lang/en/pages/add_member.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
'enter_email' => 'Enter The email',
'select_level' => 'Select level',
'name' => 'Name',
'email' => 'Email',
'delete' => 'Delete',
'instruction_email' => 'Instruction help for enter e-mail',
//insruction level
Expand All @@ -27,7 +28,10 @@
'level_administrator' => 'Level Administrator:',
'level_administrator_description' => 'The administrator level has permissions to edit, delete, view and add members through the project correlated to it.',
'admin' => 'Administrator',

'status_accepted' => 'Accepted',
'status_pending' => 'Pending',
'status_declined' => 'Declined',
'status' => 'Status',
];

?>
6 changes: 5 additions & 1 deletion lang/pt_BR/pages/add_member.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
'enter_email' => 'Digite o e-mail',
'select_level' => 'Selecione o nível',
'name' => 'Nome',
'email' => 'E-mail',
'delete' => 'Excluir',
'instruction_email' => 'Ajuda de instrução para inserir e-mail',
// //insruction level
Expand All @@ -28,7 +29,10 @@
'level_reviser_description' => 'O nível de revisor possui permissões para visualizar e editar dados.',
'le',
'admin' => 'Administrador',

'status_accepted' => 'Aceito',
'status_pending' => 'Pendente',
'status_declined' => 'Recusado',
'status' => 'Status',
];

?>
Loading
Loading