Skip to content

Commit abb7480

Browse files
committed
[WIP] Add initial synchronisation with Mailman
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.
1 parent 55f1ba2 commit abb7480

38 files changed

+1146
-150
lines changed

.env.dist

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ MAIL_TO_SUBSCRIPTION_NAME='Secretary of GEWIS'
5555
5656
MAIL_FROM_SECRETARY_NAME='Secretary of GEWIS'
5757

58+
MAILMAN_API_ENDPOINT=http://mailmanc:8001/3.1/
59+
MAILMAN_API_VERSION='3.1'
60+
MAILMAN_API_USERNAME=restadmin
61+
MAILMAN_API_PASSWORD=restpass
62+
5863
# LDAP settings (fill in to enable LDAP)
5964
LDAP_SERVERS=ldaps.gewis.nl
6065
LDAP_STARTTLS=true

.idea/inspectionProfiles/Project_Default.xml

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

+2-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"require": {
1313
"php": "^8.3.0",
1414
"ext-intl": "*",
15+
"ext-memcached": "^3.2",
1516
"ext-pdo_pgsql": "*",
1617
"ext-pgsql": "*",
1718
"ext-zend-opcache": "*",
@@ -53,7 +54,9 @@
5354
"doctrine/doctrine-laminas-hydrator": "^3.4.0",
5455
"monolog/monolog": "^1.27.1",
5556
"cweagans/composer-patches": "^1.7.3",
56-
"stripe/stripe-php": "^10.21"
57+
"stripe/stripe-php": "^10.21",
58+
"laminas/laminas-cache": "^3.12.1",
59+
"laminas/laminas-cache-storage-adapter-memcached": "^2.5.0"
5760
},
5861
"require-dev": {
5962
"laminas/laminas-component-installer": "^3.4.0",

composer.lock

+72-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/autoload/local.development.php.dist

+10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ return [
6868
],
6969
],
7070

71+
/**
72+
* Mailman REST API configuration.
73+
*/
74+
'mailman_api' => [
75+
'endpoint' => getenv('MAILMAN_API_ENDPOINT'),
76+
'version' => getenv('MAILMAN_API_VERSION'),
77+
'username' => getenv('MAILMAN_API_USERNAME'),
78+
'password' => getenv('MAILMAN_API_PASSWORD'),
79+
],
80+
7181
/**
7282
* LDAP settings for login to database frontend
7383
*/

config/autoload/local.production.php.dist

+10
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,16 @@ return [
6868
],
6969
],
7070

71+
/**
72+
* Mailman REST API configuration.
73+
*/
74+
'mailman_api' => [
75+
'endpoint' => getenv('MAILMAN_API_ENDPOINT'),
76+
'version' => getenv('MAILMAN_API_VERSION'),
77+
'username' => getenv('MAILMAN_API_USERNAME'),
78+
'password' => getenv('MAILMAN_API_PASSWORD'),
79+
],
80+
7181
/**
7282
* LDAP settings for login to database frontend
7383
*/

config/modules.config.php

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
'DoctrineORMModule',
2727
'Laminas\Cache\Storage\Adapter\Filesystem',
2828
'Laminas\Cache\Storage\Adapter\Memory',
29+
'Laminas\Cache\Storage\Adapter\Memcached',
2930
'Application',
3031
'Database',
3132
'Checker',

docker-compose.override.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ services:
3232
mailman-core:
3333
image: maxking/mailman-core:0.4
3434
container_name: mailman-core
35-
hostname: mailman-core
35+
hostname: mailmanc
3636
volumes:
3737
- ./mailman/core:/opt/mailman/
3838
depends_on:
@@ -49,7 +49,7 @@ services:
4949
mailman-web:
5050
image: maxking/mailman-web:0.4
5151
container_name: mailman-web
52-
hostname: mailman-web
52+
hostname: mailmanw
5353
depends_on:
5454
- postgresql
5555
volumes:

docker-compose.yml

+7
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,20 @@ services:
5353
# - STRIPE_CANCEL_URL=
5454
# - STRIPE_SUCCESS_URL=
5555
depends_on:
56+
- memcached
5657
- postfix
5758
volumes:
5859
- gewisdb_data:/code/data:rw
5960
- gewisdb_public:/code/public:rw
6061
networks:
6162
- gewisdb_network
6263
restart: unless-stopped
64+
memcached:
65+
image: memcached:alpine
66+
entrypoint: [ 'memcached', '-m 256' ]
67+
networks:
68+
- gewisdb_network
69+
restart: unless-stopped
6370
postfix:
6471
image: juanluisbaptiste/postfix
6572
env_file:

docker/web/development/Dockerfile

+3
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ RUN apk add --no-cache --virtual .build-deps \
1818
$PHPIZE_DEPS \
1919
curl-dev \
2020
icu-dev \
21+
libmemcached-dev \
2122
libpq-dev \
2223
libzip-dev \
2324
linux-headers \
@@ -41,6 +42,8 @@ RUN apk add --no-cache --virtual .build-deps \
4142
pdo_pgsql \
4243
pdo_sqlite \
4344
zip \
45+
&& pecl install memcached \
46+
&& docker-php-ext-enable memcached \
4447
&& pecl install xdebug \
4548
&& docker-php-ext-enable xdebug \
4649
&& rm -r /tmp/pear \

docker/web/production/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ WORKDIR /code
1717
RUN apk add --no-cache --virtual .build-deps \
1818
curl-dev \
1919
icu-dev \
20+
libmemcached-dev \
2021
libpq-dev \
2122
libzip-dev \
2223
openldap-dev \
@@ -34,6 +35,9 @@ RUN apk add --no-cache --virtual .build-deps \
3435
pgsql \
3536
pdo_pgsql \
3637
zip \
38+
&& pecl install memcached \
39+
&& docker-php-ext-enable memcached \
40+
&& rm -r /tmp/pear \
3741
&& runtimeDeps="$( \
3842
scanelf --needed --nobanner --format '%n#p' --recursive /usr/local/lib/php/extensions \
3943
| tr ',' '\n' \

module/Application/src/Model/ConfigItem.php

+21-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,15 @@ enumType: ConfigNamespaces::class,
7777
)]
7878
protected ?DateTime $valueDate = null;
7979

80+
/**
81+
* If the item is a boolean, its value.
82+
*/
83+
#[Column(
84+
type: 'boolean',
85+
nullable: true,
86+
)]
87+
protected ?bool $valueBool = null;
88+
8089
#[PrePersist]
8190
#[PreUpdate]
8291
public function assertValid(): void
@@ -102,20 +111,26 @@ public function setKey(
102111
/**
103112
* Set the value of the configuration item.
104113
*/
105-
public function setValue(string|DateTime $value): void
114+
public function setValue(bool|string|DateTime $value): void
106115
{
107116
if ($value instanceof DateTime) {
108117
$this->valueString = null;
109118
$this->valueDate = $value;
119+
$this->valueBool = null;
110120
} elseif (is_string($value)) {
111121
$this->valueString = $value;
112122
$this->valueDate = null;
123+
$this->valueBool = null;
124+
} elseif (is_bool($value)) {
125+
$this->valueString = null;
126+
$this->valueDate = null;
127+
$this->valueBool = $value;
113128
} else {
114129
throw new TypeError();
115130
}
116131
}
117132

118-
public function getValue(): string|DateTime|null
133+
public function getValue(): bool|string|DateTime|null
119134
{
120135
if (null !== $this->valueDate) {
121136
return $this->valueDate;
@@ -125,6 +140,10 @@ public function getValue(): string|DateTime|null
125140
return $this->valueString;
126141
}
127142

143+
if (null !== $this->valueBool) {
144+
return $this->valueBool;
145+
}
146+
128147
return null;
129148
}
130149
}

module/Application/src/Model/Enums/ConfigNamespaces.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/**
88
* The different namespaces in which configuration items can be created.
9-
* As a rule of thumb, a namespace should be restricted to one service or a welldefined set of a few services.
9+
* As a rule of thumb, a namespace should be restricted to one service or a well-defined set of a few services.
1010
*
1111
* Ideally these namespaces are defined inside the respective modules, but defining them as an enum allows for
1212
* verification in IDEs.
@@ -15,4 +15,5 @@ enum ConfigNamespaces: string
1515
{
1616
/* Database module */
1717
case DatabaseApi = 'database_api';
18+
case DatabaseMailman = 'database_mailman';
1819
}

module/Application/src/Service/Config.php

+7-2
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ public function __construct(private readonly ConfigItemMapper $configItemMapper)
1515
{
1616
}
1717

18+
/**
19+
* @template T of bool|string|DateTime|null
20+
* @psalm-param T $default
21+
* @psalm-return (T is null ? bool|string|DateTime|null : T|null)
22+
*/
1823
public function getConfig(
1924
ConfigNamespaces $namespace,
2025
string $key,
21-
string|DateTime|null $default = null,
26+
bool|string|DateTime|null $default = null,
2227
): string|DateTime|null {
2328
$configItem = $this->getConfigItemMapper()->findByKey($namespace, $key);
2429

@@ -32,7 +37,7 @@ public function getConfig(
3237
public function setConfig(
3338
ConfigNamespaces $namespace,
3439
string $key,
35-
string|DateTime $value,
40+
bool|string|DateTime $value,
3641
): void {
3742
$configItem = $this->getConfigItemMapper()->findByKey($namespace, $key);
3843

0 commit comments

Comments
 (0)