Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Various v4 fixes #2055

Merged
merged 6 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/Controller/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -1949,6 +1949,12 @@ function delete(Request $request, Response $response, $id)
throw new AccessDeniedException();
}

if ($display->isLead()) {
throw new InvalidArgumentException(
__('Cannot delete a Lead Display of a Sync Group'),
);
}

$display->delete();

// Return
Expand Down
14 changes: 13 additions & 1 deletion lib/Controller/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,11 +334,23 @@ public function delete(Request $request, Response $response, $folderId)
throw new AccessDeniedException();
}

if ($folder->isHome()) {
throw new InvalidArgumentException(
__('Cannot remove Folder set as home Folder for a user'),
'folderId',
__('Change home Folder for Users using this Folder before deleting')
);
}

try {
$folder->delete();
} catch (\Exception $exception) {
$this->getLog()->debug('Folder delete failed with message: ' . $exception->getMessage());
throw new InvalidArgumentException(__('Cannot remove Folder with content'), 'folderId', __('Reassign objects from this Folder before deleting.'));
throw new InvalidArgumentException(
__('Cannot remove Folder with content'),
'folderId',
__('Reassign objects from this Folder before deleting.')
);
}

// Return
Expand Down
32 changes: 31 additions & 1 deletion lib/Controller/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,36 @@ public function grid(Request $request, Response $response)
{
$params = $this->getSanitizer($request->getParams());

$displayGroupIds = $params->getIntArray('displayGroupIds', ['default' => []]);
$originalDisplayGroupIds = $displayGroupIds;

if (!$this->getUser()->isSuperAdmin()) {
$userDisplayGroupIds = array_map(function ($element) {
/** @var \Xibo\Entity\DisplayGroup $element */
return $element->displayGroupId;
}, $this->displayGroupFactory->query(null, ['isDisplaySpecific' => -1]));

// Reset the list to only those display groups that intersect and if 0 have been provided, only those from
// the user list
$displayGroupIds = (count($displayGroupIds) > 0)
? array_intersect($displayGroupIds, $userDisplayGroupIds)
: $userDisplayGroupIds;

$this->getLog()->debug('Resolved list of display groups ['
. json_encode($displayGroupIds) . '] from provided list ['
. json_encode($originalDisplayGroupIds) . '] and user list ['
. json_encode($userDisplayGroupIds) . ']');

// If we have none, then we do not return any events.
if (count($displayGroupIds) <= 0) {
$this->getState()->template = 'grid';
$this->getState()->recordsTotal = $this->scheduleFactory->countLast();
$this->getState()->setData([]);

return $this->render($request, $response);
}
}

$events = $this->scheduleFactory->query(
$this->gridRenderSort($params),
$this->gridRenderFilter([
Expand All @@ -2202,7 +2232,7 @@ public function grid(Request $request, Response $response)
'geoAware' => $params->getInt('geoAware'),
'recurring' => $params->getInt('recurring'),
'campaignId' => $params->getInt('campaignId'),
'displayGroupIds' => $params->getIntArray('displayGroupIds'),
'displayGroupIds' => $displayGroupIds,
'name' => $params->getString('name'),
'useRegexForName' => $params->getCheckbox('useRegexForName'),
'logicalOperatorName' => $params->getString('logicalOperatorName'),
Expand Down
1 change: 1 addition & 0 deletions lib/Controller/SyncGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public function grid(Request $request, Response $response): Response|\Psr\Http\M
'name' => $parsedQueryParams->getString('name'),
'folderId' => $parsedQueryParams->getInt('folderId'),
'ownerId' => $parsedQueryParams->getInt('ownerId'),
'leadDisplayId' => $parsedQueryParams->getInt('leadDisplayId')
];

$syncGroups = $this->syncGroupFactory->query(
Expand Down
14 changes: 14 additions & 0 deletions lib/Entity/Display.php
Original file line number Diff line number Diff line change
Expand Up @@ -747,12 +747,12 @@

// Check the number of licensed displays
if ($maxDisplays > 0) {
$this->getLog()->debug(sprintf('Testing authorised displays against %d maximum. Currently authorised = %d, authorised = %d.', $maxDisplays, $this->currentlyLicensed, $this->licensed));

Check warning on line 750 in lib/Entity/Display.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 196 characters

if ($this->currentlyLicensed != $this->licensed && $this->licensed == 1) {
$countLicensed = $this->getStore()->select('SELECT COUNT(DisplayID) AS CountLicensed FROM display WHERE licensed = 1', []);

$this->getLog()->debug(sprintf('There are %d authorised displays and we the maximum is %d', $countLicensed[0]['CountLicensed'], $maxDisplays));

Check warning on line 755 in lib/Entity/Display.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 159 characters

if (intval($countLicensed[0]['CountLicensed']) + 1 > $maxDisplays) {
return false;
Expand Down Expand Up @@ -893,8 +893,8 @@
private function add()
{
$this->displayId = $this->getStore()->insert('
INSERT INTO display (display, auditingUntil, defaultlayoutid, license, licensed, lastAccessed, inc_schedule, email_alert, alert_timeout, clientAddress, xmrChannel, xmrPubKey, lastCommandSuccess, macAddress, lastChanged, lastWakeOnLanCommandSent, client_type, client_version, client_code, overrideConfig, newCmsAddress, newCmsKey, commercialLicence, lanIpAddress, syncGroupId)

Check warning on line 896 in lib/Entity/Display.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 387 characters
VALUES (:display, :auditingUntil, :defaultlayoutid, :license, :licensed, :lastAccessed, :inc_schedule, :email_alert, :alert_timeout, :clientAddress, :xmrChannel, :xmrPubKey, :lastCommandSuccess, :macAddress, :lastChanged, :lastWakeOnLanCommandSent, :clientType, :clientVersion, :clientCode, :overrideConfig, :newCmsAddress, :newCmsKey, :commercialLicence, :lanIpAddress, :syncGroupId)

Check warning on line 897 in lib/Entity/Display.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 398 characters
', [
'display' => $this->display,
'auditingUntil' => 0,
Expand Down Expand Up @@ -1389,4 +1389,18 @@

return $this;
}

/**
* Check if this Display is set as Lead Display on any Sync Group
* @return bool
*/
public function isLead(): bool
{
$syncGroups = $this->getStore()->select(
'SELECT syncGroupId FROM `syncgroup` WHERE `syncgroup`.leadDisplayId = :displayId',
['displayId' => $this->displayId]
);

return count($syncGroups) > 0;
}
}
13 changes: 13 additions & 0 deletions lib/Entity/Folder.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
public function validate()
{
if (!v::stringType()->notEmpty()->length(1, 254)->validate($this->text)) {
throw new InvalidArgumentException(__('Folder needs to have a name, between 1 and 254 characters.'), 'folderName');

Check warning on line 155 in lib/Entity/Folder.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 127 characters
}

if (empty($this->parentId)) {
Expand Down Expand Up @@ -206,20 +206,20 @@
{
$parent = $this->folderFactory->getById($this->parentId);

$this->id = $this->getStore()->insert('INSERT INTO `folder` (folderName, parentId, isRoot, permissionsFolderId) VALUES (:folderName, :parentId, :isRoot, :permissionsFolderId)',

Check failure on line 209 in lib/Entity/Folder.php

View workflow job for this annotation

GitHub Actions / phpcs

Opening parenthesis of a multi-line function call must be the last content on the line

Check warning on line 209 in lib/Entity/Folder.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 184 characters
[
'folderName' => $this->text,
'parentId' => $this->parentId,
'isRoot' => 0,
'permissionsFolderId' => ($parent->permissionsFolderId == null) ? $this->parentId : $parent->permissionsFolderId

Check warning on line 214 in lib/Entity/Folder.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 128 characters
]);

Check failure on line 215 in lib/Entity/Folder.php

View workflow job for this annotation

GitHub Actions / phpcs

Multi-line function call not indented correctly; expected 8 spaces but found 12

$this->manageChildren('add');
}

private function edit()
{
$this->getStore()->update('UPDATE `folder` SET folderName = :folderName, parentId = :parentId WHERE folderId = :folderId',

Check warning on line 222 in lib/Entity/Folder.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 130 characters
[
'folderId' => $this->id,
'folderName' => $this->text,
Expand Down Expand Up @@ -275,8 +275,8 @@
/**
* Manages folder permissions
*
* When permissions are added on folder, this starts new ACL from that folder and is cascaded down to all folders under this folder

Check warning on line 278 in lib/Entity/Folder.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 135 characters
* permissionsFolderId is also updated on all relevant objects that are in this folder or under this folder in folder tree structure

Check warning on line 279 in lib/Entity/Folder.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 136 characters
*
* When permissions are removed from a folder, this sets the permissionsFolderId to parent folderId (or parent permissionsFolderId)
* same is cascaded down the folder tree and all relevant objects
Expand Down Expand Up @@ -455,4 +455,17 @@

return $found;
}

/**
* Check if this folder is used as Home Folder for any existing Users
* @return bool
*/
public function isHome(): bool
{
$userIds = $this->getStore()->select('SELECT userId FROM `user` WHERE `user`.homeFolderId = :folderId', [
'folderId' => $this->id
]);

return count($userIds) > 0;
}
}
5 changes: 5 additions & 0 deletions lib/Factory/SyncGroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,11 @@ public function query($sortOrder = null, $filterBy = []): array
$params['folderId'] = $parsedBody->getInt('folderId');
}

if ($parsedBody->getInt('leadDisplayId') !== null) {
$body .= ' AND `syncgroup`.leadDisplayId = :leadDisplayId ';
$params['leadDisplayId'] = $parsedBody->getInt('leadDisplayId');
}

// View Permissions
$this->viewPermissionSql(
'Xibo\Entity\SyncGroup',
Expand Down
7 changes: 7 additions & 0 deletions lib/Helper/XiboUploadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,13 @@ protected function handle_form_data($file, $index)
// Get the Playlist
$playlist = $controller->getPlaylistFactory()->getById($this->options['playlistId']);

if (!$playlist->isEditable()) {
throw new InvalidArgumentException(
__('This Layout is not a Draft, please checkout.'),
'layoutId'
);
}

// Create a Widget and add it to our region
$widget = $controller->getWidgetFactory()->create(
$this->options['userId'],
Expand Down
10 changes: 5 additions & 5 deletions lib/Service/DisplayNotifyService.php
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public function notifyByCampaignId($campaignId)
) campaigns
ON campaigns.campaignId = `schedule`.campaignId
WHERE (
(`schedule`.FromDT < :toDt AND IFNULL(`schedule`.toDt, `schedule`.fromDt) > :fromDt)
(`schedule`.FromDT < :toDt AND IFNULL(`schedule`.toDt, UNIX_TIMESTAMP()) > :fromDt)
OR `schedule`.recurrence_range >= :fromDt
OR (
IFNULL(`schedule`.recurrence_range, 0) = 0 AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\'
Expand Down Expand Up @@ -436,7 +436,7 @@ public function notifyByDataSetId($dataSetId)
AND `widgetoption`.option = \'dataSetId\'
AND `widgetoption`.value = :activeDataSetId
WHERE (
(schedule.FromDT < :toDt AND IFNULL(`schedule`.toDt, `schedule`.fromDt) > :fromDt)
(schedule.FromDT < :toDt AND IFNULL(`schedule`.toDt, UNIX_TIMESTAMP()) > :fromDt)
OR `schedule`.recurrence_range >= :fromDt
OR (
IFNULL(`schedule`.recurrence_range, 0) = 0 AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\'
Expand Down Expand Up @@ -588,7 +588,7 @@ public function notifyByPlaylistId($playlistId)
ON `playlist`.regionId = `region`.regionId
WHERE `playlist`.playlistId = :playlistId
AND (
(schedule.FromDT < :toDt AND IFNULL(`schedule`.toDt, `schedule`.fromDt) > :fromDt)
(schedule.FromDT < :toDt AND IFNULL(`schedule`.toDt, UNIX_TIMESTAMP()) > :fromDt)
OR `schedule`.recurrence_range >= :fromDt
OR (
IFNULL(`schedule`.recurrence_range, 0) = 0 AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\'
Expand Down Expand Up @@ -741,7 +741,7 @@ public function notifyByLayoutCode($code)
) campaigns
ON campaigns.campaignId = `schedule`.campaignId
WHERE (
(`schedule`.FromDT < :toDt AND IFNULL(`schedule`.toDt, `schedule`.fromDt) > :fromDt)
(`schedule`.FromDT < :toDt AND IFNULL(`schedule`.toDt, UNIX_TIMESTAMP()) > :fromDt)
OR `schedule`.recurrence_range >= :fromDt
OR (
IFNULL(`schedule`.recurrence_range, 0) = 0 AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\'
Expand Down Expand Up @@ -769,7 +769,7 @@ public function notifyByLayoutCode($code)
ON lkdisplaydg.DisplayID = display.displayID
WHERE schedule.actionLayoutCode = :code
AND (
(`schedule`.FromDT < :toDt AND IFNULL(`schedule`.toDt, `schedule`.fromDt) > :fromDt)
(`schedule`.FromDT < :toDt AND IFNULL(`schedule`.toDt, UNIX_TIMESTAMP()) > :fromDt)
OR `schedule`.recurrence_range >= :fromDt
OR (
IFNULL(`schedule`.recurrence_range, 0) = 0 AND IFNULL(`schedule`.recurrence_type, \'\') <> \'\'
Expand Down
2 changes: 1 addition & 1 deletion lib/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* description="Xibo CMS API.
Using HTTP formData requests.
All PUT requests require Content-Type:application/x-www-form-urlencoded header.",
* version="3.3",
* version="4.0",
* termsOfService="https://xibosignage.com/legal",
* @SWG\License(
* name="AGPLv3 or later",
Expand Down
8 changes: 5 additions & 3 deletions ui/src/core/xibo-cms.js
Original file line number Diff line number Diff line change
Expand Up @@ -3870,11 +3870,13 @@ function initJsTreeAjax(container, id, isForm, ttl, onReady = null, onSelected =
$('#container-folder-tree').jstree(true).refresh();
}
} else {
toastr.error(translations.folderWithContent);
console.log(data.message);
if (data.message !== undefined) {
toastr.error(data.message)
} else {
toastr.error(translations.folderWithContent);
}
$(container).jstree(true).refresh();
}

}
});
}).bind("changed.jstree", function (e, data) {
Expand Down
3 changes: 3 additions & 0 deletions views/syncgroup-page.twig
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
{% set title %}{% trans "Name" %}{% endset %}
{{ inline.inputNameGrid('name', title) }}

{% set title %}{% trans "Lead Display ID" %}{% endset %}
{{ inline.input("leadDisplayId", title) }}

{{ inline.hidden("folderId") }}
</form>
</div>
Expand Down
Loading