Commit f4edb764 authored by Nicolas Widart's avatar Nicolas Widart

Squashed 'Modules/User/' changes from d4e1225..f048f16

f048f16 Add an interface for the user entity. Implement it for sentinel
34d37c6 Merge pull request #16 from AsgardCms/fix-role-repo
2682d65 Fix the update method, unset the slug property for sentry.
b2371f1 Merge pull request #15 from AsgardCms/patch1
560da26 Adapting other files to the namespace change
e23ca89 Changing namespace for the user Entity
7f5dc4a Merge pull request #14 from AsgardCms/using-isset
adab07c Check for variables using isset

git-subtree-dir: Modules/User
git-subtree-split: f048f16a868474d4eca1c80c5ddfb27d451801e0
parent cf4bb7d7
<?php namespace Modules\User\Entities; <?php namespace Modules\User\Entities\Sentinel;
use Cartalyst\Sentinel\Users\EloquentUser; use Cartalyst\Sentinel\Users\EloquentUser;
use Laracasts\Presenter\PresentableTrait; use Laracasts\Presenter\PresentableTrait;
use Modules\User\Entities\UserInterface;
class SentinelUser extends EloquentUser class User extends EloquentUser implements UserInterface
{ {
use PresentableTrait; use PresentableTrait;
...@@ -16,4 +17,9 @@ class SentinelUser extends EloquentUser ...@@ -16,4 +17,9 @@ class SentinelUser extends EloquentUser
]; ];
protected $presenter = 'Modules\User\Presenters\UserPresenter'; protected $presenter = 'Modules\User\Presenters\UserPresenter';
public function hasRole($roleId)
{
return $this->roles()->whereId($roleId)->count() >= 1;
}
} }
<?php namespace Modules\User\Entities; <?php namespace Modules\User\Entities\Sentry;
use Cartalyst\Sentry\Users\Eloquent\User; use Cartalyst\Sentry\Users\Eloquent\User as SentryModel;
use Laracasts\Presenter\PresentableTrait; use Laracasts\Presenter\PresentableTrait;
use Modules\User\Entities\UserInterface;
class SentryUser extends User class User extends SentryModel implements UserInterface
{ {
use PresentableTrait; use PresentableTrait;
...@@ -21,4 +22,13 @@ class SentryUser extends User ...@@ -21,4 +22,13 @@ class SentryUser extends User
{ {
return $this->belongsToMany(static::$groupModel, static::$userGroupsPivot, 'user_id'); return $this->belongsToMany(static::$groupModel, static::$userGroupsPivot, 'user_id');
} }
/**
* Checks if a user belongs to the given Role ID
* @param int $roleId
* @return bool
*/
public function hasRole($roleId)
{
}
} }
<?php namespace Modules\User\Entities;
interface UserInterface
{
/**
* Checks if a user belongs to the given Role ID
* @param int $roleId
* @return bool
*/
public function hasRole($roleId);
}
...@@ -8,7 +8,7 @@ use Modules\User\Repositories\UserRepository; ...@@ -8,7 +8,7 @@ use Modules\User\Repositories\UserRepository;
class SentinelUserRepository implements UserRepository class SentinelUserRepository implements UserRepository
{ {
/** /**
* @var \Modules\User\Entities\SentinelUser * @var \Modules\User\Entities\User\Sentinel
*/ */
protected $user; protected $user;
/** /**
......
...@@ -20,6 +20,7 @@ class SentryRoleRepository implements RoleRepository ...@@ -20,6 +20,7 @@ class SentryRoleRepository implements RoleRepository
*/ */
public function create($data) public function create($data)
{ {
unset($data['slug']);
Sentry::createGroup($data); Sentry::createGroup($data);
} }
...@@ -41,11 +42,10 @@ class SentryRoleRepository implements RoleRepository ...@@ -41,11 +42,10 @@ class SentryRoleRepository implements RoleRepository
*/ */
public function update($id, $data) public function update($id, $data)
{ {
unset($data['slug']);
$role = Sentry::findGroupById($id); $role = Sentry::findGroupById($id);
$role->permissions($data); $role->update($data);
$role->save();
} }
/** /**
......
...@@ -34,7 +34,7 @@ ...@@ -34,7 +34,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php if ($roles->count() > 0): ?> <?php if (isset($roles)): ?>
<?php foreach($roles as $role): ?> <?php foreach($roles as $role): ?>
<tr> <tr>
<td> <td>
...@@ -73,7 +73,7 @@ ...@@ -73,7 +73,7 @@
</div> </div>
</div> </div>
<?php if ($roles->count() > 0): ?> <?php if (isset($roles)): ?>
<?php foreach($roles as $role): ?> <?php foreach($roles as $role): ?>
<!-- Modal --> <!-- Modal -->
<div class="modal fade" id="confirmation-{{ $role->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal fade" id="confirmation-{{ $role->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
......
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
<label>{{ trans('user::users.tabs.roles') }}</label> <label>{{ trans('user::users.tabs.roles') }}</label>
<select multiple="" class="form-control" name="roles[]"> <select multiple="" class="form-control" name="roles[]">
<?php foreach($roles as $role): ?> <?php foreach($roles as $role): ?>
<option value="{{ $role->id }}" <?php echo $user->roles()->whereId($role->id)->count() >= 1 ? 'selected' : '' ?>>{{ $role->name }}</option> <option value="{{ $role->id }}" <?php echo $user->hasRole($role->id) ? 'selected' : '' ?>>{{ $role->name }}</option>
<?php endforeach; ?> <?php endforeach; ?>
</select> </select>
</div> </div>
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php if ($users->count() > 0): ?> <?php if (isset($users)): ?>
<?php foreach($users as $user): ?> <?php foreach($users as $user): ?>
<tr> <tr>
<td> <td>
...@@ -89,7 +89,7 @@ ...@@ -89,7 +89,7 @@
</div> </div>
</div> </div>
<?php if ($users->count() > 0): ?> <?php if (isset($users)): ?>
<?php foreach($users as $user): ?> <?php foreach($users as $user): ?>
<!-- Modal --> <!-- Modal -->
<div class="modal fade" id="confirmation-{{ $user->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"> <div class="modal fade" id="confirmation-{{ $user->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment