Skip to content
Merged
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
13 changes: 13 additions & 0 deletions app/Classes/RcnApi/Resources/ApplicationResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,17 @@ public function deleteApplication(int $id)
$this->http->delete('apps/' . $id);
});
}

public function updateRules(int $tenantUserId, array $rules)
{
return $this->handleApiCall(function () use ($tenantUserId, $rules) {
$response = $this->http->post('applications/rules', [
'json' => [
'tenant_user_id' => (string) $tenantUserId,
'rules' => $rules,
],
]);
return json_decode($response->getBody()->getContents(), true);
});
}
}
25 changes: 25 additions & 0 deletions app/Http/Controllers/Auth/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,9 @@ public function update(Request $request, int $userId)
'organisations' => 'array',
'organisations.*' => 'string|distinct|min:3|max:3',
'confirmed_role' => 'nullable|boolean',

'can_access_legacy_whatnow' => 'nullable|boolean',
'can_access_preparedness_v2' => 'nullable|boolean',
]);


Expand Down Expand Up @@ -402,11 +405,33 @@ public function update(Request $request, int $userId)
'terms_version' => $termsVersion ?? null,
]);

// Track if access flags are being changed
$rulesChanged = $request->has('can_access_legacy_whatnow') || $request->has('can_access_preparedness_v2');

// Apply access flags directly to user model before saving
if ($request->has('can_access_legacy_whatnow')) {
$user->can_access_legacy_whatnow = (bool) $request->get('can_access_legacy_whatnow');
}
if ($request->has('can_access_preparedness_v2')) {
$user->can_access_preparedness_v2 = (bool) $request->get('can_access_preparedness_v2');
}

$user = $this->users->updateUser($user, $input);
$user->load('organisations');

event(new UserUpdated($user));

// Call external API if access flags changed
if ($rulesChanged) {
try {
$this->rcnApiClient->application()->updateRules($user->id, [
'can_access_legacy_whatnow' => (bool) $user->can_access_legacy_whatnow,
'can_access_preparedness_v2' => (bool) $user->can_access_preparedness_v2,
]);
} catch (\Exception $e) {
Log::error('Failed to update rules for user ' . $user->id . ': ' . $e->getMessage());
}
}

return UserResource::make($user);
}
Expand Down
4 changes: 3 additions & 1 deletion app/Http/Resources/UserResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class UserResource extends Resource
{

public function toArray($request)
{
$user = [
Expand All @@ -20,6 +20,8 @@ public function toArray($request)
'created_at' => $this->created_at->format('c'),
'user_profile' => UserProfileResource::make($this->userProfile),
'confirmed_role' => $this->confirmed_role,
'can_access_legacy_whatnow' => (bool) $this->can_access_legacy_whatnow,
'can_access_preparedness_v2' => (bool) $this->can_access_preparedness_v2,
];

$roles = $this->whenLoaded('roles');
Expand Down
35 changes: 19 additions & 16 deletions app/Models/Access/User/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,69 +17,72 @@ class User extends Authenticatable implements JWTSubject
SoftDeletes,
UserAccess,
UserRelationship;


protected $fillable = [
'email', 'password', 'confirmation_code', 'confirmed_role'
'email', 'password', 'confirmation_code', 'confirmed_role',
'can_access_legacy_whatnow', 'can_access_preparedness_v2',
];


protected $casts = [
'activated' => 'boolean',
'confirmed' => 'boolean',
'confirmed_role' => 'boolean',
'can_access_legacy_whatnow' => 'boolean',
'can_access_preparedness_v2' => 'boolean',
];


protected $attributes = [
'activated' => true
];


protected $dates = ['deleted_at', 'password_updated_at', 'created_at', 'updated_at', 'last_logged_in_at'];


protected $hidden = [
'password', 'remember_token',
];


protected $appends = [
'photo_url',
];


protected $with = [
'userProfile'
];


public function getPhotoUrlAttribute()
{
return 'https://www.gravatar.com/avatar/'.md5(strtolower($this->email)).'.jpg?s=200&d=mm';
}


public function oauthProviders()
{
return $this->hasMany(OAuthProvider::class);
}


public function getJWTIdentifier()
{
return $this->getKey();
}


public function getJWTCustomClaims()
{
return [
'permissions' => $this->getPermissions()
];
}


public function hasSetOwnPassword()
{
return !is_null($this->password_updated_at);
Expand All @@ -97,13 +100,13 @@ public function confirm()
$this->save();
}


public function isConfirmed()
{
return $this->confirmed === true;
}


public function isActive()
{
return $this->activated === true;
Expand Down
7 changes: 2 additions & 5 deletions config/cors.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
<?php

return [


'cors_profile' => Spatie\Cors\CorsProfile\DefaultProfile::class,


'default_profile' => [

'allow_origins' => [
'*',
],
Expand All @@ -26,9 +22,10 @@
'X-Auth-Token',
'Origin',
'Authorization',
'x-api-key',
],


'max_age' => 60 * 60 * 24,
],
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddAccessFlagsToUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('users', function (Blueprint $table) {
$table->boolean('can_access_legacy_whatnow')->default(false)->after('confirmed_role');
$table->boolean('can_access_preparedness_v2')->default(false)->after('can_access_legacy_whatnow');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('users', function (Blueprint $table) {
$table->dropColumn(['can_access_legacy_whatnow', 'can_access_preparedness_v2']);
});
}
}

53 changes: 50 additions & 3 deletions resources/assets/js/pages/users/edit.vue
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,42 @@
</b-card>
</b-col>
</b-row>
<hr>
<b-row class="pl-4 pr-4 pb-4 pt-3 bg-white" v-if="!isMe && can(authUser, permissions.USERS_EDIT)">
<b-col>
<h3 class="styled-heading text-uppercase">
{{ $t('users.edit.access_permissions') }}
</h3>
<b-card class="bg-grey">
<b-row class="mb-3">
<b-col cols="12">
<div class="d-flex align-items-center mb-3">
<b-form-checkbox
v-model="user.can_access_legacy_whatnow"
switch
size="lg"
class="mr-3"
:class="{ 'switch-active': user.can_access_legacy_whatnow }"
>
<strong>{{ $t('users.edit.can_access_legacy_whatnow') }}</strong>
</b-form-checkbox>
</div>
<div class="d-flex align-items-center">
<b-form-checkbox
v-model="user.can_access_preparedness_v2"
switch
size="lg"
class="mr-3"
:class="{ 'switch-active': user.can_access_preparedness_v2 }"
>
<strong>{{ $t('users.edit.can_access_preparedness_v2') }}</strong>
</b-form-checkbox>
</div>
</b-col>
</b-row>
</b-card>
</b-col>
</b-row>
<hr>
<b-row class="pl-4 pr-4 pb-4 pt-3 bg-white" v-if="can(authUser, permissions.CONTENT_EDIT)">
<b-col>
Expand Down Expand Up @@ -390,7 +426,9 @@ export default {
activated: null,
organisations: [],
permissions: [],
api_used_in: ''
api_used_in: '',
can_access_legacy_whatnow: false,
can_access_preparedness_v2: false
},
societies: {
selectedSoc: null,
Expand Down Expand Up @@ -484,7 +522,9 @@ export default {
const changes = {
first_name: this.user.first_name,
last_name: this.user.last_name,
organisations: this.user.organisations
organisations: this.user.organisations,
can_access_legacy_whatnow: this.user.can_access_legacy_whatnow,
can_access_preparedness_v2: this.user.can_access_preparedness_v2
}

if (this.user.api_used_in && this.user.api_used_in.length > 0) {
Expand Down Expand Up @@ -544,7 +584,9 @@ export default {
id: user.id,
organisations: user.organisations,
permissions: user.role.permissions,
api_used_in: user.user_profile.api_used_in
api_used_in: user.user_profile.api_used_in,
can_access_legacy_whatnow: !!user.can_access_legacy_whatnow,
can_access_preparedness_v2: !!user.can_access_preparedness_v2
}
},
async resendActivation () {
Expand Down Expand Up @@ -685,4 +727,9 @@ export default {
border-radius: 10px;
padding: 0.5rem;
}

.switch-active >>> .custom-control-input:checked ~ .custom-control-label::before {
background-color: #f6333f;
border-color: #f6333f;
}
</style>
5 changes: 4 additions & 1 deletion resources/lang/am.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,10 @@
"less": "ያነሰ አሳይ",
"user_can_do": "ተጠቃሚው ምን የማድረግ ፈቃድ እንዳለው ይመልከቱ:",
"user_no_permission": "ተጠቃሚው ምንም ፈቃዶች አላገኘም",
"soc_already_added": "ይህ ተጠቃሚ አስቀድሞ ለዚህ ማህበር ተመድቧል"
"soc_already_added": "ይህ ተጠቃሚ አስቀድሞ ለዚህ ማህበር ተመድቧል",
"access_permissions": "የመዳረሻ ፈቃዶች",
"can_access_legacy_whatnow": "ቀደምት WhatNow መዳረስ ይችላል",
"can_access_preparedness_v2": "Preparedness v2 መዳረስ ይችላል"
}
},
"new_welcome": {
Expand Down
5 changes: 4 additions & 1 deletion resources/lang/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,10 @@
"less": "عرض أقل",
"user_can_do": "عرض الصلاحيات الممنوحة للمستخدم:",
"user_no_permission": "المستخدم ليس لديه أي صلاحيات",
"soc_already_added": "تم تعيين هذه الجمعية لهذا المستخدم بالفعل"
"soc_already_added": "تم تعيين هذه الجمعية لهذا المستخدم بالفعل",
"access_permissions": "أذونات الوصول",
"can_access_legacy_whatnow": "يمكن الوصول إلى WhatNow القديم",
"can_access_preparedness_v2": "يمكن الوصول إلى Preparedness v2"
}
},
"new_welcome": {
Expand Down
Loading
Loading