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

Add option to limit profile views only for admin users #545

Merged
merged 4 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Fix: Social Network Auth (eluhr)
- Enh #532: /user/registration/register now shows form validation errors
- Enh: Allow/suggest new v3 releases of 2amigos 2fa dependencies: 2fa-library, qrcode-library (TonisOrmisson)
- Enh: Added option to disable viewing any other user's profile for non-admin users (TonisOrmisson)

## 1.6.2 Jan 4th, 2024

Expand Down
12 changes: 12 additions & 0 deletions src/User/Controller/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,20 @@

namespace Da\User\Controller;

use Da\User\Model\User;
use Da\User\Query\ProfileQuery;
use Da\User\Traits\ModuleAwareTrait;
use Yii;
use yii\base\Module;
use yii\filters\AccessControl;
use yii\web\Controller;
use yii\web\ForbiddenHttpException;
use yii\web\NotFoundHttpException;

class ProfileController extends Controller
{
use ModuleAwareTrait;

protected $profileQuery;

/**
Expand Down Expand Up @@ -67,6 +72,13 @@ public function actionIndex()

public function actionShow($id)
{
$user = Yii::$app->user;
/** @var User $identity */
$identity = $user->getIdentity();
if($user->getId() != $id && $this->module->disableProfileViewsForRegularUsers && !$identity->getIsAdmin()) {
throw new ForbiddenHttpException();
}

$profile = $this->profileQuery->whereUserId($id)->one();

if ($profile === null) {
Expand Down
4 changes: 4 additions & 0 deletions src/User/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,10 @@ class Module extends BaseModule
* @var boolean whether to disable IP logging into user table
*/
public $disableIpLogging = false;
/**
* @var boolean whether to disable viewing any user's profile for non-admin users
*/
public $disableProfileViewsForRegularUsers = false;
maxxer marked this conversation as resolved.
Show resolved Hide resolved
/**
* @var array Minimum requirements when a new password is automatically generated.
* Array structure: `requirement => minimum number characters`.
Expand Down
Loading