mirror of
https://github.com/Poniverse/Pony.fm.git
synced 2024-11-22 04:58:01 +01:00
#25: Limited notification management to admins.
This commit is contained in:
parent
b401a0ae7e
commit
79e77a2da0
6 changed files with 39 additions and 21 deletions
|
@ -24,7 +24,6 @@ use DB;
|
|||
use Poniverse\Ponyfm\Models\Image;
|
||||
use Poniverse\Ponyfm\Models\User;
|
||||
use Gate;
|
||||
use Auth;
|
||||
use Validator;
|
||||
|
||||
class SaveAccountSettingsCommand extends CommandBase
|
||||
|
@ -111,6 +110,8 @@ class SaveAccountSettingsCommand extends CommandBase
|
|||
$this->_user->save();
|
||||
|
||||
// Sync email subscriptions
|
||||
// TODO: [#25] Remove this when email notifications are rolled out to everyone.
|
||||
if (Gate::forUser($this->_user)->allows('receive-email-notifications')) {
|
||||
$emailSubscriptions = $this->_user->emailSubscriptions->keyBy('activity_type');
|
||||
foreach ($this->_input['notifications'] as $notificationSetting) {
|
||||
|
||||
|
@ -127,6 +128,7 @@ class SaveAccountSettingsCommand extends CommandBase
|
|||
$emailSubscriptions->get($notificationSetting['activity_type'])->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return CommandResponse::succeed();
|
||||
|
|
|
@ -71,6 +71,8 @@ class AccountController extends ApiControllerBase
|
|||
'gravatar' => $user->gravatar ? $user->gravatar : $user->email,
|
||||
'avatar_url' => !$user->uses_gravatar ? $user->getAvatarUrl() : null,
|
||||
'uses_gravatar' => $user->uses_gravatar == 1,
|
||||
// TODO: [#25] Remove this when email notifications are rolled out to everyone.
|
||||
'can_manage_notifications' => Gate::forUser($user)->allows('receive-email-notifications'),
|
||||
'notifications' => $user->getNotificationSettings()
|
||||
], 200);
|
||||
}
|
||||
|
|
|
@ -437,17 +437,26 @@ class User extends Model implements AuthenticatableContract, CanResetPasswordCon
|
|||
', [$this->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates an array of the user's notification settings. It's meant to be
|
||||
* used for the notification settings screen.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getNotificationSettings() {
|
||||
$settings = [];
|
||||
$emailSubscriptions = $this->emailSubscriptionsJoined();
|
||||
|
||||
foreach($emailSubscriptions as $subscription) {
|
||||
// TODO: remove this check when news and album notifications are implemented
|
||||
if (!in_array($subscription->activity_type, [Activity::TYPE_NEWS, Activity::TYPE_PUBLISHED_ALBUM])) {
|
||||
$settings[] = [
|
||||
'description' => $subscription->description,
|
||||
'activity_type' => $subscription->activity_type,
|
||||
'receive_emails' => $subscription->id !== NULL
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $settings;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
|
||||
namespace Poniverse\Ponyfm\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
use Gate;
|
||||
use Illuminate\Contracts\Auth\Access\Gate as GateContract;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Poniverse\Ponyfm\Models\Album;
|
||||
|
@ -76,6 +76,11 @@ class AuthServiceProvider extends ServiceProvider
|
|||
return $user->hasRole('admin');
|
||||
});
|
||||
|
||||
// TODO: [#25] Remove this when email notifications are rolled out to everyone.
|
||||
Gate::define('receive-email-notifications', function (User $user) {
|
||||
return $user->hasRole('admin');
|
||||
});
|
||||
|
||||
$this->registerPolicies();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@
|
|||
<div class="error" ng-show="errors.gravatar != null">{{errors.gravatar}}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-8">
|
||||
<div class="col-md-8" ng-if="::settings.can_manage_notifications">
|
||||
<h3>Notification settings</h3>
|
||||
<p>On-site notifications are always on. That way, you can always see
|
||||
what you've missed whenever you log on to Pony.fm!</p>
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
@section('content')
|
||||
<p>
|
||||
{{ $creatorName }} favourited your {{ $resourceType }},
|
||||
<em><a href="{{ $notificationUrl }}" target="_blank">{{ $resourceTitle }}</a></em>
|
||||
<em><a href="{{ $notificationUrl }}" target="_blank">{{ $resourceTitle }}</a></em>.
|
||||
Yay!
|
||||
</p>
|
||||
@endsection
|
||||
|
|
Loading…
Reference in a new issue