Skip to content

Commit fec9f12

Browse files
committed
feat: added summit secondary_logo attribute
Added new endpoints POST api/v1/summits/{id}/logo/secondary payload file DELETE api/v1/summits/{id}/logo/secondary Change-Id: I23b9fcf7525b966238c21cf804c82b806e9f89e0
1 parent 0973e2c commit fec9f12

8 files changed

Lines changed: 278 additions & 8 deletions

File tree

app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitApiController.php

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,61 @@ public function deleteSummitLogo($summit_id)
725725
});
726726
}
727727

728+
/**
729+
* @param LaravelRequest $request
730+
* @param $summit_id
731+
* @return JsonResponse|mixed
732+
*/
733+
public function addSummitSecondaryLogo(LaravelRequest $request, $summit_id)
734+
{
735+
return $this->processRequest(function () use ($request, $summit_id) {
736+
737+
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
738+
if (is_null($summit)) return $this->error404();
739+
740+
$file = $request->file('file');
741+
if (is_null($file)) {
742+
return $this->error412(array('file param not set!'));
743+
}
744+
745+
$current_member = $this->resource_server_context->getCurrentUser();
746+
if (!is_null($current_member) && !$current_member->isAdmin() && !$current_member->hasPermissionForOnGroup($summit, IGroup::SummitAdministrators))
747+
return $this->error403(['message' => sprintf("Member %s has not permission for this Summit", $current_member->getId())]);
748+
749+
$photo = $this->summit_service->addSummitSecondaryLogo($summit_id, $file);
750+
751+
return $this->created(SerializerRegistry::getInstance()->getSerializer($photo)->serialize
752+
(
753+
SerializerUtils::getExpand(),
754+
SerializerUtils::getFields(),
755+
SerializerUtils::getRelations()
756+
));
757+
758+
});
759+
}
760+
761+
/**
762+
* @param $summit_id
763+
* @return JsonResponse|mixed
764+
*/
765+
public function deleteSummitSecondaryLogo($summit_id)
766+
{
767+
return $this->processRequest(function() use($summit_id){
768+
769+
$summit = SummitFinderStrategyFactory::build($this->repository, $this->resource_server_context)->find($summit_id);
770+
if (is_null($summit)) return $this->error404();
771+
772+
$current_member = $this->resource_server_context->getCurrentUser();
773+
if (!is_null($current_member) && !$current_member->isAdmin() && !$current_member->hasPermissionForOnGroup($summit, IGroup::SummitAdministrators))
774+
return $this->error403(['message' => sprintf("Member %s has not permission for this Summit", $current_member->getId())]);
775+
776+
$this->summit_service->deleteSummitSecondaryLogo($summit_id);
777+
778+
return $this->deleted();
779+
780+
});
781+
}
782+
728783
/**
729784
* @param $summit_id
730785
* @param $speaker_id

app/ModelSerializers/Summit/SummitSerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class SummitSerializer extends SilverStripeSerializer
5151
'BeginAllowBookingDate' => 'begin_allow_booking_date:datetime_epoch',
5252
'EndAllowBookingDate' => 'end_allow_booking_date:datetime_epoch',
5353
'LogoUrl' => 'logo:json_url',
54-
54+
'SecondaryLogoUrl' => 'secondary_logo:json_url',
5555
// registration
5656
'OrderQRPrefix' => 'order_qr_prefix:json_string',
5757
'TicketQRPrefix' => 'ticket_qr_prefix:json_string',

app/Models/Foundation/Summit/Summit.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,13 @@ public function setMarketingSiteOauth2ClientScopes(string $marketing_site_oauth2
601601
*/
602602
private $logo;
603603

604+
/**
605+
* @ORM\ManyToOne(targetEntity="models\main\File", cascade={"persist"})
606+
* @ORM\JoinColumn(name="SecondaryLogoID", referencedColumnName="ID")
607+
* @var File
608+
*/
609+
private $secondary_logo;
610+
604611
/**
605612
* @ORM\Column(name="ApiFeedType", type="string")
606613
* @var string
@@ -1481,6 +1488,47 @@ public function getLogoId()
14811488
}
14821489
}
14831490

1491+
/**
1492+
* @return File
1493+
*/
1494+
public function getSecondaryLogo()
1495+
{
1496+
return $this->secondary_logo;
1497+
}
1498+
1499+
/**
1500+
* @param File $secondary_logo
1501+
*/
1502+
public function setSecondaryLogo(File $secondary_logo): void
1503+
{
1504+
$this->secondary_logo = $secondary_logo;
1505+
}
1506+
1507+
public function clearSecondaryLogo(): void
1508+
{
1509+
$this->secondary_logo = null;
1510+
}
1511+
1512+
/**
1513+
* @return bool
1514+
*/
1515+
public function hasSecondaryLogo()
1516+
{
1517+
return $this->getSecondaryLogoId() > 0;
1518+
}
1519+
1520+
/**
1521+
* @return int
1522+
*/
1523+
public function getSecondaryLogoId()
1524+
{
1525+
try {
1526+
return !is_null($this->secondary_logo) ? $this->secondary_logo->getId() : 0;
1527+
} catch (\Exception $ex) {
1528+
return 0;
1529+
}
1530+
}
1531+
14841532
/**
14851533
* @param int $location_id
14861534
* @return SummitAbstractLocation
@@ -3985,6 +4033,19 @@ public function getLogoUrl(): ?string
39854033
return $logoUrl;
39864034
}
39874035

4036+
4037+
/**
4038+
* @return string
4039+
*/
4040+
public function getSecondaryLogoUrl(): ?string
4041+
{
4042+
$logoUrl = null;
4043+
if ($this->hasSecondaryLogo() && $logo = $this->getSecondaryLogo()) {
4044+
$logoUrl = $logo->getUrl();
4045+
}
4046+
return $logoUrl;
4047+
}
4048+
39884049
public function getReassignTicketTillDate(): ?DateTime
39894050
{
39904051
return $this->reassign_ticket_till_date;

app/Services/Model/ISummitService.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,23 @@ public function addSummitLogo(int $summit_id, UploadedFile $file, $max_file_siz
377377
*/
378378
public function deleteSummitLogo(int $summit_id):void;
379379

380+
/**
381+
* @param int $summit_id
382+
* @param UploadedFile $file
383+
* @param int $max_file_size
384+
* @throws ValidationException
385+
* @throws EntityNotFoundException
386+
* @return File
387+
*/
388+
public function addSummitSecondaryLogo(int $summit_id, UploadedFile $file, $max_file_size = 10485760);
389+
390+
/**
391+
* @param int $summit
392+
* @throws ValidationException
393+
* @throws EntityNotFoundException
394+
*/
395+
public function deleteSummitSecondaryLogo(int $summit_id):void;
396+
380397
/**
381398
* @param Summit $summit
382399
* @param Member $member

app/Services/Model/Imp/SummitService.php

Lines changed: 58 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2129,7 +2129,6 @@ public function deleteBookableRoomAttributeValue(Summit $summit, int $type_id, i
21292129
});
21302130
}
21312131

2132-
21332132
/**
21342133
* @param int $summit_id
21352134
* @param UploadedFile $file
@@ -2146,8 +2145,8 @@ public function addSummitLogo(int $summit_id, UploadedFile $file, $max_file_size
21462145

21472146
$summit = $this->summit_repository->getById($summit_id);
21482147

2149-
if (is_null($summit) || !$summit instanceof Summit) {
2150-
throw new EntityNotFoundException('summit not found!');
2148+
if (!$summit instanceof Summit) {
2149+
throw new EntityNotFoundException('Summit not found.');
21512150
}
21522151

21532152
if (!in_array($file->extension(), $allowed_extensions)) {
@@ -2176,14 +2175,68 @@ public function deleteSummitLogo(int $summit_id): void
21762175

21772176
$summit = $this->summit_repository->getById($summit_id);
21782177

2179-
if (is_null($summit) || !$summit instanceof Summit) {
2180-
throw new EntityNotFoundException('summit not found!');
2178+
if (!$summit instanceof Summit) {
2179+
throw new EntityNotFoundException('Summit not found.');
21812180
}
21822181

21832182
$summit->clearLogo();
21842183
});
21852184
}
21862185

2186+
/**
2187+
* @param int $summit_id
2188+
* @param UploadedFile $file
2189+
* @param int $max_file_size
2190+
* @return File
2191+
* @throws EntityNotFoundException
2192+
* @throws ValidationException
2193+
*/
2194+
public function addSummitSecondaryLogo(int $summit_id, UploadedFile $file, $max_file_size = 10485760)
2195+
{
2196+
return $this->tx_service->transaction(function () use ($summit_id, $file, $max_file_size) {
2197+
2198+
$allowed_extensions = ['png', 'jpg', 'jpeg', 'gif', 'svg', 'jfif'];
2199+
2200+
$summit = $this->summit_repository->getById($summit_id);
2201+
2202+
if (!$summit instanceof Summit) {
2203+
throw new EntityNotFoundException('Summit not found.');
2204+
}
2205+
2206+
if (!in_array($file->extension(), $allowed_extensions)) {
2207+
throw new ValidationException(sprintf("file does not has a valid extension (%s).", implode(",", $allowed_extensions)));
2208+
}
2209+
2210+
if ($file->getSize() > $max_file_size) {
2211+
throw new ValidationException(sprintf("file exceeds max_file_size (%s MB).", ($max_file_size / 1024) / 1024));
2212+
}
2213+
2214+
$photo = $this->file_uploader->build($file, sprintf('summits/%s', $summit->getId()), true);
2215+
$summit->setSecondaryLogo($photo);
2216+
2217+
return $photo;
2218+
});
2219+
}
2220+
2221+
/**
2222+
* @param int $summit_id
2223+
* @throws ValidationException
2224+
* @throws EntityNotFoundException
2225+
*/
2226+
public function deleteSummitSecondaryLogo(int $summit_id): void
2227+
{
2228+
$this->tx_service->transaction(function () use ($summit_id) {
2229+
2230+
$summit = $this->summit_repository->getById($summit_id);
2231+
2232+
if (!$summit instanceof Summit) {
2233+
throw new EntityNotFoundException('Summit not found.');
2234+
}
2235+
2236+
$summit->clearSecondaryLogo();
2237+
});
2238+
}
2239+
21872240
/**
21882241
* @param Summit $summit
21892242
* @param Member $member
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?php namespace Database\Migrations\Model;
2+
/**
3+
* Copyright 2023 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 Version20231204203518
21+
* @package Database\Migrations\Model
22+
*/
23+
final class Version20231204203518 extends AbstractMigration
24+
{
25+
/**
26+
* @param Schema $schema
27+
*/
28+
public function up(Schema $schema): void
29+
{
30+
$builder = new Builder($schema);
31+
32+
if($schema->hasTable("Summit")) {
33+
$builder->table('Summit', function (Table $table) {
34+
$table->integer("SecondaryLogoID", false, false)->setNotnull(false)->setDefault('NULL');
35+
$table->index("SecondaryLogoID", "SecondaryLogoID");
36+
$table->foreign("File", "SecondaryLogoID", "ID", ["onDelete" => "CASCADE"]);
37+
});
38+
}
39+
}
40+
41+
/**
42+
* @param Schema $schema
43+
*/
44+
public function down(Schema $schema): void
45+
{
46+
$builder = new Builder($schema);
47+
if($schema->hasTable("Summit")) {
48+
$builder->table('Summit', function (Table $table) {
49+
$table->dropColumn('SecondaryLogoID');
50+
});
51+
}
52+
}
53+
}

database/seeders/ApiEndpointsSeeder.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,32 @@ private function seedSummitEndpoints()
12231223
IGroup::SummitAdministrators,
12241224
]
12251225
],
1226+
[
1227+
'name' => 'add-summit-logo-secondary',
1228+
'route' => '/api/v1/summits/{id}/logo/secondary',
1229+
'http_method' => 'POST',
1230+
'scopes' => [
1231+
sprintf(SummitScopes::WriteSummitData, $current_realm),
1232+
],
1233+
'authz_groups' => [
1234+
IGroup::SuperAdmins,
1235+
IGroup::Administrators,
1236+
IGroup::SummitAdministrators,
1237+
]
1238+
],
1239+
[
1240+
'name' => 'delete-summit-logo-secondary',
1241+
'route' => '/api/v1/summits/{id}/logo/secondary',
1242+
'http_method' => 'DELETE',
1243+
'scopes' => [
1244+
sprintf(SummitScopes::WriteSummitData, $current_realm),
1245+
],
1246+
'authz_groups' => [
1247+
IGroup::SuperAdmins,
1248+
IGroup::Administrators,
1249+
IGroup::SummitAdministrators,
1250+
]
1251+
],
12261252
[
12271253
'name' => 'delete-summit',
12281254
'route' => '/api/v1/summits/{id}',

routes/api_v1.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,8 +261,13 @@
261261
});
262262

263263
Route::put('', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitApiController@updateSummit']);
264-
Route::post('logo', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitApiController@addSummitLogo']);
265-
Route::delete('logo', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitApiController@deleteSummitLogo']);
264+
Route::group(['prefix' => 'logo'], function () {
265+
Route::post('', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitApiController@addSummitLogo']);
266+
Route::delete('', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitApiController@deleteSummitLogo']);
267+
Route::post('secondary', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitApiController@addSummitLogo']);
268+
Route::delete('secondary', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitApiController@deleteSummitLogo']);
269+
});
270+
266271
Route::delete('', ['middleware' => 'auth.user', 'uses' => 'OAuth2SummitApiController@deleteSummit']);
267272
Route::get('', ['middleware' => 'cache:' . Config::get('cache_api_response.get_summit_response_lifetime', 1200), 'uses' => 'OAuth2SummitApiController@getSummit'])->where('id', 'current|[0-9]+');
268273

0 commit comments

Comments
 (0)