Skip to content
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
64 changes: 64 additions & 0 deletions app/Http/Controllers/SearchController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace App\Http\Controllers;

use App\Item;
use App\Search;
use App\Setting;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
Expand All @@ -12,6 +14,13 @@

class SearchController extends Controller
{
public function __construct()
{
parent::__construct();
// The item list exposes the user's apps, so it gets the dashboard gate
$this->middleware('allowed')->only('items');
}

/**
* @return Application|RedirectResponse|Redirector|mixed|void
*/
Expand Down Expand Up @@ -44,6 +53,61 @@ public function index(Request $request)
abort(404, 'Provider type not supported');
}

/**
* All apps the current user can see, pinned or not, for the quick launcher
*/
public function items(Request $request): JsonResponse
{
$query = Item::where('type', 0)->with('parents')->orderBy('order', 'asc');

if (config('app.auth_roles_enable')) {
$roles = explode(
config('app.auth_roles_delimiter'),
$request->header(config('app.auth_roles_header')) ?? ''
);
$query->whereIn('role', $roles);
}

$items = $query->get()->map(function (Item $app) {
return [
'id' => $app->id,
'title' => $app->title,
'url' => $app->link,
'colour' => $app->colour,
'icon' => $app->icon_url,
'tags' => $app->parents->where('id', '!=', 0)->pluck('title')->values(),
];
})->values();

// Web search fallback, unless the provider is the tile filter or search is off
$fallback = null;
if ((bool) Setting::fetch('homepage_search')) {
$provider = Setting::fetch('search_provider');
$details = $provider && $provider !== 'tiles' && $provider !== 'none'
? Search::providerDetails($provider)
: false;
if ($details) {
$fallback = ['provider' => $provider, 'name' => $details->name, 'url' => url('search')];
}
}

return response()->json([
'items' => $items,
'fallback' => $fallback,
'target' => $this->linkTarget(),
]);
}

/**
* The "Link opens in" setting as an anchor target
*/
private function linkTarget(): string
{
$target = Setting::fetch('window_target');

return in_array($target, [null, '', 'current'], true) ? '_self' : $target;
}

/**
* Get autocomplete suggestions for a search query
*
Expand Down
12 changes: 2 additions & 10 deletions app/Http/Middleware/CheckAllowed.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,11 @@ public function handle(Request $request, Closure $next): Response
}
}

// Continue with passwordless user
if (empty($current_user->password)) {
// Continue with a passwordless user, or one the visitor is logged in as
if ($current_user->isOpenToVisitor()) {
return $next($request);
}

// Check if user is logged in as $current_user
if (Auth::check()) {
$loggedin_user = Auth::user();
if ($loggedin_user->id === $current_user->getId()) {
return $next($request);
}
}

// Redirect to login
Auth::authenticate();
return redirect()->route('user.select');
Expand Down
9 changes: 9 additions & 0 deletions app/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @property-read \Illuminate\Database\Eloquent\Collection|Item[] $children
* @property-read int|null $children_count
* @property-read string $droppable
* @property-read string $icon_url
* @property-read \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\Routing\UrlGenerator|mixed|string $link
* @property-read string $link_icon
* @property-read string $link_target
Expand Down Expand Up @@ -230,6 +231,14 @@ public function getDroppableAttribute(): string
}
}

/** The tile icon URL, or the default Heimdall icon when there is none */
public function getIconUrlAttribute(): string
{
return $this->icon
? asset('/storage/'.str_replace('supportedapps', 'icons', $this->icon))
: asset('/img/heimdall-icon-small.png');
}

public function getLinkTargetAttribute(): string
{
$target = Setting::fetch('window_target');
Expand Down
15 changes: 15 additions & 0 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Auth;

// @codingStandardsIgnoreStart
/**
Expand Down Expand Up @@ -76,6 +77,20 @@ public function getId()
return $this->id;
}

/**
* Whether the current visitor may use this user's private pages: the user
* has no password, or the visitor is logged in as them. The "allowed"
* middleware and the views that must match it both use this.
*/
public function isOpenToVisitor(): bool
{
if (empty($this->password)) {
return true;
}

return Auth::check() && Auth::user()->id === $this->getId();
}

/**
* Get the items for the user.
*/
Expand Down
6 changes: 6 additions & 0 deletions lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,10 @@
'role' => 'Authentication role',
'unauthorized_for_form' => 'You are not authorized to view this form.',
'disabled_feature' => 'This feature is disabled.',
'quicklauncher.title' => 'Quick launcher',
'quicklauncher.open' => 'Open quick launcher',
'quicklauncher.placeholder' => 'Search apps…',
'quicklauncher.loading' => 'Loading…',
'quicklauncher.error' => 'Could not load your apps',
'quicklauncher.search_web' => 'Search :provider for “:query”',
);
3 changes: 3 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ There is also a multi-arch Docker which supports x86-64, armhf and arm64, instru
## Updating
To update your instance, simply clone this repository or download the zip/tar file with the new version and copy it over the old installation.

## Quick launcher
Press `Cmd+K` (`Ctrl+K` on Windows and Linux) on any page to open a quick launcher that finds any of your apps, pinned or not. Use the arrow keys and `Enter` to open one, or `Esc` to close it. Apps you open most recently are listed first (this history is kept in your browser, so it isn't shared between devices). If a default search provider is set for the homepage search, the launcher offers a web search for anything it can't find. On touch devices a search button in the bottom left corner opens it.

## Search Providers
v2.3.0 added the ability for users to customise the search options.

Expand Down
1 change: 1 addition & 0 deletions resources/assets/js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import "./globals";
import "./jquery-ui.min";
import "./app";
import "./keyBindings";
import "./quicklauncher";
import "./itemExport";
import "./itemImport";
import "./liveStatRefresh";
Loading
Loading