From 10f9beaf97f868b8647fa9b160f40ccaebc0f34b Mon Sep 17 00:00:00 2001 From: Taslan Graham Date: Tue, 12 Nov 2024 10:46:06 -0500 Subject: [PATCH] pkp/pkp-lib#10571 Update emailTemplate schema --- .../I10403_EmailTemplateUserGroupAccess.php | 75 ------------------- schemas/emailTemplate.json | 10 ++- 2 files changed, 9 insertions(+), 76 deletions(-) delete mode 100644 classes/migration/upgrade/v3_5_0/I10403_EmailTemplateUserGroupAccess.php diff --git a/classes/migration/upgrade/v3_5_0/I10403_EmailTemplateUserGroupAccess.php b/classes/migration/upgrade/v3_5_0/I10403_EmailTemplateUserGroupAccess.php deleted file mode 100644 index fb4b75a2e55..00000000000 --- a/classes/migration/upgrade/v3_5_0/I10403_EmailTemplateUserGroupAccess.php +++ /dev/null @@ -1,75 +0,0 @@ -bigInteger('email_template_user_group_access_id')->autoIncrement(); - $table->string('email_key', 255); - $table->bigInteger('context_id'); - $table->bigInteger('user_group_id')->nullable(); - - $table->foreign('context_id')->references($contextDao->primaryKeyColumn)->on($contextDao->tableName)->onDelete('cascade'); - $table->foreign('user_group_id')->references('user_group_id')->on('user_groups')->onDelete('cascade'); - }); - - $contextIds = array_map(fn (Context $context) => $context->getId(), $contextDao->getAll()->toArray()); - - if (!empty($contextIds)) { - DB::table('email_template_user_group_access')->select('*')->get(); - - $defaultTemplateKeys = DB::table('email_templates_default_data')->select()->pluck('email_key')->all(); - $alternateTemplates = DB::table('email_templates')->select(['context_id', 'email_key'])->get()->toArray(); - - $data = []; - - // Record any existing default templates as unrestricted for existing Contexts - foreach ($defaultTemplateKeys as $defaultTemplateKey) { - foreach ($contextIds as $contextId) { - $data[] = [ - 'email_key' => $defaultTemplateKey, - 'context_id' => $contextId, - 'user_group_id' => null - ]; - } - } - - // For any existing alternate template, register it as unrestricted within its assigned context - foreach ($alternateTemplates as $template) { - foreach ($contextIds as $contextId) { - if ($contextId === $template->context_id) { - $data[] = [ - 'email_key' => $template->email_key, - 'context_id' => $contextId, - 'user_group_id' => null - ]; - } - } - } - - EmailTemplateAccessGroup::insert($data); - } - } - - /** - * Reverse the migrations. - */ - public function down(): void - { - Schema::drop('email_template_user_group_access'); - } -} diff --git a/schemas/emailTemplate.json b/schemas/emailTemplate.json index 017be1187ba..9681ab37fdd 100644 --- a/schemas/emailTemplate.json +++ b/schemas/emailTemplate.json @@ -71,8 +71,16 @@ }, "isUnrestricted": { "type": "boolean", - "description": "Boolean indicating if an email template is available to all user groups within the roles associated with the template's mailable", + "description": "Boolean indicating if an email template is available to all user groups within the roles associated with the template's mailable.", "apiSummary": true + }, + "assignedUserGroupIds": { + "type": "array", + "description": "IDs of the user groups that currently has access to this email template.", + "apiSummary": true, + "items": { + "type": "integer" + } } } }