Skip to content

Project #3

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
Empty file modified .editorconfig
100644 → 100755
Empty file.
Empty file modified .env.example
100644 → 100755
Empty file.
Empty file modified .gitattributes
100644 → 100755
Empty file.
Empty file modified .gitignore
100644 → 100755
Empty file.
Empty file modified README.md
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/AuthenticatedSessionController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/ConfirmablePasswordController.php
100644 → 100755
Empty file.
Empty file.
Empty file modified app/Http/Controllers/Auth/EmailVerificationPromptController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/NewPasswordController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/PasswordController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/PasswordResetLinkController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/RegisteredUserController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Auth/VerifyEmailController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/Controller.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/DashboardController.php
100644 → 100755
Empty file.
Empty file modified app/Http/Controllers/ProfileController.php
100644 → 100755
Empty file.
92 changes: 92 additions & 0 deletions app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<?php

namespace App\Http\Controllers;

use App\Models\Project;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;

class ProjectController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
$team = Auth::user()->currentTeam;
$projects = $team->projects()->latest()->paginate(10);
return view('projects.index', compact('projects'));
}

/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('projects.create');
}

/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$validated = $request->validate([
'title' => 'required|string|max:255',
]);

$project = Auth::user()->currentTeam->projects()->create($validated);

return redirect()->route('projects.show', $project)
->with('success', 'Project created successfully.');
}

/**
* Display the specified resource.
*/
public function show(Project $project)
{
Gate::authorize('view', $project);
return view('projects.show', compact('project'));
}

/**
* Show the form for editing the specified resource.
*/
public function edit(Project $project)
{
Gate::authorize('update', $project);
return view('projects.edit', compact('project'));
}

/**
* Update the specified resource in storage.
*/
public function update(Request $request, Project $project)
{
Gate::authorize('update', $project);

$validated = $request->validate([
'title' => 'required|string|max:255',
]);

$project->update($validated);

return redirect()->route('projects.show', $project)
->with('success', 'Project updated successfully.');
}

/**
* Remove the specified resource from storage.
*/
public function destroy(Project $project)
{
Gate::authorize('delete', $project);

$project->delete();

return redirect()->route('projects.index')
->with('success', 'Project deleted successfully.');
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/TeamController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public function setCurrent(SetCurrentTeamRequest $request, Team $team)
public function edit(Request $request)
{
return view('team.edit', [
'team' => $request->user()->currentTeam
'team' => $request->user()->currentTeam,
]);
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/TeamInviteController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function store(TeamInviteStoreRequest $request, Team $team)
{
$invite = $team->invites()->create([
'email' => $request->email,
'token' => str()->random(30)
'token' => str()->random(30),
]);

Mail::to($request->email)->send(new TeamInvitation($invite));
Expand Down
1 change: 0 additions & 1 deletion app/Http/Controllers/TeamMemberController.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
use App\Http\Requests\TeamMemberUpdateRequest;
use App\Models\Team;
use App\Models\User;
use Illuminate\Http\Request;

class TeamMemberController extends Controller
{
Expand Down
Empty file modified app/Http/Middleware/TeamsPermission.php
100644 → 100755
Empty file.
Empty file modified app/Http/Requests/Auth/LoginRequest.php
100644 → 100755
Empty file.
Empty file modified app/Http/Requests/ProfileUpdateRequest.php
100644 → 100755
Empty file.
Empty file modified app/Http/Requests/SetCurrentTeamRequest.php
100644 → 100755
Empty file.
Empty file modified app/Http/Requests/TeamInviteDestroyRequest.php
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions app/Http/Requests/TeamInviteStoreRequest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function rules(): array
'email',
'max:255',
Rule::unique(TeamInvite::class, 'email')
->where('team_id', $this->team->id)
]
->where('team_id', $this->team->id),
],
];
}
}
Empty file modified app/Http/Requests/TeamLeaveRequest.php
100644 → 100755
Empty file.
Empty file modified app/Http/Requests/TeamMemberDestroyRequest.php
100644 → 100755
Empty file.
4 changes: 2 additions & 2 deletions app/Http/Requests/TeamMemberUpdateRequest.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function rules(): array
return [
'role' => [
'nullable',
Rule::exists('roles', 'name')
]
Rule::exists('roles', 'name'),
],
];
}
}
Empty file modified app/Http/Requests/TeamUpdateRequest.php
100644 → 100755
Empty file.
3 changes: 1 addition & 2 deletions app/Mail/TeamInvitation.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\TeamInvite;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
Expand Down Expand Up @@ -35,7 +34,7 @@ public function __construct(public TeamInvite $teamInvite)
public function envelope(): Envelope
{
return new Envelope(
subject: 'You have been invited to the ' . $this->teamInvite->team->name . ' team',
subject: 'You have been invited to the '.$this->teamInvite->team->name.' team',
);
}

Expand Down
43 changes: 43 additions & 0 deletions app/Models/Project.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,57 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use App\Models\Team;
use App\Models\Task;

class Project extends Model
{
/** @use HasFactory<\Database\Factories\ProjectFactory> */
use HasFactory;

protected $fillable = [
'title',
'team_id',
'completion_percentage',
];

protected $casts = [
'completion_percentage' => 'decimal:2',
'uuid' => 'string',
];

protected static function boot()
{
parent::boot();

static::creating(function ($model) {
$model->uuid = Str::uuid();
});
}

public function getRouteKeyName()
{
return 'uuid';
}

public function team()
{
return $this->belongsTo(Team::class);
}

public function tasks()
{
return $this->hasMany(Task::class);
}

public function updateCompletionPercentage()
{
$totalTasks = $this->tasks()->count();
if ($totalTasks > 0) {
$completedTasks = $this->tasks()->where('completed', true)->count();
$this->completion_percentage = ($completedTasks / $totalTasks) * 100;
$this->save();
}
}
}
4 changes: 4 additions & 0 deletions app/Models/Team.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\Project;
use App\Models\User;
use App\Models\TeamInvite;

class Team extends Model
{
Expand All @@ -26,4 +29,5 @@ public function projects()
{
return $this->hasMany(Project::class);
}

}
Empty file modified app/Models/TeamInvite.php
100644 → 100755
Empty file.
Empty file modified app/Models/TeamUser.php
100644 → 100755
Empty file.
25 changes: 23 additions & 2 deletions app/Models/User.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class User extends Authenticatable
{
/** @use HasFactory<\Database\Factories\UserFactory> */
use HasFactory, Notifiable;

use HasRoles;

/**
Expand Down Expand Up @@ -49,12 +50,14 @@ protected function casts(): array

public function profilePhotoUrl()
{
return 'https://gravatar.com/avatar/' . md5($this->email) . '?s=100';
return 'https://gravatar.com/avatar/'.md5($this->email).'?s=100';
}

public function teams()
{
return $this->belongsToMany(Team::class);
return $this->belongsToMany(Team::class)
->withPivot('role')
->withTimestamps();
}

public function currentTeam()
Expand All @@ -73,4 +76,22 @@ public function projects()
'team_id'
);
}

public function belongsToTeam($team): bool
{
return $this->teams()->where('team_id', $team->id)->exists();
}

public function hasTeamPermission($team, string $permission): bool
{
if ($this->hasRole('admin')) {
return true;
}

$teamUser = $this->teams()
->where('team_id', $team->id)
->first();

return $teamUser && $teamUser->pivot->role === 'admin';
}
}
Empty file modified app/Observers/UserObserver.php
100644 → 100755
Empty file.
68 changes: 68 additions & 0 deletions app/Policies/ProjectPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

namespace App\Policies;

use App\Models\Project;
use App\Models\User;
use Illuminate\Auth\Access\Response;

class ProjectPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
return true;
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, Project $project): bool
{
return $user->belongsToTeam($project->team);
}

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
return true;
}

/**
* Determine whether the user can update the model.
*/
public function update(User $user, Project $project): bool
{
return $user->belongsToTeam($project->team) &&
$user->hasTeamPermission($project->team, 'update');
}

/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, Project $project): bool
{
return $user->belongsToTeam($project->team) &&
$user->hasTeamPermission($project->team, 'delete');
}

/**
* Determine whether the user can restore the model.
*/
public function restore(User $user, Project $project): bool
{
return false;
}

/**
* Determine whether the user can permanently delete the model.
*/
public function forceDelete(User $user, Project $project): bool
{
return false;
}
}
4 changes: 2 additions & 2 deletions app/Policies/TeamPolicy.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function setCurrent(User $user, Team $team)

public function update(User $user, Team $team)
{
if (!$user->teams->contains($team)) {
if (! $user->teams->contains($team)) {
return false;
}

Expand All @@ -23,7 +23,7 @@ public function update(User $user, Team $team)

public function leave(User $user, Team $team)
{
if (!$user->teams->contains($team)) {
if (! $user->teams->contains($team)) {
return false;
}

Expand Down
Empty file modified app/Providers/AppServiceProvider.php
100644 → 100755
Empty file.
Empty file modified app/View/Components/AppLayout.php
100644 → 100755
Empty file.
Empty file modified app/View/Components/GuestLayout.php
100644 → 100755
Empty file.
5 changes: 3 additions & 2 deletions app/helpers.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php

if (!function_exists('team')) {
function team() {
if (! function_exists('team')) {
function team()
{
return request()->team();
}
}
Empty file modified bootstrap/app.php
100644 → 100755
Empty file.
Empty file modified bootstrap/cache/.gitignore
100644 → 100755
Empty file.
Empty file modified bootstrap/providers.php
100644 → 100755
Empty file.
Loading