Skip to content

Commit

Permalink
Syncing files from cloud/release/2024.003 to release/2024.003
Browse files Browse the repository at this point in the history
  • Loading branch information
Crousem committed Feb 20, 2024
1 parent 72fd382 commit ff30b89
Show file tree
Hide file tree
Showing 400 changed files with 8,445 additions and 4,092 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
!/plugins/ProfileExtender/
!/plugins/QnA/
!/plugins/Quotes/
!/plugins/Reactions/
!/plugins/recaptcha/
!/plugins/rich-editor/
!/plugins/Redirector/
Expand Down
1 change: 0 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ applications/dashboard/scss/vendors
./library/deprecated/functions.deprecated.php
./plugins/OpenID/class.lightopenid.php
./plugins/Quotes/class.quotes.plugin.php
./plugins/Reactions/ReactionsPlugin.php
./plugins/VanillaInThisDiscussion/class.inthisdiscussionmodule.php
6 changes: 0 additions & 6 deletions addons/themes/theme-dashboard/views/admin.master.twig
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
<div class="panel panel-left">
<div class="panel-nav panel-content-wrapper">
<div class="js-fluid-fixed panel-content">
<a href="/" class="title">
{{ forumLinkLabel }}
<svg class="icon icon-svg icon-16" alt="external-link" viewbox="0 0 17 17">
<use xlink:href="#external-link"></use>
</svg>
</a>
<div id="panel-nav" class="js-panel-nav">
{{ dashboardNav|raw }}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ConversationMessageModel extends ConversationsModel
*/
private static $instance;

private $LastMessageID;

/**
* @var ConversationModel
*/
Expand Down
23 changes: 13 additions & 10 deletions applications/conversations/models/class.conversationmodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/**
* Conversation model.
*
* @copyright 2009-2019 Vanilla Forums Inc.
* @copyright 2009-2024 Higher Logic Inc.
* @license GPL-2.0-only
* @package Conversations
* @since 2.0
Expand Down Expand Up @@ -422,12 +422,13 @@ public static function getMaxRecipients()
/**
* Get all users involved in conversation.
*
* @since 2.0.0
* @access public
*
* @param int $conversationID Unique ID of conversation.
* @param int $limit The number of recipients to grab.
* @return Gdn_DataSet SQL results.
* @throws Exception
* @since 2.0.0
* @access public
*
*/
public function getRecipients($conversationID, $limit = 1000)
{
Expand Down Expand Up @@ -1001,25 +1002,27 @@ public function addUserToConversation($conversationID, $userIDs)
* If we pass $countRecipients then $conversationID isn't needed (set to zero).
*
* @param int $conversationID Unique ID of the conversation.
* @param int $countRecipients Optionally skip needing to query the count by passing it.
* @param int $recipientsCount Optionally skip needing to query the count by passing it.
* @return bool Whether user may add more recipients to conversation.
*/
public function addUserAllowed($conversationID = 0, $countRecipients = 0)
public function addUserAllowed($conversationID = 0, $recipientsCount = 0)
{
// Determine whether recipients can be added
$canAddRecipients = true;
$maxRecipients = self::getMaxRecipients();

// Avoid a query if we already know we can add. MaxRecipients being unset means unlimited.
if ($maxRecipients) {
if (!$countRecipients) {
if (!$recipientsCount) {
// Count current recipients
$conversationModel = new ConversationModel();
$countRecipients = $conversationModel->getRecipients($conversationID);
$recipientsCount = $this->getRecipients($conversationID);
}

if (is_array($recipientsCount)) {
$recipientsCount = count($recipientsCount);
}
// Add 1 because sender counts as a recipient.
$canAddRecipients = count($countRecipients) < $maxRecipients + 1;
$canAddRecipients = $recipientsCount < $maxRecipients + 1;
}

return $canAddRecipients;
Expand Down
4 changes: 4 additions & 0 deletions applications/dashboard/Addon/DashboardContainerRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,9 @@ public function configureContainer(ContainerConfigurationInterface $container):
->setConstructorArgs([new Reference(Gdn_Session::class), new Reference("@smart-id-middleware")]);

$container->rule(Dispatcher::class)->addCall("addMiddleware", [new Reference(SpoofMiddleware::class)]);

$container
->rule(\Vanilla\OpenAPIBuilder::class)
->addCall("addFilter", ["filter" => new Reference(\ReactionsFilterOpenApi::class)]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ public function index()
$this->setData("ReactionTypes", $ReactionTypes);

Gdn_Theme::section("Settings");
include_once $this->fetchViewLocation("settings_functions", "", "plugins/Reactions");
$this->render("reactiontypes", "", "plugins/Reactions");
include_once $this->fetchViewLocation("settings_functions");
$this->render("reactiontypes");
}

/**
Expand Down Expand Up @@ -91,7 +91,7 @@ public function add()
}
}

$this->render("addedit", "", "plugins/Reactions");
$this->render("addedit");
}

/**
Expand All @@ -117,7 +117,7 @@ public function undo($Type, $ID, $Reaction, $UserID)

$this->jsonTarget("!parent", "", "SlideUp");

include_once $this->fetchViewLocation("reaction_functions", "", "plugins/Reactions");
include_once $this->fetchViewLocation("reaction_functions");
$this->render("Blank", "Utility", "Dashboard");
}

Expand All @@ -132,7 +132,7 @@ public function undo($Type, $ID, $Reaction, $UserID)
*/
public function users($type, $id, $reaction, $page = null)
{
if (!c("Plugins.Reactions.ShowUserReactions", ReactionsPlugin::RECORD_REACTIONS_DEFAULT)) {
if (!c("Plugins.Reactions.ShowUserReactions", ReactionModel::RECORD_REACTIONS_DEFAULT)) {
throw permissionException();
}

Expand All @@ -149,7 +149,7 @@ public function users($type, $id, $reaction, $page = null)

[$offset, $limit] = offsetLimit($page, 10);
$this->setData("Users", $reactionModel->getUsers($type, $id, $reaction, $offset, $limit));
$this->render("", "reactions", "plugins/Reactions");
$this->render();
}

/**
Expand Down Expand Up @@ -230,7 +230,7 @@ public function edit($urlCode)
}
}

$this->render("addedit", "", "plugins/Reactions");
$this->render("addedit");
}

/**
Expand Down Expand Up @@ -317,7 +317,7 @@ public function logged($type, $iD)
$this->setData("RecordType", $type);
$this->setData("RecordID", $iD);

$this->render("log", "reactions", "plugins/Reactions");
$this->render("log");
}

/**
Expand Down Expand Up @@ -370,7 +370,7 @@ public function toggle($UrlCode, $Active)

if ($this->deliveryType() != DELIVERY_TYPE_DATA) {
// Send back the new button.
include_once $this->fetchViewLocation("settings_functions", "", "plugins/Reactions");
include_once $this->fetchViewLocation("settings_functions");
$this->deliveryMethod(DELIVERY_METHOD_JSON);
$this->jsonTarget(
"#ReactionType_{$ReactionType["UrlCode"]} #reactions-toggle",
Expand Down Expand Up @@ -400,7 +400,7 @@ public function settings()
"LabelCode" => "Show Who Reacted to Posts",
"Control" => "RadioList",
"Items" => ["popup" => "In a popup", "avatars" => "As avatars", "off" => "Don't show"],
"Default" => ReactionsPlugin::RECORD_REACTIONS_DEFAULT,
"Default" => ReactionModel::RECORD_REACTIONS_DEFAULT,
],
"Plugins.Reactions.BestOfStyle" => [
"LabelCode" => "Best of Style",
Expand Down
167 changes: 167 additions & 0 deletions applications/dashboard/controllers/api/AttachmentsApiController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
<?php
/**
* @author Richard Flynn <rflynn@higherlogic.com>
* @copyright 2009-2024 Vanilla Forums Inc.
* @license GPL-2.0-only
*/

namespace Vanilla\Dashboard\Controllers\Api;

use AbstractApiController;
use AttachmentModel;
use Vanilla\Dashboard\Models\ExternalIssueService;
use Garden\Utils\ArrayUtils;
use Garden\Web\Data;
use Garden\Web\Exception\NotFoundException;
use Vanilla\Dashboard\Models\ExternalIssueProviderInterface;

/**
* API v2 endpoints for attachments.
*/
class AttachmentsApiController extends AbstractApiController
{
private AttachmentModel $attachmentModel;

private ExternalIssueService $externalIssueService;

/**
* D.I.
*
* @param AttachmentModel $attachmentModel
* @param ExternalIssueService $externalIssueService
*/
public function __construct(AttachmentModel $attachmentModel, ExternalIssueService $externalIssueService)
{
$this->attachmentModel = $attachmentModel;
$this->externalIssueService = $externalIssueService;
}

/**
* Post a new attachment.
*
* @param array $body
* @return Data
* @throws \Garden\Web\Exception\NotFoundException
*/
public function post(array $body): Data
{
$this->permission("staff.allow");

$in = $this->attachmentModel->getAttachmentPostSchema();
$in->validate($body);

$recordType = $body["recordType"];
$recordID = $body["recordID"];

$provider = $this->getProvider($body["source"]);
if (!$provider) {
throw new NotFoundException("No provider was found for this attachment source.");
}

$metadata = $this->extractMetadata($body);

$issueSchema = $provider->issuePostSchema();
$issueSchema->validate($metadata);

$attachment = $provider->makeNewIssue($recordType, $recordID, $body);

$attachment = $this->normalizeSingleAttachment($attachment);

$out = $provider->fullIssueSchema();
$out->validate($attachment, true);

return new Data($attachment);
}

/**
* Get attachments for a record.
*
* @param array $query
* @return Data
*/
public function index(array $query = []): \Garden\Web\Data
{
$this->permission("staff.allow");

$in = $this->schema([
"recordType:s" => ["enum" => ["discussion", "comment", "user"]],
"recordID:i",
]);

$in->validate($query);

$foreignID = $this->attachmentModel->createForeignID($query["recordType"], $query["recordID"]);

$attachments = $this->attachmentModel->getWhere(["ForeignID" => $foreignID])->resultArray();
$this->normalizeAttachments($attachments);

$out = $this->schema([":a" => $this->attachmentModel->getAttachmentSchema()], "out");
$out->validate($attachments);

return new Data($attachments);
}

/**
* Get the provider for a source.
*
* @param string $sourceName
* @return ExternalIssueProviderInterface|null
*/
private function getProvider(string $sourceName): ?ExternalIssueProviderInterface
{
foreach ($this->externalIssueService->getAllProviders() as $provider) {
if ($provider->getSourceName() == $sourceName) {
return $provider;
}
}
return null;
}

/**
* Extract metadata from an array of attachment data.
*
* @param array $data
* @return array
*/
public function extractMetadata(array $data): array
{
$metadata = [];
foreach ($data["metadata"] as $item) {
$metadata[$item["labelCode"]] = $item["value"];
}
return $metadata;
}

/**
* Normalize a single attachment for output.
*
* @param array $attachment
* @return array
*/
private function normalizeSingleAttachment(array $attachment): array
{
$attachmentArray = [$attachment];
$this->attachmentModel->normalizeAttachments($attachmentArray);
$normalizedAttachment = $attachmentArray[0];
$normalizedAttachment = ArrayUtils::camelCase($normalizedAttachment);
$schemaArray = $this->attachmentModel->getAttachmentSchema()->getSchemaArray();
$filteredAttachment = array_intersect_key($normalizedAttachment, $schemaArray["properties"]);
return $filteredAttachment;
}

/**
* Normalize an array of attachments for output.
*
* @param array $attachments
* @return void
*/
private function normalizeAttachments(array &$attachments): void
{
$this->attachmentModel->normalizeAttachments($attachments);
$schemaArray = $this->attachmentModel->getAttachmentSchema()->getSchemaArray();
$attachments = ArrayUtils::camelCase($attachments);
foreach ($attachments as &$attachment) {
$attachment = array_intersect_key($attachment, $schemaArray["properties"]);
}
}
}

0 comments on commit ff30b89

Please sign in to comment.