Permalink
Browse files

COM-20083: Package submission page (Permission Fix) (ezsystems#155)

  • Loading branch information...
ciastektk authored and damianz5 committed Feb 4, 2019
1 parent d811a6c commit f3a895a23cb9ea897db3836883ecd7955b931f1a
@@ -10,7 +10,8 @@ parameters:
release_container_location_id: 57
# `folder` in the media library containing all the betas
beta_container_location_id: 58

# package contributor id
package_contributor_id: 452
# `blog` locationId
blog.location_id: 71
# `blog_post` limit on the `blog` page
@@ -10,6 +10,7 @@ services:
arguments:
$parentLocationId: '%packages.location_id%'
$tagsService: '@ezpublish.api.service.tags'
$packageContributorId: '%package_contributor_id%'

AppBundle\Service\Cache\CacheService:
arguments:
@@ -6,3 +6,7 @@ services:

AppBundle\Validator\:
resource: '../../../src/AppBundle/Validator/*'

AppBundle\Validator\Constraints\PackageDbNotExistsConstraintValidator:
arguments:
$packageContributorId: '%package_contributor_id%'
@@ -8,6 +8,8 @@
*/
namespace AppBundle\Service;
use eZ\Publish\API\Repository\PermissionResolver as PermissionResolverInterface;
use eZ\Publish\API\Repository\UserService as UserServiceInterface;
use eZ\Publish\API\Repository\ContentService as ContentServiceInterface;
use eZ\Publish\API\Repository\ContentTypeService as ContentTypeServiceInterface;
use eZ\Publish\API\Repository\LocationService as LocationServiceInterface;
@@ -19,6 +21,16 @@
*/
abstract class AbstractService
{
/**
* @var \eZ\Publish\API\Repository\PermissionResolver
*/
protected $permissionResolver;
/**
* @var \eZ\Publish\API\Repository\UserService
*/
protected $userService;
/**
* @var \eZ\Publish\API\Repository\ContentTypeService
*/
@@ -35,10 +47,14 @@ abstract class AbstractService
protected $locationService;
public function __construct(
PermissionResolverInterface $permissionResolver,
UserServiceInterface $userService,
ContentTypeServiceInterface $contentTypeService,
ContentServiceInterface $contentService,
LocationServiceInterface $locationService
) {
$this->permissionResolver = $permissionResolver;
$this->userService = $userService;
$this->contentTypeService = $contentTypeService;
$this->contentService = $contentService;
$this->locationService = $locationService;
@@ -12,6 +12,8 @@
use AppBundle\Service\Cache\CacheServiceInterface;
use AppBundle\Service\DOM\DOMServiceInterface;
use AppBundle\Service\GitHub\GitHubServiceProvider;
use eZ\Publish\API\Repository\PermissionResolver as PermissionResolverInterface;
use eZ\Publish\API\Repository\UserService as UserServiceInterface;
use AppBundle\Service\PackageRepository\PackageRepositoryServiceInterface;
use AppBundle\Service\Packagist\PackagistServiceProviderInterface;
use AppBundle\ValueObject\Package;
@@ -36,22 +38,22 @@ class PackageService extends AbstractService implements PackageServiceInterface
static $DEFAULT_LANG_CODE = 'eng-GB';
/**
* @var PackagistServiceProviderInterface
* @var \AppBundle\Service\Packagist\PackagistServiceProviderInterface
*/
private $packagistServiceProvider;
/**
* @var PackageRepositoryServiceInterface
* @var \AppBundle\Service\Packagist\PackagistServiceProviderInterface
*/
private $packageRepositoryService;
/**
* @var CacheServiceInterface $cacheService
* @var \AppBundle\Service\Cache\CacheServiceInterface
*/
private $cacheService;
/**
* @var DOMServiceInterface $domService
* @var \AppBundle\Service\DOM\DOMServiceInterface
*/
private $domService;
@@ -65,7 +67,14 @@ class PackageService extends AbstractService implements PackageServiceInterface
*/
private $parentLocationId;
/**
* @var int
*/
private $packageContributorId;
public function __construct(
PermissionResolverInterface $permissionResolver,
UserServiceInterface $userService,
ContentTypeServiceInterface $contentTypeService,
ContentServiceInterface $contentService,
LocationServiceInterface $locationService,
@@ -74,16 +83,18 @@ public function __construct(
CacheServiceInterface $cacheService,
DOMServiceInterface $domService,
TagsServiceInterface $tagsService,
int $parentLocationId
int $parentLocationId,
int $packageContributorId
) {
$this->packagistServiceProvider = $packagistServiceProvider;
$this->packageRepositoryService = $packageRepositoryService;
$this->cacheService = $cacheService;
$this->domService = $domService;
$this->tagsService = $tagsService;
$this->parentLocationId = $parentLocationId;
$this->packageContributorId = $packageContributorId;
parent::__construct($contentTypeService, $contentService, $locationService);
parent::__construct($permissionResolver, $userService, $contentTypeService, $contentService, $locationService);
}
/**
@@ -106,6 +117,10 @@ public function addPackage(array $formData): Content
$packageName = $formData['name'] ?? '';
$packageCategories = $formData['categories'] ?? [];
$this->permissionResolver->setCurrentUserReference(
$this->userService->loadUser($this->packageContributorId)
);
$packageDetails = $this->getPackageDetails($this->getPackageIdFromUrl($packageUrl));
$contentCreateStruct->setField('package_id', $packageDetails->packageId);
@@ -228,7 +243,7 @@ private function getXmlString($stringToXml): string
{
$escapedString = htmlspecialchars($stringToXml, ENT_XML1);
$xmlText = <<< EOX
return <<< EOX
<?xml version='1.0' encoding='utf-8'?>
<section
xmlns="http://docbook.org/ns/docbook"
@@ -239,6 +254,5 @@ private function getXmlString($stringToXml): string
<para>{$escapedString}</para>
</section>
EOX;
return $xmlText;
}
}
@@ -10,7 +10,9 @@
use AppBundle\Url\UrlBuilder;
use AppBundle\ValueObject\RepositoryMetadata;
use eZ\Publish\API\Repository\PermissionResolver as PermissionResolverInterface;
use eZ\Publish\API\Repository\SearchService as SearchServiceInterface;
use eZ\Publish\API\Repository\UserService as UserServiceInterface;
use eZ\Publish\API\Repository\Values\Content\Query;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\ContentTypeIdentifier;
use eZ\Publish\API\Repository\Values\Content\Query\Criterion\Field;
@@ -34,6 +36,16 @@ class PackageDbNotExistsConstraintValidator extends ConstraintValidator
'name' => 'package name'
];
/**
* @var \eZ\Publish\API\Repository\PermissionResolver
*/
private $permissionResolver;
/**
* @var \eZ\Publish\API\Repository\UserService
*/
private $userService;
/**
* @var \eZ\Publish\API\Repository\SearchService
*/
@@ -49,21 +61,33 @@ class PackageDbNotExistsConstraintValidator extends ConstraintValidator
*/
private $urlBuilder;
/**
* @var int
*/
private $packageContributorId;
public function __construct(
PermissionResolverInterface $permissionResolver,
UserServiceInterface $userService,
SearchServiceInterface $searchService,
ContentDraftsDataset $contentDraftsDataset,
UrlBuilder $urlBuilder
UrlBuilder $urlBuilder,
int $packageContributorId
) {
$this->permissionResolver = $permissionResolver;
$this->userService = $userService;
$this->searchService = $searchService;
$this->contentDraftsDataset = $contentDraftsDataset;
$this->urlBuilder = $urlBuilder;
$this->packageContributorId = $packageContributorId;
}
/**
* @param mixed $value
* @param Constraint $constraint
*
* @throws \eZ\Publish\API\Repository\Exceptions\InvalidArgumentException
* @throws \eZ\Publish\API\Repository\Exceptions\NotFoundException
*/
public function validate($value, Constraint $constraint)
{
@@ -81,6 +105,10 @@ public function validate($value, Constraint $constraint)
'search' => $value
];
$this->permissionResolver->setCurrentUserReference(
$this->userService->loadUser($this->packageContributorId)
);
$drafts = $this->contentDraftsDataset->load();
$repositoryMetadata = new RepositoryMetadata($value);
@@ -340,5 +340,6 @@ section#top-banner {
}

.btn.btn-blue {
color: $white;
background-color: #0094ce;
}

0 comments on commit f3a895a

Please sign in to comment.