Skip to content

Commit

Permalink
[WIP] Add initial synchronisation with Mailman
Browse files Browse the repository at this point in the history
This allows syncronisation of mailing list ids from Mailman and
they can then be added to a mailing list.

At this point there is no actual synchronisation of memberships.
  • Loading branch information
tomudding committed May 25, 2024
1 parent 55f1ba2 commit abb7480
Show file tree
Hide file tree
Showing 38 changed files with 1,146 additions and 150 deletions.
5 changes: 5 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ MAIL_TO_SUBSCRIPTION_NAME='Secretary of GEWIS'
[email protected]
MAIL_FROM_SECRETARY_NAME='Secretary of GEWIS'

MAILMAN_API_ENDPOINT=http://mailmanc:8001/3.1/
MAILMAN_API_VERSION='3.1'
MAILMAN_API_USERNAME=restadmin
MAILMAN_API_PASSWORD=restpass

# LDAP settings (fill in to enable LDAP)
LDAP_SERVERS=ldaps.gewis.nl
LDAP_STARTTLS=true
Expand Down
2 changes: 1 addition & 1 deletion .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion .idea/php.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"require": {
"php": "^8.3.0",
"ext-intl": "*",
"ext-memcached": "^3.2",
"ext-pdo_pgsql": "*",
"ext-pgsql": "*",
"ext-zend-opcache": "*",
Expand Down Expand Up @@ -53,7 +54,9 @@
"doctrine/doctrine-laminas-hydrator": "^3.4.0",
"monolog/monolog": "^1.27.1",
"cweagans/composer-patches": "^1.7.3",
"stripe/stripe-php": "^10.21"
"stripe/stripe-php": "^10.21",
"laminas/laminas-cache": "^3.12.1",
"laminas/laminas-cache-storage-adapter-memcached": "^2.5.0"
},
"require-dev": {
"laminas/laminas-component-installer": "^3.4.0",
Expand Down
73 changes: 72 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions config/autoload/local.development.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ return [
],
],

/**
* Mailman REST API configuration.
*/
'mailman_api' => [
'endpoint' => getenv('MAILMAN_API_ENDPOINT'),
'version' => getenv('MAILMAN_API_VERSION'),
'username' => getenv('MAILMAN_API_USERNAME'),
'password' => getenv('MAILMAN_API_PASSWORD'),
],

/**
* LDAP settings for login to database frontend
*/
Expand Down
10 changes: 10 additions & 0 deletions config/autoload/local.production.php.dist
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ return [
],
],

/**
* Mailman REST API configuration.
*/
'mailman_api' => [
'endpoint' => getenv('MAILMAN_API_ENDPOINT'),
'version' => getenv('MAILMAN_API_VERSION'),
'username' => getenv('MAILMAN_API_USERNAME'),
'password' => getenv('MAILMAN_API_PASSWORD'),
],

/**
* LDAP settings for login to database frontend
*/
Expand Down
1 change: 1 addition & 0 deletions config/modules.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
'DoctrineORMModule',
'Laminas\Cache\Storage\Adapter\Filesystem',
'Laminas\Cache\Storage\Adapter\Memory',
'Laminas\Cache\Storage\Adapter\Memcached',
'Application',
'Database',
'Checker',
Expand Down
4 changes: 2 additions & 2 deletions docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ services:
mailman-core:
image: maxking/mailman-core:0.4
container_name: mailman-core
hostname: mailman-core
hostname: mailmanc
volumes:
- ./mailman/core:/opt/mailman/
depends_on:
Expand All @@ -49,7 +49,7 @@ services:
mailman-web:
image: maxking/mailman-web:0.4
container_name: mailman-web
hostname: mailman-web
hostname: mailmanw
depends_on:
- postgresql
volumes:
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,20 @@ services:
# - STRIPE_CANCEL_URL=
# - STRIPE_SUCCESS_URL=
depends_on:
- memcached
- postfix
volumes:
- gewisdb_data:/code/data:rw
- gewisdb_public:/code/public:rw
networks:
- gewisdb_network
restart: unless-stopped
memcached:
image: memcached:alpine
entrypoint: [ 'memcached', '-m 256' ]
networks:
- gewisdb_network
restart: unless-stopped
postfix:
image: juanluisbaptiste/postfix
env_file:
Expand Down
3 changes: 3 additions & 0 deletions docker/web/development/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ RUN apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
curl-dev \
icu-dev \
libmemcached-dev \
libpq-dev \
libzip-dev \
linux-headers \
Expand All @@ -41,6 +42,8 @@ RUN apk add --no-cache --virtual .build-deps \
pdo_pgsql \
pdo_sqlite \
zip \
&& pecl install memcached \
&& docker-php-ext-enable memcached \
&& pecl install xdebug \
&& docker-php-ext-enable xdebug \
&& rm -r /tmp/pear \
Expand Down
4 changes: 4 additions & 0 deletions docker/web/production/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ WORKDIR /code
RUN apk add --no-cache --virtual .build-deps \
curl-dev \
icu-dev \
libmemcached-dev \
libpq-dev \
libzip-dev \
openldap-dev \
Expand All @@ -34,6 +35,9 @@ RUN apk add --no-cache --virtual .build-deps \
pgsql \
pdo_pgsql \
zip \
&& pecl install memcached \
&& docker-php-ext-enable memcached \
&& rm -r /tmp/pear \
&& runtimeDeps="$( \
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
| tr ',' '\n' \
Expand Down
23 changes: 21 additions & 2 deletions module/Application/src/Model/ConfigItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ enumType: ConfigNamespaces::class,
)]
protected ?DateTime $valueDate = null;

/**
* If the item is a boolean, its value.
*/
#[Column(
type: 'boolean',
nullable: true,
)]
protected ?bool $valueBool = null;

#[PrePersist]
#[PreUpdate]
public function assertValid(): void
Expand All @@ -102,20 +111,26 @@ public function setKey(
/**
* Set the value of the configuration item.
*/
public function setValue(string|DateTime $value): void
public function setValue(bool|string|DateTime $value): void
{
if ($value instanceof DateTime) {
$this->valueString = null;
$this->valueDate = $value;
$this->valueBool = null;
} elseif (is_string($value)) {
$this->valueString = $value;
$this->valueDate = null;
$this->valueBool = null;
} elseif (is_bool($value)) {

Check failure on line 124 in module/Application/src/Model/ConfigItem.php

View workflow job for this annotation

GitHub Actions / php-codesniffer / PHP_CodeSniffer (8.3)

Function is_bool() should not be referenced via a fallback global name, but via a use statement.
$this->valueString = null;
$this->valueDate = null;
$this->valueBool = $value;
} else {
throw new TypeError();
}
}

public function getValue(): string|DateTime|null
public function getValue(): bool|string|DateTime|null
{
if (null !== $this->valueDate) {
return $this->valueDate;
Expand All @@ -125,6 +140,10 @@ public function getValue(): string|DateTime|null
return $this->valueString;
}

if (null !== $this->valueBool) {
return $this->valueBool;
}

return null;
}
}
3 changes: 2 additions & 1 deletion module/Application/src/Model/Enums/ConfigNamespaces.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

/**
* The different namespaces in which configuration items can be created.
* As a rule of thumb, a namespace should be restricted to one service or a welldefined set of a few services.
* As a rule of thumb, a namespace should be restricted to one service or a well-defined set of a few services.
*
* Ideally these namespaces are defined inside the respective modules, but defining them as an enum allows for
* verification in IDEs.
Expand All @@ -15,4 +15,5 @@ enum ConfigNamespaces: string
{
/* Database module */
case DatabaseApi = 'database_api';
case DatabaseMailman = 'database_mailman';
}
9 changes: 7 additions & 2 deletions module/Application/src/Service/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,15 @@ public function __construct(private readonly ConfigItemMapper $configItemMapper)
{
}

/**
* @template T of bool|string|DateTime|null

Check failure on line 19 in module/Application/src/Service/Config.php

View workflow job for this annotation

GitHub Actions / php-codesniffer / PHP_CodeSniffer (8.3)

Incorrect annotations group.
* @psalm-param T $default
* @psalm-return (T is null ? bool|string|DateTime|null : T|null)

Check failure on line 21 in module/Application/src/Service/Config.php

View workflow job for this annotation

GitHub Actions / Psalm

MismatchingDocblockReturnType

module/Application/src/Service/Config.php:21:22: MismatchingDocblockReturnType: Docblock has incorrect return type '(T is null ? DateTime|bool|null|string : (T:fn-application\service\config::getconfig as DateTime|bool|null|string)|null)', should be 'DateTime|null|string' (see https://psalm.dev/142)
*/
public function getConfig(
ConfigNamespaces $namespace,
string $key,
string|DateTime|null $default = null,
bool|string|DateTime|null $default = null,
): string|DateTime|null {
$configItem = $this->getConfigItemMapper()->findByKey($namespace, $key);

Expand All @@ -32,7 +37,7 @@ public function getConfig(
public function setConfig(
ConfigNamespaces $namespace,
string $key,
string|DateTime $value,
bool|string|DateTime $value,
): void {
$configItem = $this->getConfigItemMapper()->findByKey($namespace, $key);

Expand Down
Loading

0 comments on commit abb7480

Please sign in to comment.