Skip to content

Commit

Permalink
feat: SMTP 1/2 - Preparation
Browse files Browse the repository at this point in the history
Create an SMTP Settings option under Aspen Administration -> Email.
Included in the patch should be all the database + permissions changes.
  • Loading branch information
ammopt committed Jun 12, 2024
1 parent c128a7f commit 3d9a5a4
Show file tree
Hide file tree
Showing 6 changed files with 210 additions and 0 deletions.
81 changes: 81 additions & 0 deletions code/web/services/Admin/SMTPSettings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

require_once ROOT_DIR . '/Action.php';
require_once ROOT_DIR . '/services/Admin/ObjectEditor.php';
require_once ROOT_DIR . '/sys/Email/SMTPSetting.php';

class Admin_SMTPSettings extends ObjectEditor {
function getObjectType(): string {
return 'SMTPSetting';
}

function getToolName(): string {
return 'SMTPSettings';
}

function getModule(): string {
return 'Admin';
}

function getPageTitle(): string {
return 'SMTP Settings';
}

function getAllObjects($page, $recordsPerPage): array {
$object = new SMTPSetting();
$object->limit(($page - 1) * $recordsPerPage, $recordsPerPage);
$this->applyFilters($object);
$object->find();
$objectList = [];
while ($object->fetch()) {
$objectList[$object->id] = clone $object;
}
return $objectList;
}

function getDefaultSort(): string {
return 'id asc';
}

function canSort(): bool {
return false;
}

function getObjectStructure($context = ''): array {
return SMTPSetting::getObjectStructure($context);
}

function getPrimaryKeyColumn(): string {
return 'id';
}

function getIdKeyColumn(): string {
return 'id';
}

function getAdditionalObjectActions($existingObject): array {
return [];
}

function getInstructions(): string {
return '';
}

function getBreadcrumbs(): array {
$breadcrumbs = [];
$breadcrumbs[] = new Breadcrumb('/Admin/Home', 'Administration Home');
$breadcrumbs[] = new Breadcrumb('/Admin/Home#system_admin', 'System Administration');
$breadcrumbs[] = new Breadcrumb('/Admin/SMTPSettings', 'SMTP Settings');
return $breadcrumbs;
}

function getActiveAdminSection(): string {
return 'email';
}

function canView(): bool {
return UserAccount::userHasPermission('Administer SMTP');
}


}
1 change: 1 addition & 0 deletions code/web/sys/Account/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3503,6 +3503,7 @@ public function getAdminActions() {
$sections['email']->addAction(new AdminAction('Email Templates', 'Templates for various emails sent from Aspen Discovery.', '/Admin/EmailTemplates'), ['Administer All Email Templates', 'Administer Library Email Templates']);
$sections['email']->addAction(new AdminAction('Amazon SES Settings', 'Settings to allow Aspen Discovery to send emails via Amazon SES.', '/Admin/AmazonSesSettings'), 'Administer Amazon SES');
$sections['email']->addAction(new AdminAction('Send Grid Settings', 'Settings to allow Aspen Discovery to send emails via SendGrid.', '/Admin/SendGridSettings'), 'Administer SendGrid');
$sections['email']->addAction(new AdminAction('SMTP Settings', 'Settings to allow Aspen Discovery to send emails via an SMTP server.', '/Admin/SMTPSettings'), 'Administer SMTP');

$sections['ils_integration'] = new AdminSection('ILS Integration');
$indexingProfileAction = new AdminAction('Indexing Profiles', 'Define how records from the ILS are loaded into Aspen Discovery.', '/ILS/IndexingProfiles');
Expand Down
1 change: 1 addition & 0 deletions code/web/sys/DBMaintenance/user_updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,7 @@ function getUserUpdates() {
,('System Administration', 'Administer Permissions', '', 15, 'Allows configuration of the roles within Aspen Discovery and what each role can do. <i>Give to trusted users, this has security implications.</i>')
,('System Administration', 'Run Database Maintenance', '', 20, 'Controls if the user can run database maintenance or not.')
,('System Administration', 'Administer SendGrid', '', 30, 'Controls if the user can change SendGrid settings. <em>This has potential security and cost implications.</em>')
,('System Administration', 'Administer SMTP', '', 30, 'Controls if the user can change SMTP settings.')
,('System Administration', 'Administer System Variables','', 40, 'Controls if the user can change system variables.')
,('Reporting', 'View System Reports', '', 0, 'Controls if the user can view System Reports that show how Aspen Discovery performs and how background tasks are operating. Includes Indexing Logs and Dashboards.')
,('Reporting', 'View Indexing Logs', '', 10, 'Controls if the user can view Indexing Logs for the ILS and eContent.')
Expand Down
28 changes: 28 additions & 0 deletions code/web/sys/DBMaintenance/version_updates/24.06.00.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,34 @@ function getUpdates24_06_00(): array {
],
], //full_text_limiter

//pedro - PTFS-Europe
'smtp_settings' => [
'title' => 'SMTP Settings',
'description' => 'Allow configuration of SMTP to send mail from',
'sql' => [
"CREATE TABLE smtp_settings (
id int(11) NOT NULL AUTO_INCREMENT,
name varchar(80) NOT NULL,
host varchar(80) NOT NULL DEFAULT 'localhost',
port int(11) NOT NULL DEFAULT 25,
ssl_mode enum('disabled','ssl','tls') NOT NULL,
from_address varchar(80) DEFAULT NULL,
user_name varchar(80) DEFAULT NULL,
password varchar(80) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB",
],
], //smtp_settings

'permissions_create_administer_smtp' => [
'title' => 'Create Administer SMTP Permission',
'description' => 'Controls if the user can change SMTP settings',
'sql' => [
"INSERT INTO permissions (sectionName, name, requiredModule, weight, description) VALUES ('Primary Configuration', 'Administer SMTP', '', 30, 'Controls if the user can change SMTP settings.')",
"INSERT INTO role_permissions(roleId, permissionId) VALUES ((SELECT roleId from roles where name='opacAdmin'), (SELECT id from permissions where name='Administer SMTP'))",
],
], //permissions_create_administer_smtp

//other


Expand Down
87 changes: 87 additions & 0 deletions code/web/sys/Email/SMTPSetting.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php


class SMTPSetting extends DataObject {
public $__table = 'smtp_settings';
public $id;
public $name;
public $host;
public $port;
public $ssl_mode;
public $from_address;
public $user_name;
public $password;

public static function getObjectStructure($context = ''): array {
return [
'id' => [
'property' => 'id',
'type' => 'label',
'label' => 'Id',
'description' => 'The unique id',
],
'name' => [
'property' => 'name',
'type' => 'text',
'label' => 'Server name',
'description' => 'The name of the server',
'default' => 'heyo',
'required' => true,
],
'host' => [
'property' => 'host',
'type' => 'text',
'label' => 'Host',
'description' => 'The SMTP host',
'default' => 'localhost',
'required' => true,
],
'port' => [
'property' => 'port',
'type' => 'integer',
'label' => 'Port',
'description' => 'The utilized port',
'default' => '25',
'required' => true,
],
'ssl_mode' => [
'property' => 'ssl_mode',
'type' => 'enum',
'values' => [
'disabled' => 'Disabled',
'ssl' => 'SSL',
'tls' => 'StartTLS',
],
'label' => 'SSL mode',
'description' => 'SSL mode',
],
'from_address' => [
'property' => 'from_address',
'type' => 'text',
'label' => 'From',
'description' => 'The \'From:\' e-mail address',
'default' => '',
'required' => true,
],
'user_name' => [
'property' => 'user_name',
'type' => 'text',
'label' => 'Username',
'description' => 'The username',
'default' => '',
'required' => true,
],
'password' => [
'property' => 'password',
'type' => 'storedPassword',
'label' => 'Password',
'description' => 'The password',
'default' => '',
],
];
}

function getActiveAdminSection(): string {
return 'system_admin';
}
}
12 changes: 12 additions & 0 deletions install/aspen.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4681,6 +4681,18 @@ CREATE TABLE `slow_page` (
PRIMARY KEY (`id`),
KEY `year` (`year`,`month`,`module`,`action`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
DROP TABLE IF EXISTS smtp_settings;
CREATE TABLE `smtp_settings` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`host` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL DEFAULT 'localhost',
`port` int(11) NOT NULL DEFAULT 25,
`ssl_mode` enum('disabled','ssl','tls') NOT NULL,
`from_address` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
`user_name` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
`password` varchar(80) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
DROP TABLE IF EXISTS springshare_libcal_events;
CREATE TABLE `springshare_libcal_events` (
`id` int(11) NOT NULL AUTO_INCREMENT,
Expand Down

0 comments on commit 3d9a5a4

Please sign in to comment.