Skip to content

Commit

Permalink
Improve current project setting flow
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Jul 26, 2024
1 parent 47a8ee6 commit 3cf5c54
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 21 deletions.
11 changes: 10 additions & 1 deletion app/Core/Middleware/CurrentProject.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace Leantime\Core\Middleware;

use Closure;
use Leantime\Core\Frontcontroller;
use Leantime\Core\HtmxRequest;
use Leantime\Core\IncomingRequest;
use Leantime\Domain\Auth\Services\Auth as AuthService;
use Leantime\Domain\Projects\Services\Projects as ProjectService;
Expand All @@ -18,8 +20,15 @@ class CurrentProject
**/
public function handle(IncomingRequest $request, Closure $next): Response
{

if (app()->make(AuthService::class)->loggedIn()) {
app()->make(ProjectService::class)->setCurrentProject();

$actionPath = Frontcontroller::getModuleName();

//Only change/set project if the request is not htmx, api or cron
if (!($request instanceof HtmxRequest) && $actionPath != 'api' && $actionPath != 'cron') {
app()->make(ProjectService::class)->setCurrentProject();
}
}

return $next($request);
Expand Down
27 changes: 12 additions & 15 deletions app/Core/Middleware/StartSession.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,16 @@
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Date;
use Leantime\Core\Eventhelpers;
use Leantime\Core\Frontcontroller;
use Leantime\Core\IncomingRequest;
use Symfony\Component\HttpFoundation\Cookie;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Encryption\Encrypter;

class StartSession
{

use Eventhelpers;

/**
* The session manager.
*
Expand Down Expand Up @@ -64,33 +65,29 @@ public function handle(IncomingRequest $request, Closure $next)

self::dispatch_event('session_initialized');

//Enable session locking by default
//We have too many async requests with session write requests creating all sorts of odd behavior
//if session locking is not enabled
return $this->handleRequestWhileBlocking($request, $session, $next);
}

/**
* Handle the given request within session state.
*
* @param IncomingRequest $request
* @param \Illuminate\Contracts\Session\Session $session
* @param \Closure $next
* @param IncomingRequest $request
* @param \Illuminate\Contracts\Session\Session $session
* @param \Closure $next
* @return mixed
*/
protected function handleRequestWhileBlocking(IncomingRequest $request, $session, Closure $next) {

protected function handleRequestWhileBlocking(IncomingRequest $request, $session, Closure $next)
{

$lockFor = $this->manager->defaultRouteBlockLockSeconds();

$lock = Cache::store("installation")
->lock('session:'.$session->getId(), $lockFor)
$lock = $this->cache("installation")
->lock('session:' . $session->getId(), $lockFor)
->betweenBlockedAttemptsSleepFor(50);

try {
$lock->block(
$this->manager->defaultRouteBlockWaitSeconds()
);
//Acquire lock every 50ms for 20 seconds
$lock->block(20);

return $this->handleStatefulRequest($request, $session, $next);
} finally {
Expand Down Expand Up @@ -303,6 +300,6 @@ protected function sessionIsPersistent(?array $config = null)
*/
protected function cache($driver)
{
return call_user_func($this->cacheFactoryResolver)->driver($driver);
return Cache::store($driver);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
<span class="fa fa-trash"></span> <?php echo $tpl->__('links.delete') ?>
</a></li>
<?php } ?>
<?php if (($row['userId'] == $_SESSION['userdata']['id']) || $login::userIsAtLeast($roles::$manager)) { ?>
<?php if (($row['userId'] == session('userdata.id')) || $login::userIsAtLeast($roles::$manager)) { ?>
<li>
<a href="javascript:void(0);" onclick="toggleCommentBoxes(<?php echo $row['id']; ?>, null, '<?=$formHash?>', true)">
<span class="fa fa-edit"></span> <?php echo $tpl->__('label.edit') ?>
Expand Down
2 changes: 1 addition & 1 deletion app/Domain/Projects/Hxcontrollers/ProjectCardProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function init(

public function getProgress() {

$projectId = $_GET['projectId'];
$projectId = $_GET['pId'];

$project = array("id" => $projectId);

Expand Down
7 changes: 7 additions & 0 deletions app/Domain/Projects/Services/Projects.php
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,13 @@ public function changeCurrentSessionProject($projectId): bool

$projectId = (int)$projectId;

if (
session()->exists("currentProject") &&
session("currentProject") == $projectId
) {
return true;
}

session(["currentProjectName" => '']);

if ($this->isUserAssignedToProject(session("userdata.id"), $projectId) === true) {
Expand Down
4 changes: 1 addition & 3 deletions app/Domain/Projects/Templates/partials/projectCard.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
'type' => 'simple'
])



<div class="projectBox" id="projectBox-{{ $project['id'] }}">
<div class="row" >
<div class="col-md-12 fixed">
Expand Down Expand Up @@ -42,7 +40,7 @@ class="favoriteClick favoriteStar pull-right margin-right {{ $project['isFavorit

@if($type != "simple")
<div id="projectProgressBox-{{ $project['id'] }}"
hx-get="{{ BASE_URL }}/hx/projects/projectCardProgress/getProgress?projectId={{ $project['id'] }}"
hx-get="{{ BASE_URL }}/hx/projects/projectCardProgress/getProgress?pId={{ $project['id'] }}"
hx-trigger="load"
hx-swap="innerHTML"
hx-target="#projectProgressBox-{{ $project['id'] }}"
Expand Down

0 comments on commit 3cf5c54

Please sign in to comment.