Skip to content

Commit

Permalink
pkp#10571 WIP: Add checks to limit email template access by usergroups
Browse files Browse the repository at this point in the history
  • Loading branch information
taslangraham committed Jan 14, 2025
1 parent 6207ac7 commit 4d0c0e3
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 0 deletions.
1 change: 1 addition & 0 deletions classes/decision/steps/Email.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ protected function getEmailTemplates(): array
});
}


return Repo::emailTemplate()->getSchemaMap()->mapMany($emailTemplates)->toArray();
}

Expand Down
2 changes: 2 additions & 0 deletions classes/emailTemplate/maps/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public function map(EmailTemplate $item): array
* Summarize an email template
*
* Includes properties with the apiSummary flag in the email template schema.
*
* @param null|mixed $mailableClass
*/
public function summarize(EmailTemplate $item, ?string $mailableClass = null): array
{
Expand Down
16 changes: 16 additions & 0 deletions classes/mail/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use PKP\context\Context;
use PKP\emailTemplate\EmailTemplate;
use PKP\mail\mailables\DecisionNotifyOtherAuthors;
use PKP\mail\mailables\EditReviewNotify;
use PKP\mail\mailables\ReviewCompleteNotifyEditors;
Expand Down Expand Up @@ -278,4 +279,19 @@ public function map(): Collection
mailables\ValidateEmailSite::class,
]);
}

/**
* Gets the mailable for a given email template
*
* @param EmailTemplate $template
*
* Note: This does not discover/find mailbles defined within plugins
*
* @return string|null - Fully Qualified Class Name of a mailable
*/
public function getMailableByEmailTemplate(EmailTemplate $template): ?string
{
$emailKey = $template->getData('alternateTo') ?? $template->getData('key');
return $this->map()->first(fn ($class) => $class::getEmailTemplateKey() === $emailKey);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace PKP\migration\upgrade\v3_5_0;

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
use PKP\migration\Migration;

class I10403_EmailTemplateRoleAccess extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{

Schema::create('email_template_role_access', function (Blueprint $table) {
$table->bigInteger('email_template_role_access_id')->autoIncrement();
$table->string('email_key', 255);
$table->bigInteger('context_id');
$table->bigInteger('user_group_id');

$table->foreign('context_id')->references('journal_id')->on('journals')->onDelete('cascade');
$table->foreign('user_group_id')->references('user_group_id')->on('user_groups')->onDelete('cascade');
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::drop('email_template_role_access');
}
}
1 change: 1 addition & 0 deletions controllers/grid/queries/form/QueryForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ public function fetch($request, $template = null, $display = false, $actionArgs
}
}


$templateMgr->assign('templates', $templateKeySubjectPairs);

// Get currently selected participants in the query
Expand Down

0 comments on commit 4d0c0e3

Please sign in to comment.