Skip to content

Commit

Permalink
feat: profile data permissions from IDP
Browse files Browse the repository at this point in the history
  • Loading branch information
smarcet committed Jul 22, 2024
1 parent 7587f06 commit 7a2c68b
Show file tree
Hide file tree
Showing 9 changed files with 351 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/ModelSerializers/AbstractMemberSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ class AbstractMemberSerializer extends SilverStripeSerializer
protected static $array_mappings = [
'FirstName' => 'first_name:json_string',
'LastName' => 'last_name:json_string',
'Bio' => 'bio:json_string',
'Gender' => 'gender:json_string',
'GitHubUser' => 'github_user:json_string',
'Bio' => 'bio:json_string',
'LinkedInProfile' => 'linked_in:json_string',
'IrcHandle' => 'irc:json_string',
'TwitterHandle' => 'twitter:json_string',
Expand Down
46 changes: 45 additions & 1 deletion app/ModelSerializers/PublicMemberSerializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,56 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/

use models\main\Member;
/**
* Class PublicMemberSerializer
* @package ModelSerializers
*/
final class PublicMemberSerializer extends AbstractMemberSerializer
{
/**
* @param null $expand
* @param array $fields
* @param array $relations
* @param array $params
* @return array
*/
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = [])
{
$member = $this->object;
if(!$member instanceof Member) return [];
$values = parent::serialize($expand, $fields, $relations, $params);

// permissions check

if(!$member->isPublicProfileShowBio())
{
unset($values['bio']);
unset($values['gender']);
unset($values['company']);
unset($values['state']);
unset($values['country']);
}

if(!$member->isPublicProfileShowSocialMediaInfo())
{
unset($values['github_user']);
unset($values['linked_in']);
unset($values['irc']);
unset($values['twitter']);
}

if(!$member->isPublicProfileShowPhoto())
{
unset($values['pic']);
}

if(!$member->isPublicProfileShowFullname())
{
unset($values['first_name']);
unset($values['last_name']);
}

return $values;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,54 @@ public function serialize($expand = null, array $fields = [], array $relations =
}
}

// permissions check

if(!$speaker->isPublicProfileShowBio())
{
unset($values['bio']);
unset($values['gender']);
unset($values['company']);
unset($values['state']);
unset($values['country']);
unset($values['title']);
unset($values['affiliations']);
unset($values['languages']);
unset($values['other_presentation_links']);
unset($values['areas_of_expertise']);
unset($values['travel_preferences']);
unset($values['active_involvements']);
unset($values['organizational_roles']);
unset($values['badge_features']);
}

if(!$speaker->isPublicProfileShowEmail())
{
unset($values['email']);
}

if(!$speaker->isPublicProfileShowSocialMediaInfo())
{
unset($values['irc']);
unset($values['twitter']);
}

if(!$speaker->isPublicProfileShowPhoto())
{
unset($values['pic']);
unset($values['big_pic']);
}

if(!$speaker->isPublicProfileShowFullname())
{
unset($values['first_name']);
unset($values['last_name']);
}

if(!$speaker->isPublicProfileShowTelephoneNumber())
{
unset($values['phone_number']);
}

return $values;
}
}
14 changes: 12 additions & 2 deletions app/Models/Foundation/Main/Factories/MemberFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@
* limitations under the License.
**/


use Illuminate\Support\Facades\Log;
use models\main\Member;

/**
* Class MemberFactory
* @package App\Models\Foundation\Main\Factories
*/
final class MemberFactory
{
public static function populate(Member $member, array $payload):Member{
Expand Down Expand Up @@ -77,6 +80,14 @@ public static function populateFromExternalProfile(Member $member, int $user_ext
$member->setIrcHandle($payload['irc'] ?? '');
$member->setGender($payload['gender'] ?? '');
$member->setTwitterHandle($payload['twitter_name'] ?? '');
// permissions
$member->setPublicProfileShowPhoto(to_boolean($payload['public_profile_show_photo']) ?? false);
$member->setPublicProfileShowFullname(to_boolean($payload['public_profile_show_fullname']) ?? false);
$member->setPublicProfileShowEmail(to_boolean($payload['public_profile_show_email']) ?? false);
$member->setPublicProfileShowTelephoneNumber(to_boolean($payload['public_profile_show_telephone_number']) ?? false);
$member->setPublicProfileShowBio(to_boolean($payload['public_profile_show_bio']) ?? false);
$member->setPublicProfileShowSocialMediaInfo(to_boolean($payload['public_profile_show_social_media_info']) ?? false);
$member->setPublicProfileAllowChatWithMe(to_boolean($payload['public_profile_allow_chat_with_me']) ?? false);

if(isset($payload['pic']))
$member->setExternalPic($payload['pic']);
Expand All @@ -91,7 +102,6 @@ public static function populateFromExternalProfile(Member $member, int $user_ext
* @return Member
*/
public static function createFromExternalProfile(int $user_external_id, array $payload):Member{

return self::populateFromExternalProfile(new Member(), $user_external_id, $payload);
}
}
122 changes: 122 additions & 0 deletions app/Models/Foundation/Main/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,48 @@ class Member extends SilverstripeBaseModel
*/
private $external_pic;

/**
* @ORM\Column(name="PublicProfileShowPhoto", options={"default":0}, type="boolean")
* @var bool
*/
private $public_profile_show_photo;

/**
* @ORM\Column(name="PublicProfileShowFullName", options={"default":0}, type="boolean")
* @var bool
*/
private $public_profile_show_fullname;

/**
* @ORM\Column(name="PublicProfileShowEmail", options={"default":0}, type="boolean")
* @var bool
*/
private $public_profile_show_email;

/**
* @ORM\Column(name="PublicProfileAllowChatWithMe", options={"default":0}, type="boolean")
* @var bool
*/
private $public_profile_allow_chat_with_me;

/**
* @ORM\Column(name="PublicProfileShowSocialMediaInfo", options={"default":0}, type="boolean")
* @var bool
*/
private $public_profile_show_social_media_info;

/**
* @ORM\Column(name="PublicProfileShowBio", options={"default":0}, type="boolean")
* @var bool
*/
private $public_profile_show_bio;

/**
* @ORM\Column(name="PublicProfileShowTelephoneNumber", options={"default":0}, type="boolean")
* @var bool
*/
private $public_profile_show_telephone_number;

/**
* @ORM\OneToMany(targetEntity="SummitMemberSchedule", mappedBy="member", cascade={"persist"}, orphanRemoval=true, fetch="EXTRA_LAZY")
* @var SummitMemberSchedule[]
Expand Down Expand Up @@ -422,6 +464,15 @@ public function __construct()
$this->subscribed_to_newsletter = false;
$this->display_on_site = false;
$this->created_presentations = new ArrayCollection();

// user profile settings
$this->public_profile_show_photo = false;
$this->public_profile_show_email = false;
$this->public_profile_show_fullname = true;
$this->public_profile_allow_chat_with_me = false;
$this->public_profile_show_social_media_info = false;
$this->public_profile_show_bio = true;
$this->public_profile_show_telephone_number = false;
}

/**
Expand Down Expand Up @@ -3124,4 +3175,75 @@ public function isAuthzFor(Summit $summit, Sponsor $sponsor = null):bool{
return true;
return false;
}

public function isPublicProfileShowPhoto(): bool
{
return $this->public_profile_show_photo;
}

public function setPublicProfileShowPhoto(bool $public_profile_show_photo): void
{
$this->public_profile_show_photo = $public_profile_show_photo;
}

public function isPublicProfileShowFullname(): bool
{
return $this->public_profile_show_fullname;
}

public function setPublicProfileShowFullname(bool $public_profile_show_fullname): void
{
$this->public_profile_show_fullname = $public_profile_show_fullname;
}

public function isPublicProfileShowEmail(): bool
{
return $this->public_profile_show_email;
}

public function setPublicProfileShowEmail(bool $public_profile_show_email): void
{
$this->public_profile_show_email = $public_profile_show_email;
}

public function isPublicProfileAllowChatWithMe(): bool
{
return $this->public_profile_allow_chat_with_me;
}

public function setPublicProfileAllowChatWithMe(bool $public_profile_allow_chat_with_me): void
{
$this->public_profile_allow_chat_with_me = $public_profile_allow_chat_with_me;
}

public function isPublicProfileShowSocialMediaInfo(): bool
{
return $this->public_profile_show_social_media_info;
}

public function setPublicProfileShowSocialMediaInfo(bool $public_profile_show_social_media_info): void
{
$this->public_profile_show_social_media_info = $public_profile_show_social_media_info;
}

public function isPublicProfileShowBio(): bool
{
return $this->public_profile_show_bio;
}

public function setPublicProfileShowBio(bool $public_profile_show_bio): void
{
$this->public_profile_show_bio = $public_profile_show_bio;
}

public function isPublicProfileShowTelephoneNumber(): bool
{
return $this->public_profile_show_telephone_number;
}

public function setPublicProfileShowTelephoneNumber(bool $public_profile_show_telephone_number): void
{
$this->public_profile_show_telephone_number = $public_profile_show_telephone_number;
}

}
44 changes: 44 additions & 0 deletions app/Models/Foundation/Summit/Speakers/PresentationSpeaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2478,4 +2478,48 @@ public function removeAnnouncementSummitEmail(SpeakerAnnouncementSummitEmail $an
}

use ScheduleEntity;

// profile data permissions

public function isPublicProfileShowPhoto(): bool
{
if(!$this->hasMember()) return false;

return $this->member->isPublicProfileShowPhoto();
}

public function isPublicProfileShowFullname(): bool
{
if(!$this->hasMember()) return false;

return $this->member->isPublicProfileShowFullname();
}

public function isPublicProfileShowEmail(): bool
{
if(!$this->hasMember()) return false;

return $this->member->isPublicProfileShowEmail();
}

public function isPublicProfileShowSocialMediaInfo(): bool
{
if(!$this->hasMember()) return false;

return $this->member->isPublicProfileShowSocialMediaInfo();
}

public function isPublicProfileShowBio(): bool
{
if(!$this->hasMember()) return false;

return $this->member->isPublicProfileShowBio();
}

public function isPublicProfileShowTelephoneNumber(): bool
{
if(!$this->hasMember()) return false;

return $this->member->isPublicProfileShowTelephoneNumber();
}
}
10 changes: 8 additions & 2 deletions app/Services/Apis/ExternalUserApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,11 @@ public function getUserById(int $id)
]
);

return json_decode($response->getBody()->getContents(), true);
$res = json_decode($response->getBody()->getContents(), true);

Log::debug(sprintf("ExternalUserApi::getUserById id %s res %s", $id, json_encode($res)));

return $res;
}
catch (RequestException $ex){
$this->cleanAccessToken();
Expand Down Expand Up @@ -238,7 +242,9 @@ public function updateUser(int $id, ?string $first_name, ?string $last_name, ?st
]
);

return json_decode($response->getBody()->getContents(), true);
$res = json_decode($response->getBody()->getContents(), true);
Log::debug(sprintf("ExternalUserApi::updateUser id %s res %s", $id, json_encode($res)));
return $res;
}
catch(RequestException $ex){
$this->cleanAccessToken();
Expand Down
1 change: 0 additions & 1 deletion app/Services/Model/Imp/MemberService.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,6 @@ public function registerExternalUserById($user_external_id): Member
$is_new = false;
if(is_null($member)) {
Log::debug(sprintf("MemberService::registerExternalUserById %s does not exists , creating it ...", $email));

$member = MemberFactory::createFromExternalProfile($user_external_id, $user_data);
$this->member_repository->add($member, true);
$is_new = true;
Expand Down
Loading

0 comments on commit 7a2c68b

Please sign in to comment.