Skip to content
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

Rebase #542

Merged
merged 34 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
495b672
Merge pull request #520 from dbarzin/dev
dbarzin Oct 4, 2023
353a322
Merge pull request #522 from dbarzin/dev
dbarzin Oct 4, 2023
5a00a01
Merge pull request #526 from dbarzin/dev
dbarzin Oct 12, 2023
c3536c7
Autorisation de l'admin à modifier les applications lorsque qu'option…
TheoB-dev Oct 23, 2023
a53d2ad
Renommage fonction
TheoB-dev Oct 23, 2023
1d907c0
Refactor
TheoB-dev Oct 23, 2023
dba3634
Refactor
TheoB-dev Oct 23, 2023
fd966dd
Suppression du recommended sur champ Cartographes
TheoB-dev Oct 23, 2023
1864a9e
Refactor
TheoB-dev Oct 23, 2023
f7da5b8
Suppression du cache sur role qui ne fonctionne pas
TheoB-dev Oct 24, 2023
3abd55e
Orthographe
TheoB-dev Oct 24, 2023
c40e4e2
Simplification cartographes sélectionnés à l'affichage & en cas d'err…
TheoB-dev Oct 24, 2023
d5d8be1
Merge branch 'develop'
TheoB-dev Oct 24, 2023
b4d708e
Merge pull request #529 from dbarzin/dev
dbarzin Oct 29, 2023
31ed080
Merge pull request #530 from dbarzin/dev
dbarzin Oct 30, 2023
8dd6c6f
Add dev mode (http) in docker description
pdurandfr Oct 30, 2023
cd31ca2
Merge pull request #531 from dbarzin/dev
dbarzin Oct 30, 2023
68b2fbb
Merge pull request #532 from dbarzin/dev
dbarzin Oct 30, 2023
04afef5
Update README.fr.md
dbarzin Oct 30, 2023
135f6e3
Merge pull request #534 from dbarzin/dev
dbarzin Nov 2, 2023
8a75cc4
Merge pull request #536 from dbarzin/dev
dbarzin Nov 3, 2023
d49c255
Merge pull request #537 from dbarzin/dev
dbarzin Nov 4, 2023
f66d6c8
Merge pull request #538 from dbarzin/dev
dbarzin Nov 4, 2023
18358d1
Update README.fr.md
dbarzin Nov 6, 2023
551663f
Merge pull request #539 from dbarzin/dev
dbarzin Nov 7, 2023
d1f756e
Merge pull request #540 from dbarzin/dev
dbarzin Nov 7, 2023
edd3de0
Merge 'dzarbin/master' into 'master'
TheoB-dev Nov 12, 2023
d25b641
Merge branch 'master' into develop
TheoB-dev Nov 12, 2023
7ae4752
Remise variable supprimée après merge
TheoB-dev Nov 12, 2023
2865ef7
Merge branch 'master' into develop
TheoB-dev Nov 12, 2023
2c6070e
Refactor isAdmin qui modifie en interne la variable pour les rôles, d…
TheoB-dev Nov 12, 2023
4929b9c
Merge branch 'develop'
TheoB-dev Nov 12, 2023
cce651c
Merge pull request #541 from dbarzin/dev
dbarzin Nov 12, 2023
8cebf42
Merge pull request #528 from TheoB-dev/master
dbarzin Nov 12, 2023
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
39 changes: 38 additions & 1 deletion README.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,44 @@ Modèle de données
## Installation

- Procédure d'[installation](https://github.com/dbarzin/mercator/blob/master/INSTALL.fr.md)
- Déploiement sous [Docker](https://github.com/dbarzin/mercator/blob/master/docker/README.fr.md)

### Docker

Téléchargez d'abord l'image Docker.

```Shell
docker pull ghcr.io/dbarzin/mercator:latest
```

Ensuite, vous pouvez lancer une instance locale éphémère en mode développement (i.e. http) :

```shell
docker run -it --rm --name mercator -e APP_ENV=development -p "127.0.0.1:8000":80 ghcr.io/dbarzin/mercator:latest
```

Par défaut, il utilise un backend SQLite. Si vous voulez rendre les données persistantes :

```Shell
touch ./db.sqlite && chmod a+w ./db.sqlite
docker run -it --rm --name mercator -e APP_ENV=development -p "127.0.0.1:8000":80 -v $PWD/db.sqlite:/var/www/mercator/db.sqlite ghcr.io/dbarzin/mercator:latest
```

Enfin, vous pouvez remplir la base de données avec des données de démonstration grâce à la variable d'environnement `USE_DEMO_DATA` :

```shell
touch ./db.sqlite && chmod a+w ./db.sqlite
docker run -it --rm \
--name mercator \
-e APP_ENV=development \
-p "127.0.0.1:8000":80 \
-v $PWD/db.sqlite:/var/www/mercator/db.sqlite \
-e USE_DEMO_DATA=1 \
ghcr.io/dbarzin/mercator:latest
```

Visitez http://127.0.0.1:8000 !

Si vous recherchez un environnement plus robuste (https) et automatisé, jetez un oeil au dossier [docker-compose](docker-compose/).

## Changelog

Expand Down
9 changes: 6 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,17 @@ First download the docker image.
docker pull ghcr.io/dbarzin/mercator:latest
```

Then you can run an ephemeral local instance:
Then you can run an ephemeral local instance in development mode (i.e. http):

```shell
docker run -it --rm --name mercator -p "127.0.0.1:8000":80 ghcr.io/dbarzin/mercator:latest
docker run -it --rm --name mercator -e APP_ENV=development -p "127.0.0.1:8000":80 ghcr.io/dbarzin/mercator:latest
```

By default it uses an SQLite backend. If you want to make data persistent:

```shell
touch ./db.sqlite && chmod a+w ./db.sqlite
docker run -it --rm --name mercator -p "127.0.0.1:8000":80 -v $PWD/db.sqlite:/var/www/mercator/db.sqlite ghcr.io/dbarzin/mercator:latest
docker run -it --rm --name mercator -e APP_ENV=development -p "127.0.0.1:8000":80 -v $PWD/db.sqlite:/var/www/mercator/db.sqlite ghcr.io/dbarzin/mercator:latest
```

Finally you can populate the database with demo data through the `USE_DEMO_DATA` environment variable:
Expand All @@ -98,6 +98,7 @@ Finally you can populate the database with demo data through the `USE_DEMO_DATA`
touch ./db.sqlite && chmod a+w ./db.sqlite
docker run -it --rm \
--name mercator \
-e APP_ENV=development \
-p "127.0.0.1:8000":80 \
-v $PWD/db.sqlite:/var/www/mercator/db.sqlite \
-e USE_DEMO_DATA=1 \
Expand All @@ -106,6 +107,8 @@ docker run -it --rm \

Visit http://127.0.0.1:8000 !

If you are looking for a more robust (https) and automated environment, please have a look on [docker-compose](docker-compose/) folder.

## Changelog

All notable changes to this project are [documented](https://github.com/dbarzin/mercator/blob/master/CHANGELOG.md).
Expand Down
2 changes: 1 addition & 1 deletion app/Ldap/Rules/OnlySpecificUsers.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class OnlySpecificUsers extends Rule
*
* @return bool
*/
public function isValid()
public function isValid(): bool
{
if (! config('app.ldap_groups')) {
return true;
Expand Down
2 changes: 1 addition & 1 deletion app/Ldap/Scopes/OnlyOrgUnitUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class OnlyOrgUnitUser implements Scope
*
* @return void
*/
public function apply(Builder $query, Model $model)
public function apply(Builder $query, Model $model): void
{
if (! config('app.ldap_scope')) {
return;
Expand Down
22 changes: 1 addition & 21 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,31 +44,11 @@ public function boot()
Passport::personalAccessTokensExpireIn(now()->addHours(4));
}

/*
* Register one Gate per model for cartographers.
* */
/**
* Before check
*/
/*
Gate::before(function (User $user, $ability) {
// check $ability before
if (!config('app.cartographers', false))
return false;
if ($ability==="is-cartographer-m-application")
// Si c'est un admin, on lui autorise toutes les applications
if ($user->getIsAdminAttribute())
return true;
else
return false;
});
*/

/**
* MApplication
*/
Gate::define('is-cartographer-m-application', function (User $user, MApplication $application) {
if (! config('app.cartographers', false)) {
if (! config('app.cartographers', false) || $user->isAdmin()) {
return true;
}
return $application->hasCartographer($user);
Expand Down
15 changes: 8 additions & 7 deletions app/Services/CartographerService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\MApplication;
use App\Role;
use App\User;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
Expand Down Expand Up @@ -35,7 +36,7 @@ public function filterOnCartographers(Collection $applications): Collection
// Maybe there's a way to TypeHint the authenticated user ? (\Illuminate\Contracts\Auth\Authenticatable user)
$currentUser = Auth::user();
// On ne filtre pas pour les admins
if (! $this->active || $currentUser->getIsAdminAttribute()) {
if (! $this->active || $currentUser->isAdmin()) {
return $applications->sortBy('name')->pluck('name', 'id');
}

Expand All @@ -53,27 +54,27 @@ public function filterOnCartographers(Collection $applications): Collection
*
* @param MApplication $application
*
* @return bool
* @return void
*/
public function attributeCartographerRole(MApplication $application): bool
public function attributeCartographerRole(MApplication $application): void
{
if (! $this->active) {
return false;
return;
}

// On ne veut pas le créer s'il existe pas
if (! ($role = Role::getRoleByTitle('Cartographer')) && ! ($role = Role::getRoleByTitle('Cartographe'))) {
return false;
return;
}

/** @var User $cartographer */
foreach ($application->cartographers as $cartographer) {
// Pas besoin de le mettre sur les utilisateurs étant administrateurs
if ($cartographer->getIsAdminAttribute()) {
if ($cartographer->isAdmin()) {
continue;
}

$cartographer->addRole($role);
}
return true;
}
}
14 changes: 8 additions & 6 deletions app/Services/EventService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,18 @@ class EventService
public function getLoadAppEvents(MApplication $application)
{
// Chargement des évènements triés
$application->load(['events' => function ($query) {
$query->orderBy('created_at', 'desc');
},
$application->load([
'events' => function ($query) {
$query->orderBy('created_at', 'desc');
},
]);

// On veut le nom utilisateur pour chaque évènements
foreach ($application->events as $event) {
$event->load(['user' => function ($query) {
$query->select('id', 'name');
},
$event->load([
'user' => function ($query) {
$query->select('id', 'name');
},
]);
}
}
Expand Down
45 changes: 29 additions & 16 deletions app/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Carbon\Carbon;
use DateTimeInterface;
use Hash;
use Illuminate\Auth\Notifications\ResetPassword;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Facades\Hash;
use Laravel\Passport\HasApiTokens;
use LdapRecord\Laravel\Auth\AuthenticatesWithLdap;
use LdapRecord\Laravel\Auth\HasLdapUser;
Expand All @@ -19,7 +20,11 @@
*/
class User extends Authenticatable implements LdapAuthenticatable
{
use SoftDeletes, Notifiable, HasApiTokens, AuthenticatesWithLdap, HasLdapUser;
use AuthenticatesWithLdap;
use HasApiTokens;
use HasLdapUser;
use Notifiable;
use SoftDeletes;

public $table = 'users';

Expand All @@ -28,7 +33,7 @@ class User extends Authenticatable implements LdapAuthenticatable
'password',
];

protected $dates = [
protected array $dates = [
'email_verified_at',
'created_at',
'updated_at',
Expand All @@ -48,16 +53,33 @@ class User extends Authenticatable implements LdapAuthenticatable
'deleted_at',
];

/**
* Check if the User has the 'Admin' role, which is the first role in the app
* @return bool
*/
public function isAdmin(): bool
{
foreach ($this->roles()->get() as $role) {
if ($role->id === 1) {
return true;
}
}
return false;
}

// Add some caching for roles
private $roles = null;
private ?BelongsToMany $cachedRoles = null;

public function getIsAdminAttribute(): bool
public function roles(): BelongsToMany
{
return $this->roles()->where('id', 1)->exists();
if ($this->cachedRoles === null) {
$this->cachedRoles = $this->belongsToMany(Role::class);
}
return $this->cachedRoles;
}

/**
* Permet de check si un utilisateur a un role
* Check si un utilisateur a un role
*
* @param String|Role $role
*
Expand Down Expand Up @@ -111,15 +133,6 @@ public function sendPasswordResetNotification($token)
{
$this->notify(new ResetPassword($token));
}

public function roles()
{
if ($this->roles === null) {
return $this->roles = $this->belongsToMany(Role::class)->orderBy('title');
}
return $this->roles;
}

public function m_applications()
{
return $this->belongsToMany(MApplication::class, 'cartographer_m_application');
Expand Down
14 changes: 7 additions & 7 deletions resources/lang/fr/validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,13 @@
'password' => 'Le mot de passe est incorrect',
'present' => ':attribute champ doit être présent.',
'regex' => ":attribute n'est pas au bon format",
'required' => ':attribute champ est recquis.',
'required_if' => ':attribute champ est recquis lorsque :other est :value.',
'required_unless' => ':attribute champ est recquis à moins que :other est dans :values.',
'required_with' => ':attribute champ est recquis lorsque :values est présent.',
'required_with_all' => ':attribute champ est recquis lorsque :values est présent.',
'required_without' => ":attribute champ est recquis lorsque :values n'est pas présent.",
'required_without_all' => ':attribute champ est recquis lorsque aucun de :values sont présents',
'required' => ':attribute champ est requis.',
'required_if' => ':attribute champ est requis lorsque :other est :value.',
'required_unless' => ':attribute champ est requis à moins que :other est dans :values.',
'required_with' => ':attribute champ est requis lorsque :values est présent.',
'required_with_all' => ':attribute champ est requis lorsque :values est présent.',
'required_without' => ":attribute champ est requis lorsque :values n'est pas présent.",
'required_without_all' => ':attribute champ est requis lorsque aucun de :values sont présents',
'reserved_word' => ':attribute contient un mot réservé.',
'same' => ':attribute et :other doivent correspondre.',
'size' => [
Expand Down
2 changes: 1 addition & 1 deletion resources/views/admin/applications/create.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="recommended" for="cartographers">{{ trans('cruds.application.fields.cartographers') }}</label>
<label for="cartographers">{{ trans('cruds.application.fields.cartographers') }}</label>
<select class="form-control select2-free {{ $errors->has('cartographers') ? 'is-invalid' : '' }}" name="cartographers[]" id="cartographers" multiple>
@foreach($cartographers_list as $key => $cartographer)
<option value="{{ $key }}" {{ in_array($key, old('cartographers', [])) ? 'selected' : '' }}>{{ $cartographer }}</option>
Expand Down
Loading
Loading