Skip to content

Commit 9a8356d

Browse files
committed
feat: granular permissios for profile user data
added public_profile_show_telephone_number Change-Id: I4ddcd30469526cd9e7d276c91251d5be3fbcb84c
1 parent af8f25f commit 9a8356d

File tree

8 files changed

+157
-51
lines changed

8 files changed

+157
-51
lines changed

app/Http/Controllers/Factories/UserValidationRulesFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ public static function build(array $data, $update = false, ?User $currentUser =
6565
'public_profile_show_social_media_info' => 'sometimes|boolean',
6666
'public_profile_show_bio' => 'sometimes|boolean',
6767
'public_profile_allow_chat_with_me' => 'sometimes|boolean',
68+
'public_profile_show_telephone_number' => 'sometimes|boolean',
6869
];
6970

7071
if(!is_null($currentUser) && !$currentUser->isAdmin() && $currentUser->hasPasswordSet()){
@@ -111,6 +112,7 @@ public static function build(array $data, $update = false, ?User $currentUser =
111112
'public_profile_show_social_media_info' => 'sometimes|boolean',
112113
'public_profile_show_bio' => 'sometimes|boolean',
113114
'public_profile_allow_chat_with_me' => 'sometimes|boolean',
115+
'public_profile_show_telephone_number' => 'sometimes|boolean',
114116
];
115117
}
116118
}

app/ModelSerializers/Auth/UserSerializer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ final class PrivateUserSerializer extends BaseUserSerializer
8181
'PublicProfileShowSocialMediaInfo' => 'public_profile_show_social_media_info:json_boolean',
8282
'PublicProfileShowBio' => 'public_profile_show_bio:json_boolean',
8383
'PublicProfileAllowChatWithMe' => 'public_profile_allow_chat_with_me:json_boolean',
84+
'PublicProfileShowTelephoneNumber' => 'public_profile_show_telephone_number:json_boolean',
8485
];
8586

8687
/**

app/Services/OAuth2/ResourceServer/UserService.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ public function getCurrentUserInfo()
160160
$data[StandardClaims::ShowBio] = $current_user->isPublicProfileShowBio();
161161
$data[StandardClaims::ShowSocialMediaInfo] = $current_user->isPublicProfileShowSocialMediaInfo();
162162
$data[StandardClaims::AllowChatWithMe] = $current_user->isPublicProfileAllowChatWithMe();
163+
$data[StandardClaims::ShowTelephoneNumber] = $current_user->isPublicProfileShowTelephoneNumber();
163164

164165
$user_groups = [];
165166

@@ -220,6 +221,7 @@ public static function populateProfileClaims(JWTClaimSet $claim_set, User $user)
220221
$claim_set->addClaim(new JWTClaim(StandardClaims::ShowSocialMediaInfo, new JsonValue($user->isPublicProfileShowSocialMediaInfo())));
221222
$claim_set->addClaim(new JWTClaim(StandardClaims::ShowFullName, new JsonValue($user->isPublicProfileShowFullname())));
222223
$claim_set->addClaim(new JWTClaim(StandardClaims::AllowChatWithMe, new JsonValue($user->isPublicProfileAllowChatWithMe())));
224+
$claim_set->addClaim(new JWTClaim(StandardClaims::ShowTelephoneNumber, new JsonValue($user->isPublicProfileShowTelephoneNumber())));
223225

224226
$user_groups = [];
225227

app/libs/Auth/Factories/UserFactory.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,9 @@ public static function populate(User $user, array $payload):User{
172172
if(isset($payload['public_profile_allow_chat_with_me']))
173173
$user->setPublicProfileAllowChatWithMe(boolval($payload['public_profile_allow_chat_with_me']));
174174

175+
if(isset($payload['public_profile_show_telephone_number']))
176+
$user->setPublicProfileShowTelephoneNumber(boolval($payload['public_profile_show_telephone_number']));
177+
175178
if(isset($payload['email_verified']) && boolval($payload['email_verified']) === true && !$user->isEmailVerified()) {
176179
// we have this variable to bypass email UserEmailVerified
177180
$send_email_verified_notice = isset($payload['send_email_verified_notice']) ? boolval($payload['send_email_verified_notice']):true;

app/libs/Auth/Models/User.php

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,11 @@ class User extends BaseEntity
119119
*/
120120
private $public_profile_show_bio;
121121

122+
/**
123+
* @ORM\Column(name="public_profile_show_telephone_number", options={"default":0}, type="boolean")
124+
* @var bool
125+
*/
126+
private $public_profile_show_telephone_number;
122127

123128
/**
124129
* @ORM\Column(name="last_login_date", type="datetime")
@@ -355,7 +360,6 @@ class User extends BaseEntity
355360

356361
// relations
357362

358-
359363
/**
360364
* @ORM\ManyToOne(targetEntity="Models\OAuth2\OAuth2OTP", cascade={"persist"})
361365
* @ORM\JoinColumn(name="created_by_otp_id", referencedColumnName="id", nullable=true)
@@ -455,9 +459,10 @@ public function __construct()
455459
$this->public_profile_show_photo = false;
456460
$this->public_profile_show_email = false;
457461
$this->public_profile_show_fullname = true;
458-
$this->public_profile_allow_chat_with_me = false;
459462
$this->public_profile_show_social_media_info = false;
460463
$this->public_profile_show_bio = true;
464+
$this->public_profile_show_telephone_number = false;
465+
$this->public_profile_allow_chat_with_me = false;
461466

462467
$this->password = "";
463468
$this->identifier = null;
@@ -1095,6 +1100,17 @@ public function setPublicProfileShowSocialMediaInfo(bool $public_profile_show_so
10951100
$this->public_profile_show_social_media_info = $public_profile_show_social_media_info;
10961101
}
10971102

1103+
public function isPublicProfileShowTelephoneNumber(): bool
1104+
{
1105+
return $this->public_profile_show_telephone_number;
1106+
}
1107+
1108+
public function setPublicProfileShowTelephoneNumber(bool $public_profile_show_telephone_number): void
1109+
{
1110+
$this->public_profile_show_telephone_number = $public_profile_show_telephone_number;
1111+
}
1112+
1113+
10981114
public function isPublicProfileShowBio(): bool
10991115
{
11001116
return $this->public_profile_show_bio;
@@ -2087,6 +2103,7 @@ public function updating(PreUpdateEventArgs $args)
20872103
'public_profile_allow_chat_with_me',
20882104
'public_profile_show_social_media_info',
20892105
'public_profile_show_bio',
2106+
'public_profile_show_telephone_number',
20902107
'active',
20912108
'first_name',
20922109
'last_name',

app/libs/OAuth2/StandardClaims.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ abstract class StandardClaims
2222

2323
const ShowSocialMediaInfo = 'public_profile_show_social_media_info';
2424

25+
const ShowTelephoneNumber = 'public_profile_show_telephone_number';
26+
2527
const ShowBio = 'public_profile_show_bio';
2628

2729
const AllowChatWithMe = 'public_profile_allow_chat_with_me';
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<?php namespace Database\Migrations;
2+
/**
3+
* Copyright 2024 OpenStack Foundation
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
**/
14+
use Doctrine\Migrations\AbstractMigration;
15+
use Doctrine\DBAL\Schema\Schema as Schema;
16+
use LaravelDoctrine\Migrations\Schema\Builder;
17+
use LaravelDoctrine\Migrations\Schema\Table;
18+
19+
/**
20+
* Class Version20240722174651
21+
* @package Database\Migrations
22+
*/
23+
final class Version20240722174651 extends AbstractMigration
24+
{
25+
/**
26+
* @param Schema $schema
27+
*/
28+
public function up(Schema $schema): void
29+
{
30+
$builder = new Builder($schema);
31+
if($schema->hasTable("users") && !$builder->hasColumn("users","public_profile_show_telephone_number") ) {
32+
$builder->table('users', function (Table $table) {
33+
$table->boolean('public_profile_show_telephone_number')->setNotnull(true)->setDefault(false);
34+
});
35+
}
36+
}
37+
38+
/**
39+
* @param Schema $schema
40+
*/
41+
public function down(Schema $schema): void
42+
{
43+
$builder = new Builder($schema);
44+
if($schema->hasTable("users") && $builder->hasColumn("users","public_profile_show_telephone_number") ) {
45+
$builder->table('users', function (Table $table) {
46+
$table->dropColumn('public_profile_show_telephone_number');
47+
});
48+
}
49+
}
50+
}

resources/js/profile/profile.js

Lines changed: 78 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -712,55 +712,84 @@ const ProfilePage = ({
712712
hasPasswordSet={initialValues.has_password_set}
713713
formik={formik}
714714
passwordPolicy={passwordPolicy}/>
715-
<Grid item xs={12}>
716-
<FormControlLabel
717-
control={<Checkbox name="public_profile_show_photo"
718-
id="public_profile_show_photo"
719-
checked={formik.values.public_profile_show_photo}
720-
onChange={formik.handleChange}
721-
color="primary"/>}
722-
label="Show Picture on Public Profile?"
723-
/>
724-
<FormControlLabel
725-
control={<Checkbox name="public_profile_show_fullname"
726-
id="public_profile_show_fullname"
727-
checked={formik.values.public_profile_show_fullname}
728-
onChange={formik.handleChange}
729-
color="primary"/>}
730-
label="Show Full name on Public Profile?"
731-
/>
732-
<FormControlLabel
733-
control={<Checkbox name="public_profile_show_email"
734-
id="public_profile_show_email"
735-
checked={formik.values.public_profile_show_email}
736-
onChange={formik.handleChange}
737-
color="primary"/>}
738-
label="Show Email on Public Profile?"
739-
/>
740-
<FormControlLabel
741-
control={<Checkbox name="public_profile_show_bio"
742-
id="public_profile_show_bio"
743-
checked={formik.values.public_profile_show_bio}
744-
onChange={formik.handleChange}
745-
color="primary"/>}
746-
label="Show Bio on Public Profile?"
747-
/>
748-
<FormControlLabel
749-
control={<Checkbox name="public_profile_show_social_media_info"
750-
id="public_profile_show_social_media_info"
751-
checked={formik.values.public_profile_show_social_media_info}
752-
onChange={formik.handleChange}
753-
color="primary"/>}
754-
label="Show Social Media Info on Public Profile?"
755-
/>
756-
<FormControlLabel
757-
control={<Checkbox name="public_profile_allow_chat_with_me"
758-
id="public_profile_allow_chat_with_me"
759-
checked={formik.values.public_profile_allow_chat_with_me}
760-
onChange={formik.handleChange}
761-
color="primary"/>}
762-
label="Allow people to chat with me?"
763-
/>
715+
716+
<Grid item spacing={2} container direction="row">
717+
<Grid item xs={6}>
718+
<FormControlLabel
719+
control={<Checkbox name="public_profile_show_photo"
720+
id="public_profile_show_photo"
721+
checked={formik.values.public_profile_show_photo}
722+
onChange={formik.handleChange}
723+
color="primary"/>}
724+
label="Show Picture on Public Profile?"
725+
/>
726+
</Grid>
727+
<Grid item xs={6}>
728+
<FormControlLabel
729+
control={<Checkbox name="public_profile_show_fullname"
730+
id="public_profile_show_fullname"
731+
checked={formik.values.public_profile_show_fullname}
732+
onChange={formik.handleChange}
733+
color="primary"/>}
734+
label="Show Full name on Public Profile?"
735+
/>
736+
</Grid>
737+
</Grid>
738+
<Grid item spacing={2} container direction="row">
739+
<Grid item xs={6}>
740+
<FormControlLabel
741+
control={<Checkbox name="public_profile_show_email"
742+
id="public_profile_show_email"
743+
checked={formik.values.public_profile_show_email}
744+
onChange={formik.handleChange}
745+
color="primary"/>}
746+
label="Show Email on Public Profile?"
747+
/>
748+
</Grid>
749+
<Grid item xs={6}>
750+
<FormControlLabel
751+
control={<Checkbox name="public_profile_show_bio"
752+
id="public_profile_show_bio"
753+
checked={formik.values.public_profile_show_bio}
754+
onChange={formik.handleChange}
755+
color="primary"/>}
756+
label="Show Bio on Public Profile?"
757+
/>
758+
</Grid>
759+
</Grid>
760+
<Grid item spacing={2} container direction="row">
761+
<Grid item xs={6}>
762+
<FormControlLabel
763+
control={<Checkbox name="public_profile_show_social_media_info"
764+
id="public_profile_show_social_media_info"
765+
checked={formik.values.public_profile_show_social_media_info}
766+
onChange={formik.handleChange}
767+
color="primary"/>}
768+
label="Show Social Media Info on Public Profile?"
769+
/>
770+
</Grid>
771+
<Grid item xs={6}>
772+
<FormControlLabel
773+
control={<Checkbox name="public_profile_show_telephone_number"
774+
id="public_profile_show_telephone_number"
775+
checked={formik.values.public_profile_show_telephone_number}
776+
onChange={formik.handleChange}
777+
color="primary"/>}
778+
label="Show Telephone Number on Public Profile?"
779+
/>
780+
</Grid>
781+
</Grid>
782+
<Grid item spacing={2} container direction="row">
783+
<Grid item xs={6}>
784+
<FormControlLabel
785+
control={<Checkbox name="public_profile_allow_chat_with_me"
786+
id="public_profile_allow_chat_with_me"
787+
checked={formik.values.public_profile_allow_chat_with_me}
788+
onChange={formik.handleChange}
789+
color="primary"/>}
790+
label="Allow People Chat With Me?"
791+
/>
792+
</Grid>
764793
</Grid>
765794
<Grid item container alignItems="center" justifyContent="center">
766795
<Button

0 commit comments

Comments
 (0)