Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mailman API integration for synchronisation of mailing list memberships #279

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 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 All @@ -67,6 +72,7 @@ LDAP_BASEDN=
# These are the environment variables for Postgres, only used in docker-compose.override.yaml for development
POSTGRES_PASSWORD=gewisdb
POSTGRES_USER=gewisdb
POSTGRES_MAILMAN_DATABASE=gewisdb_mailman
[email protected]
PGADMIN_DEFAULT_PASSWORD=pgadmin
PGADMIN_DISABLE_POSTFIX=true
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ phpcs.xml

# Language binaries are created during the docker build process or using 'make compilelang'
*.mo

# Local mailman data for development
mailman/
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
41 changes: 40 additions & 1 deletion docker-compose.override.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
- .env
volumes:
- gewisdb_postgresql:/var/lib/postgresql/data:rw
- ./docker/pgadmin/create-gewisdb_report-database.sh:/docker-entrypoint-initdb.d/create-database.sh
- ./docker/pgadmin/create-gewisdb-database.sh:/docker-entrypoint-initdb.d/create-database.sh
networks:
- gewisdb_network
ports:
Expand All @@ -29,8 +29,46 @@ services:
image: mailhog/mailhog
ports:
- "8025:8025"
mailman-core:
image: maxking/mailman-core:0.4
container_name: mailman-core
hostname: mailmanc
volumes:
- ./mailman/core:/opt/mailman/
depends_on:
- postgresql
environment:
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgresql/${POSTGRES_MAILMAN_DATABASE}
- DATABASE_TYPE=postgres
- DATABASE_CLASS=mailman.database.postgresql.PostgreSQLDatabase
- HYPERKITTY_API_KEY=somerandomapikeythatiobviouslydidnotcreatemyself
ports:
- "8020:8001"
networks:
- gewisdb_network
mailman-web:
image: maxking/mailman-web:0.4
container_name: mailman-web
hostname: mailmanw
depends_on:
- postgresql
volumes:
- ./mailman/web:/opt/mailman-web-data/
environment:
- DATABASE_URL=postgresql://${POSTGRES_USER}:${POSTGRES_PASSWORD}@postgresql/${POSTGRES_MAILMAN_DATABASE}
- DATABASE_TYPE=postgres
- HYPERKITTY_API_KEY=somerandomapikeythatiobviouslydidnotcreatemyself
- SECRET_KEY=anotherandomkeythatiobviouslydidnotcreatemyself
- SERVE_FROM_DOMAIN=localhost
- UWSGI_STATIC_MAP=/static=/opt/mailman-web-data/static
ports:
- "8021:8000"
networks:
- gewisdb_network
nginx:
build: docker/nginx
volumes:
- ./mailman/web/static:/var/html/mailman/
ports:
- "80:9725"
stripe:
Expand All @@ -50,6 +88,7 @@ services:
dockerfile: docker/web/development/Dockerfile
context: .
depends_on:
- mailman-core
- 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
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ set -e
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" <<-PGSQL
CREATE DATABASE $DOCTRINE_REPORT_DATABASE;
GRANT ALL PRIVILEGES ON DATABASE $DOCTRINE_REPORT_DATABASE TO $POSTGRES_USER;
CREATE DATABASE $POSTGRES_MAILMAN_DATABASE;
GRANT ALL PRIVILEGES ON DATABASE $POSTGRES_MAILMAN_DATABASE TO $POSTGRES_USER;
PGSQL
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
24 changes: 22 additions & 2 deletions module/Application/src/Model/ConfigItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use LogicException;
use TypeError;

use function is_bool;
use function is_string;

/**
Expand Down Expand Up @@ -77,6 +78,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 +112,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)) {
$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 +141,10 @@ public function getValue(): string|DateTime|null
return $this->valueString;
}

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

return null;
}
}
Loading
Loading