Fix on pics urls encoding

Change-Id: I8567856051e6781be18dae4eb77a63b2a8a817d4
This commit is contained in:
smarcet 2019-10-24 12:50:59 -03:00
parent f2439838b8
commit 14e58c4808
4 changed files with 33 additions and 20 deletions

View File

@ -1,5 +1,4 @@
<?php namespace Libs\ModelSerializers; <?php namespace Libs\ModelSerializers;
/** /**
* Copyright 2016 OpenStack Foundation * Copyright 2016 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
@ -12,11 +11,9 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
**/ **/
use libs\utils\JsonUtils; use libs\utils\JsonUtils;
use models\oauth2\IResourceServerContext; use models\oauth2\IResourceServerContext;
use models\utils\IEntity; use models\utils\IEntity;
/** /**
* Class AbstractSerializer * Class AbstractSerializer
* @package Libs\ModelSerializers * @package Libs\ModelSerializers
@ -188,6 +185,9 @@ abstract class AbstractSerializer implements IModelSerializer
{ {
$value = JsonUtils::toObfuscatedEmail($value); $value = JsonUtils::toObfuscatedEmail($value);
} }
case 'json_url':{
$value = JsonUtils::encodeUrl($value);
}
break; break;
} }
} }

View File

@ -44,6 +44,20 @@ abstract class JsonUtils
return $obfuscated_email; return $obfuscated_email;
} }
/**
* @param string $url
* @return string
*/
public static function encodeUrl(string $url):string{
$url= rawurlencode($url);
$url = str_replace("%3A",":", $url);
$url = str_replace("%2F","/", $url);
$url = str_replace("%3D","=", $url);
$url = str_replace("%3F","?", $url);
$url = str_replace("%26","&", $url);
return $url;
}
/** /**
* @param string $value * @param string $value
* @return bool * @return bool

View File

@ -35,6 +35,7 @@ class AbstractMemberSerializer extends SilverStripeSerializer
'Country' => 'country:json_string', 'Country' => 'country:json_string',
'Active' => 'active:json_boolean', 'Active' => 'active:json_boolean',
'EmailVerified' => 'email_verified:json_boolean', 'EmailVerified' => 'email_verified:json_boolean',
'ProfilePhotoUrl' => 'pic:json_url',
]; ];
protected static $allowed_relations = [ protected static $allowed_relations = [
@ -57,8 +58,7 @@ class AbstractMemberSerializer extends SilverStripeSerializer
if(!count($relations)) $relations = $this->getAllowedRelations(); if(!count($relations)) $relations = $this->getAllowedRelations();
$values = parent::serialize($expand, $fields, $relations, $params); $values = parent::serialize($expand, $fields, $relations, $params);
$values['pic'] = $member->getProfilePhotoUrl();
if(in_array('groups', $relations)) if(in_array('groups', $relations))
$values['groups'] = $member->getGroupsIds(); $values['groups'] = $member->getGroupsIds();

View File

@ -21,21 +21,22 @@ use models\summit\PresentationSpeaker;
class PresentationSpeakerSerializer extends SilverStripeSerializer class PresentationSpeakerSerializer extends SilverStripeSerializer
{ {
protected static $array_mappings = [ protected static $array_mappings = [
'FirstName' => 'first_name:json_string', 'FirstName' => 'first_name:json_string',
'LastName' => 'last_name:json_string', 'LastName' => 'last_name:json_string',
'Title' => 'title:json_string', 'Title' => 'title:json_string',
'Bio' => 'bio:json_string', 'Bio' => 'bio:json_string',
'IRCHandle' => 'irc:json_string', 'IRCHandle' => 'irc:json_string',
'TwitterName' => 'twitter:json_string', 'TwitterName' => 'twitter:json_string',
'OrgHasCloud' => 'org_has_cloud:json_boolean', 'OrgHasCloud' => 'org_has_cloud:json_boolean',
'Country' => 'country:json_string', 'Country' => 'country:json_string',
'AvailableForBureau' => 'available_for_bureau:json_boolean', 'AvailableForBureau' => 'available_for_bureau:json_boolean',
'FundedTravel' => 'funded_travel:json_boolean', 'FundedTravel' => 'funded_travel:json_boolean',
'WillingToTravel' => 'willing_to_travel:json_boolean', 'WillingToTravel' => 'willing_to_travel:json_boolean',
'WillingToPresentVideo' => 'willing_to_present_video:json_boolean', 'WillingToPresentVideo' => 'willing_to_present_video:json_boolean',
'Email' => 'email:json_obfuscated_email', 'Email' => 'email:json_obfuscated_email',
'MemberID' => 'member_id:json_int', 'MemberID' => 'member_id:json_int',
'RegistrationRequestId' => 'registration_request_id:json_int' 'RegistrationRequestId' => 'registration_request_id:json_int',
'ProfilePhotoUrl' => 'pic:json_url'
]; ];
protected static $allowed_relations = [ protected static $allowed_relations = [
@ -64,8 +65,6 @@ class PresentationSpeakerSerializer extends SilverStripeSerializer
$values['moderated_presentations'] = $speaker->getModeratedPresentationIds($summit_id, $published); $values['moderated_presentations'] = $speaker->getModeratedPresentationIds($summit_id, $published);
} }
$values['pic'] = $speaker->getProfilePhotoUrl();
if (in_array('member', $relations) && $speaker->hasMember()) if (in_array('member', $relations) && $speaker->hasMember())
{ {
$member = $speaker->getMember(); $member = $speaker->getMember();