Skip to content

Commit 5bc83d2

Browse files
committed
feat: profile data permissions from IDP
1 parent 7587f06 commit 5bc83d2

File tree

9 files changed

+343
-7
lines changed

9 files changed

+343
-7
lines changed

app/ModelSerializers/AbstractMemberSerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ class AbstractMemberSerializer extends SilverStripeSerializer
2525
protected static $array_mappings = [
2626
'FirstName' => 'first_name:json_string',
2727
'LastName' => 'last_name:json_string',
28+
'Bio' => 'bio:json_string',
2829
'Gender' => 'gender:json_string',
2930
'GitHubUser' => 'github_user:json_string',
30-
'Bio' => 'bio:json_string',
3131
'LinkedInProfile' => 'linked_in:json_string',
3232
'IrcHandle' => 'irc:json_string',
3333
'TwitterHandle' => 'twitter:json_string',

app/ModelSerializers/PublicMemberSerializer.php

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,56 @@
1111
* See the License for the specific language governing permissions and
1212
* limitations under the License.
1313
**/
14-
14+
use models\main\Member;
1515
/**
1616
* Class PublicMemberSerializer
1717
* @package ModelSerializers
1818
*/
1919
final class PublicMemberSerializer extends AbstractMemberSerializer
2020
{
21+
/**
22+
* @param null $expand
23+
* @param array $fields
24+
* @param array $relations
25+
* @param array $params
26+
* @return array
27+
*/
28+
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = [])
29+
{
30+
$member = $this->object;
31+
if(!$member instanceof Member) return [];
32+
$values = parent::serialize($expand, $fields, $relations, $params);
33+
34+
// permissions check
35+
36+
if(!$member->isPublicProfileShowBio())
37+
{
38+
unset($values['bio']);
39+
unset($values['gender']);
40+
unset($values['company']);
41+
unset($values['state']);
42+
unset($values['country']);
43+
}
44+
45+
if(!$member->isPublicProfileShowSocialMediaInfo())
46+
{
47+
unset($values['github_user']);
48+
unset($values['linked_in']);
49+
unset($values['irc']);
50+
unset($values['twitter']);
51+
}
52+
53+
if(!$member->isPublicProfileShowPhoto())
54+
{
55+
unset($values['pic']);
56+
}
57+
58+
if(!$member->isPublicProfileShowFullname())
59+
{
60+
unset($values['first_name']);
61+
unset($values['last_name']);
62+
}
2163

64+
return $values;
65+
}
2266
}

app/ModelSerializers/Summit/Speakers/PresentationSpeakerSerializer.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,46 @@ public function serialize($expand = null, array $fields = [], array $relations =
318318
}
319319
}
320320

321+
// permissions check
322+
323+
if(!$speaker->isPublicProfileShowBio())
324+
{
325+
unset($values['bio']);
326+
unset($values['gender']);
327+
unset($values['company']);
328+
unset($values['state']);
329+
unset($values['country']);
330+
unset($values['title']);
331+
}
332+
333+
if(!$speaker->isPublicProfileShowEmail())
334+
{
335+
unset($values['email']);
336+
}
337+
338+
if(!$speaker->isPublicProfileShowSocialMediaInfo())
339+
{
340+
unset($values['irc']);
341+
unset($values['twitter']);
342+
}
343+
344+
if(!$speaker->isPublicProfileShowPhoto())
345+
{
346+
unset($values['pic']);
347+
unset($values['big_pic']);
348+
}
349+
350+
if(!$speaker->isPublicProfileShowFullname())
351+
{
352+
unset($values['first_name']);
353+
unset($values['last_name']);
354+
}
355+
356+
if(!$speaker->isPublicProfileShowTelephoneNumber())
357+
{
358+
unset($values['phone_number']);
359+
}
360+
321361
return $values;
322362
}
323363
}

app/Models/Foundation/Main/Factories/MemberFactory.php

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,13 @@
1212
* limitations under the License.
1313
**/
1414

15-
1615
use Illuminate\Support\Facades\Log;
1716
use models\main\Member;
1817

18+
/**
19+
* Class MemberFactory
20+
* @package App\Models\Foundation\Main\Factories
21+
*/
1922
final class MemberFactory
2023
{
2124
public static function populate(Member $member, array $payload):Member{
@@ -77,6 +80,14 @@ public static function populateFromExternalProfile(Member $member, int $user_ext
7780
$member->setIrcHandle($payload['irc'] ?? '');
7881
$member->setGender($payload['gender'] ?? '');
7982
$member->setTwitterHandle($payload['twitter_name'] ?? '');
83+
// permissions
84+
$member->setPublicProfileShowPhoto(to_boolean($payload['public_profile_show_photo']) ?? false);
85+
$member->setPublicProfileShowFullname(to_boolean($payload['public_profile_show_fullname']) ?? false);
86+
$member->setPublicProfileShowEmail(to_boolean($payload['public_profile_show_email']) ?? false);
87+
$member->setPublicProfileShowTelephoneNumber(to_boolean($payload['public_profile_show_telephone_number']) ?? false);
88+
$member->setPublicProfileShowBio(to_boolean($payload['public_profile_show_bio']) ?? false);
89+
$member->setPublicProfileShowSocialMediaInfo(to_boolean($payload['public_profile_show_social_media_info']) ?? false);
90+
$member->setPublicProfileAllowChatWithMe(to_boolean($payload['public_profile_allow_chat_with_me']) ?? false);
8091

8192
if(isset($payload['pic']))
8293
$member->setExternalPic($payload['pic']);
@@ -91,7 +102,6 @@ public static function populateFromExternalProfile(Member $member, int $user_ext
91102
* @return Member
92103
*/
93104
public static function createFromExternalProfile(int $user_external_id, array $payload):Member{
94-
95105
return self::populateFromExternalProfile(new Member(), $user_external_id, $payload);
96106
}
97107
}

app/Models/Foundation/Main/Member.php

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,48 @@ class Member extends SilverstripeBaseModel
254254
*/
255255
private $external_pic;
256256

257+
/**
258+
* @ORM\Column(name="PublicProfileShowPhoto", options={"default":0}, type="boolean")
259+
* @var bool
260+
*/
261+
private $public_profile_show_photo;
262+
263+
/**
264+
* @ORM\Column(name="PublicProfileShowFullName", options={"default":0}, type="boolean")
265+
* @var bool
266+
*/
267+
private $public_profile_show_fullname;
268+
269+
/**
270+
* @ORM\Column(name="PublicProfileShowEmail", options={"default":0}, type="boolean")
271+
* @var bool
272+
*/
273+
private $public_profile_show_email;
274+
275+
/**
276+
* @ORM\Column(name="PublicProfileAllowChatWithMe", options={"default":0}, type="boolean")
277+
* @var bool
278+
*/
279+
private $public_profile_allow_chat_with_me;
280+
281+
/**
282+
* @ORM\Column(name="PublicProfileShowSocialMediaInfo", options={"default":0}, type="boolean")
283+
* @var bool
284+
*/
285+
private $public_profile_show_social_media_info;
286+
287+
/**
288+
* @ORM\Column(name="PublicProfileShowBio", options={"default":0}, type="boolean")
289+
* @var bool
290+
*/
291+
private $public_profile_show_bio;
292+
293+
/**
294+
* @ORM\Column(name="PublicProfileShowTelephoneNumber", options={"default":0}, type="boolean")
295+
* @var bool
296+
*/
297+
private $public_profile_show_telephone_number;
298+
257299
/**
258300
* @ORM\OneToMany(targetEntity="SummitMemberSchedule", mappedBy="member", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY")
259301
* @var SummitMemberSchedule[]
@@ -422,6 +464,15 @@ public function __construct()
422464
$this->subscribed_to_newsletter = false;
423465
$this->display_on_site = false;
424466
$this->created_presentations = new ArrayCollection();
467+
468+
// user profile settings
469+
$this->public_profile_show_photo = false;
470+
$this->public_profile_show_email = false;
471+
$this->public_profile_show_fullname = true;
472+
$this->public_profile_allow_chat_with_me = false;
473+
$this->public_profile_show_social_media_info = false;
474+
$this->public_profile_show_bio = true;
475+
$this->public_profile_show_telephone_number = false;
425476
}
426477

427478
/**
@@ -3124,4 +3175,75 @@ public function isAuthzFor(Summit $summit, Sponsor $sponsor = null):bool{
31243175
return true;
31253176
return false;
31263177
}
3178+
3179+
public function isPublicProfileShowPhoto(): bool
3180+
{
3181+
return $this->public_profile_show_photo;
3182+
}
3183+
3184+
public function setPublicProfileShowPhoto(bool $public_profile_show_photo): void
3185+
{
3186+
$this->public_profile_show_photo = $public_profile_show_photo;
3187+
}
3188+
3189+
public function isPublicProfileShowFullname(): bool
3190+
{
3191+
return $this->public_profile_show_fullname;
3192+
}
3193+
3194+
public function setPublicProfileShowFullname(bool $public_profile_show_fullname): void
3195+
{
3196+
$this->public_profile_show_fullname = $public_profile_show_fullname;
3197+
}
3198+
3199+
public function isPublicProfileShowEmail(): bool
3200+
{
3201+
return $this->public_profile_show_email;
3202+
}
3203+
3204+
public function setPublicProfileShowEmail(bool $public_profile_show_email): void
3205+
{
3206+
$this->public_profile_show_email = $public_profile_show_email;
3207+
}
3208+
3209+
public function isPublicProfileAllowChatWithMe(): bool
3210+
{
3211+
return $this->public_profile_allow_chat_with_me;
3212+
}
3213+
3214+
public function setPublicProfileAllowChatWithMe(bool $public_profile_allow_chat_with_me): void
3215+
{
3216+
$this->public_profile_allow_chat_with_me = $public_profile_allow_chat_with_me;
3217+
}
3218+
3219+
public function isPublicProfileShowSocialMediaInfo(): bool
3220+
{
3221+
return $this->public_profile_show_social_media_info;
3222+
}
3223+
3224+
public function setPublicProfileShowSocialMediaInfo(bool $public_profile_show_social_media_info): void
3225+
{
3226+
$this->public_profile_show_social_media_info = $public_profile_show_social_media_info;
3227+
}
3228+
3229+
public function isPublicProfileShowBio(): bool
3230+
{
3231+
return $this->public_profile_show_bio;
3232+
}
3233+
3234+
public function setPublicProfileShowBio(bool $public_profile_show_bio): void
3235+
{
3236+
$this->public_profile_show_bio = $public_profile_show_bio;
3237+
}
3238+
3239+
public function isPublicProfileShowTelephoneNumber(): bool
3240+
{
3241+
return $this->public_profile_show_telephone_number;
3242+
}
3243+
3244+
public function setPublicProfileShowTelephoneNumber(bool $public_profile_show_telephone_number): void
3245+
{
3246+
$this->public_profile_show_telephone_number = $public_profile_show_telephone_number;
3247+
}
3248+
31273249
}

app/Models/Foundation/Summit/Speakers/PresentationSpeaker.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,4 +2478,48 @@ public function removeAnnouncementSummitEmail(SpeakerAnnouncementSummitEmail $an
24782478
}
24792479

24802480
use ScheduleEntity;
2481+
2482+
// profile data permissions
2483+
2484+
public function isPublicProfileShowPhoto(): bool
2485+
{
2486+
if(!$this->hasMember()) return false;
2487+
2488+
return $this->member->isPublicProfileShowPhoto();
2489+
}
2490+
2491+
public function isPublicProfileShowFullname(): bool
2492+
{
2493+
if(!$this->hasMember()) return false;
2494+
2495+
return $this->member->isPublicProfileShowFullname();
2496+
}
2497+
2498+
public function isPublicProfileShowEmail(): bool
2499+
{
2500+
if(!$this->hasMember()) return false;
2501+
2502+
return $this->member->isPublicProfileShowEmail();
2503+
}
2504+
2505+
public function isPublicProfileShowSocialMediaInfo(): bool
2506+
{
2507+
if(!$this->hasMember()) return false;
2508+
2509+
return $this->member->isPublicProfileShowSocialMediaInfo();
2510+
}
2511+
2512+
public function isPublicProfileShowBio(): bool
2513+
{
2514+
if(!$this->hasMember()) return false;
2515+
2516+
return $this->member->isPublicProfileShowBio();
2517+
}
2518+
2519+
public function isPublicProfileShowTelephoneNumber(): bool
2520+
{
2521+
if(!$this->hasMember()) return false;
2522+
2523+
return $this->member->isPublicProfileShowTelephoneNumber();
2524+
}
24812525
}

app/Services/Apis/ExternalUserApi.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,11 @@ public function getUserById(int $id)
185185
]
186186
);
187187

188-
return json_decode($response->getBody()->getContents(), true);
188+
$res = json_decode($response->getBody()->getContents(), true);
189+
190+
Log::debug(sprintf("ExternalUserApi::getUserById id %s res %s", $id, json_encode($res)));
191+
192+
return $res;
189193
}
190194
catch (RequestException $ex){
191195
$this->cleanAccessToken();
@@ -238,7 +242,9 @@ public function updateUser(int $id, ?string $first_name, ?string $last_name, ?st
238242
]
239243
);
240244

241-
return json_decode($response->getBody()->getContents(), true);
245+
$res = json_decode($response->getBody()->getContents(), true);
246+
Log::debug(sprintf("ExternalUserApi::updateUser id %s res %s", $id, json_encode($res)));
247+
return $res;
242248
}
243249
catch(RequestException $ex){
244250
$this->cleanAccessToken();

app/Services/Model/Imp/MemberService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ public function registerExternalUserById($user_external_id): Member
352352
$is_new = false;
353353
if(is_null($member)) {
354354
Log::debug(sprintf("MemberService::registerExternalUserById %s does not exists , creating it ...", $email));
355-
356355
$member = MemberFactory::createFromExternalProfile($user_external_id, $user_data);
357356
$this->member_repository->add($member, true);
358357
$is_new = true;

0 commit comments

Comments
 (0)