Skip to content

Commit 503df11

Browse files
committed
Last mile work for issue rocky-linux#6: content blocking and new user moderation
This is a wrap-up PR for the work that NH started. The original issue is here: rocky-linux#6 The original PR from NH is here: rocky-linux#7 To summarize all of the *new* changes in this branch: - Added the ability to deploy a local-dev mattermost instance to test the plugin. - Resolved some bugs related to domain and user name blocking - Added in more test automation + tests in depth for new features - Documentation cleanup - Fixed issues reported by golang linting tools - Tuned LRUCache for slight performance improvement
1 parent 537ed90 commit 503df11

28 files changed

+4730
-817
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
dist
22
vendor/
33
bin/
4-
docker/data/
5-
docker/config/
4+
podman/**
5+
!podman/env.example
66
.env

CONTRIBUTING.md

100755100644
Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ This document is a primer for developing in this repository.
3737
```
3838

3939
4. **Mattermost Server** (9.3.0+)
40-
- Either local installation or Docker container
40+
- Either local installation or Podman container
4141
- Admin access for plugin management
4242

4343
5. **Git**
@@ -58,7 +58,7 @@ This document is a primer for developing in this repository.
5858
```
5959

6060
This installs:
61-
- `golangci-lint v2.5.0` - Go code linter
61+
- `golangci-lint v2.6.0` - Go code linter
6262
- `gotestsum v1.13.0` - Enhanced test runner
6363

6464
3. **Configure plugin deployment (optional - for local testing):**
@@ -111,60 +111,60 @@ The project uses GNU Make for build automation. Here are all available commands:
111111

112112
### Primary Build Commands
113113

114-
| Command | Description | Usage |
115-
|---------|-------------|-------|
116-
| `make all` | Complete build pipeline: check-style → test → dist | Use before committing |
117-
| `make dist` | Build production plugin bundle | Creates `dist/mattermost-community-toolkit-*.tar.gz` |
118-
| `make server` | Build server binaries only | Builds for linux-amd64 and linux-arm64 |
119-
| `make webapp` | Build webapp (currently disabled) | N/A - webapp is WIP |
120-
| `make bundle` | Create distribution tarball | Packages built artifacts |
121-
| `make clean` | Remove all build artifacts | Clean slate rebuild |
114+
| Command | Description | Usage |
115+
| ------------- | -------------------------------------------------- | ---------------------------------------------------- |
116+
| `make all` | Complete build pipeline: check-style → test → dist | Use before committing |
117+
| `make dist` | Build production plugin bundle | Creates `dist/mattermost-community-toolkit-*.tar.gz` |
118+
| `make server` | Build server binaries only | Builds for linux-amd64 and linux-arm64 |
119+
| `make webapp` | Build webapp (currently disabled) | N/A - webapp is WIP |
120+
| `make bundle` | Create distribution tarball | Packages built artifacts |
121+
| `make clean` | Remove all build artifacts | Clean slate rebuild |
122122

123123
### Development Commands
124124

125-
| Command | Description | Usage |
126-
|---------|-------------|-------|
127-
| `make apply` | Propagate manifest changes | Run after editing `plugin.json` |
128-
| `make deploy` | Build and install to server | Requires configured `pluginctl` |
129-
| `make watch` | Auto-rebuild on file changes | For webapp development |
130-
| `make deploy-from-watch` | Deploy watched changes | Use with `make watch` |
125+
| Command | Description | Usage |
126+
| ------------------------ | ---------------------------- | ------------------------------- |
127+
| `make apply` | Propagate manifest changes | Run after editing `plugin.json` |
128+
| `make deploy` | Build and install to server | Requires configured `pluginctl` |
129+
| `make watch` | Auto-rebuild on file changes | For webapp development |
130+
| `make deploy-from-watch` | Deploy watched changes | Use with `make watch` |
131131

132132
### Testing Commands
133133

134-
| Command | Description | Usage |
135-
|---------|-------------|-------|
136-
| `make test` | Run all tests with race detection | Standard test run |
137-
| `make test-ci` | CI-optimized test with JUnit output | For CI pipelines |
138-
| `make coverage` | Generate test coverage report | Opens HTML report in browser |
139-
| `make check-style` | Run linters (Go + JS) | Must pass before commit |
134+
| Command | Description | Usage |
135+
| ------------------ | ----------------------------------- | ---------------------------- |
136+
| `make test` | Run all tests with race detection | Standard test run |
137+
| `make test-ci` | CI-optimized test with JUnit output | For CI pipelines |
138+
| `make coverage` | Generate test coverage report | Opens HTML report in browser |
139+
| `make check-style` | Run linters (Go + JS) | Must pass before commit |
140140

141141
### Plugin Management Commands
142142

143-
| Command | Description | Usage |
144-
|---------|-------------|-------|
145-
| `make enable` | Enable the plugin | After deployment |
146-
| `make disable` | Disable the plugin | For testing |
147-
| `make reset` | Restart plugin (disable + enable) | Quick restart |
148-
| `make kill` | Force kill plugin process | Emergency stop |
149-
| `make logs` | View plugin logs | Debugging |
150-
| `make logs-watch` | Tail plugin logs | Real-time monitoring |
143+
| Command | Description | Usage |
144+
| ----------------- | --------------------------------- | -------------------- |
145+
| `make enable` | Enable the plugin | After deployment |
146+
| `make disable` | Disable the plugin | For testing |
147+
| `make reset` | Restart plugin (disable + enable) | Quick restart |
148+
| `make kill` | Force kill plugin process | Emergency stop |
149+
| `make logs` | View plugin logs | Debugging |
150+
| `make logs-watch` | Tail plugin logs | Real-time monitoring |
151151

152152
### Debugging Commands
153153

154-
| Command | Description | Usage |
155-
|---------|-------------|-------|
156-
| `make attach` | Attach dlv debugger | Interactive debugging |
157-
| `make attach-headless` | Headless dlv on port 2346 | Remote debugging |
158-
| `make detach` | Detach debugger | Stop debugging |
159-
| `make setup-attach` | Find plugin PID | Internal use |
154+
| Command | Description | Usage |
155+
| ---------------------- | ------------------------- | --------------------- |
156+
| `make attach` | Attach dlv debugger | Interactive debugging |
157+
| `make attach-headless` | Headless dlv on port 2346 | Remote debugging |
158+
| `make detach` | Detach debugger | Stop debugging |
159+
| `make setup-attach` | Find plugin PID | Internal use |
160160

161161
### Utility Commands
162162

163-
| Command | Description | Usage |
164-
|---------|-------------|-------|
165-
| `make install-go-tools` | Install required Go tools | First-time setup |
166-
| `make i18n-extract` | Extract translatable strings | For localization |
167-
| `make help` | Show all available commands | Quick reference |
163+
| Command | Description | Usage |
164+
| ----------------------- | ---------------------------- | ---------------- |
165+
| `make install-go-tools` | Install required Go tools | First-time setup |
166+
| `make i18n-extract` | Extract translatable strings | For localization |
167+
| `make help` | Show all available commands | Quick reference |
168168

169169
### Environment Variables
170170

@@ -268,7 +268,7 @@ goimports -w -local github.com/rocky-linux/mattermost-plugin-community-toolkit s
268268

269269
### Linting Rules
270270

271-
We use `golangci-lint v2.5.0+` with linting rules available in the file `.golangci.yml`
271+
We use `golangci-lint v2.6.0+` with linting rules configured in `.golangci.yml`
272272

273273
## Debugging
274274

@@ -308,7 +308,7 @@ We use `golangci-lint v2.5.0+` with linting rules available in the file `.golang
308308

309309
## Additional Resources
310310

311-
- [Plugin Architecture Overview](.local/ARCHITECTURE_OVERVIEW.md)
312311
- [Mattermost Plugin Developer Docs](https://developers.mattermost.com/integrate/plugins/)
313312
- [Go Documentation](https://go.dev/doc/)
314-
- [Original Repository](https://github.com/mattermost/mattermost-plugin-profanity-filter)
313+
- [Podman Development Environment](docs/PODMAN_DEVELOPMENT.md)
314+
- [New User Moderation Features](docs/NEW_USER_MODERATION.md)

Makefile

Lines changed: 77 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ else
9494
endif
9595
endif
9696

97+
## Alias for server target - builds the server component.
98+
.PHONY: build
99+
build: server
100+
97101
## Ensures NPM dependencies are installed without having to run this all the time.
98102
webapp/node_modules: $(wildcard webapp/package.json)
99103
ifneq ($(HAS_WEBAPP),)
@@ -279,6 +283,24 @@ ifneq ($(HAS_WEBAPP),)
279283
endif
280284
rm -fr build/bin/
281285

286+
## Formats Go and Markdown code.
287+
.PHONY: format
288+
format:
289+
@echo Formatting code...
290+
ifneq ($(HAS_SERVER),)
291+
@echo Formatting Go files...
292+
$(GO) fmt ./...
293+
endif
294+
@echo Formatting Markdown files...
295+
@if command -v prettier > /dev/null 2>&1; then \
296+
prettier --write "**/*.md"; \
297+
elif command -v npx > /dev/null 2>&1; then \
298+
npx --yes prettier --write "**/*.md"; \
299+
else \
300+
echo "Warning: prettier not found. Install it with 'npm install -g prettier' to format Markdown files."; \
301+
fi
302+
@echo Formatting complete.
303+
282304
.PHONY: logs
283305
logs:
284306
./build/bin/pluginctl logs $(PLUGIN_ID)
@@ -287,23 +309,40 @@ logs:
287309
logs-watch:
288310
./build/bin/pluginctl logs-watch $(PLUGIN_ID)
289311

290-
# Development environment management with Docker Compose
291-
DOCKER_COMPOSE_FILE ?= docker-compose.yml
292-
DOCKER_COMPOSE := docker-compose -f $(DOCKER_COMPOSE_FILE)
312+
# Development environment management with Podman Compose
313+
PODMAN_COMPOSE_FILE ?= podman-compose.yml
314+
PODMAN_COMPOSE := podman-compose -f $(PODMAN_COMPOSE_FILE)
293315

294-
## Starts the Docker Compose development stack.
316+
## Sets up the required directories for Podman development stack.
317+
.PHONY: dev-setup
318+
dev-setup:
319+
@echo "Setting up development environment directories..."
320+
@mkdir -p podman/data/mattermost/plugins podman/data/mattermost/client/plugins podman/data/postgres podman/config
321+
@chmod -R 777 podman/config podman/data/mattermost 2>/dev/null || true
322+
@echo "Directories created and permissions set."
323+
324+
## Starts the Podman Compose development stack.
295325
.PHONY: dev-up
296-
dev-up:
326+
dev-up: dev-setup
297327
@echo "Starting development environment..."
298-
$(DOCKER_COMPOSE) up -d
328+
$(PODMAN_COMPOSE) up -d
299329
@echo "Waiting for Mattermost to be ready..."
300330
@timeout 60 bash -c 'until $$(curl -s http://localhost:8065/api/v4/system/ping > /dev/null 2>&1); do sleep 2; done' || echo "Mattermost is starting. Access at http://localhost:8065"
331+
@echo "Creating admin account if it doesn't exist..."
332+
@$(MAKE) dev-create-admin || echo "Admin account already exists or creation failed"
301333

302-
## Stops the Docker Compose development stack.
334+
## Stops the Podman Compose development stack.
303335
.PHONY: dev-down
304336
dev-down:
305337
@echo "Stopping development environment..."
306-
$(DOCKER_COMPOSE) down
338+
$(PODMAN_COMPOSE) down
339+
340+
## Creates the admin account if it doesn't exist.
341+
## Uses credentials from podman-compose.yml (admin/admin123/[email protected])
342+
## Also creates a default team and adds the admin user to it.
343+
.PHONY: dev-create-admin
344+
dev-create-admin:
345+
@./scripts/dev-create-admin.sh
307346

308347
## Alias for dev-up
309348
.PHONY: dev-start
@@ -313,123 +352,88 @@ dev-start: dev-up
313352
.PHONY: dev-stop
314353
dev-stop: dev-down
315354

316-
## Restarts the Docker Compose development stack.
355+
## Restarts the Podman Compose development stack.
317356
.PHONY: dev-restart
318357
dev-restart: dev-down dev-up
319358

320359
## Removes containers, volumes, and data for a clean start.
321360
.PHONY: dev-clean
322361
dev-clean:
323362
@echo "Cleaning development environment (removing containers, volumes, and data)..."
324-
$(DOCKER_COMPOSE) down -v
325-
rm -rf docker/data/* docker/config/*
363+
$(PODMAN_COMPOSE) down -v
364+
sudo rm -rf podman/data/* podman/config/*
326365
@echo "Development environment cleaned. Run 'make dev-up' to start fresh."
327366

328367
## Views Mattermost server logs.
329368
.PHONY: dev-logs
330369
dev-logs:
331-
$(DOCKER_COMPOSE) logs mattermost
370+
$(PODMAN_COMPOSE) logs mattermost
332371

333372
## Tails Mattermost server logs in real-time.
334373
.PHONY: dev-logs-watch
335374
dev-logs-watch:
336-
$(DOCKER_COMPOSE) logs -f mattermost
375+
$(PODMAN_COMPOSE) logs -f mattermost
337376

338-
## Builds and deploys the plugin to the Docker development stack.
377+
## Builds and deploys the plugin to the Podman development stack.
339378
.PHONY: dev-deploy
340379
dev-deploy: dist
341-
@if ! $(DOCKER_COMPOSE) ps mattermost | grep -q "Up"; then \
342-
echo "Error: Mattermost container is not running. Run 'make dev-up' first."; \
343-
exit 1; \
344-
fi
345-
@echo "Deploying plugin to development environment..."
346-
@if [ -f docker/.env ]; then \
347-
echo "Loading environment variables from docker/.env..."; \
348-
set -a && . docker/.env && set +a; \
349-
fi
350-
@if [ -z "$$MM_ADMIN_TOKEN" ] && [ -z "$$MM_ADMIN_USERNAME" ]; then \
351-
echo "Warning: MM_ADMIN_TOKEN or MM_ADMIN_USERNAME/MM_ADMIN_PASSWORD not set."; \
352-
echo "Please set them in docker/.env or export them in your shell."; \
353-
echo "See docker/env.example for an example."; \
354-
fi
355-
MM_SERVICESETTINGS_SITEURL=http://localhost:8065 \
356-
./build/bin/pluginctl deploy $(PLUGIN_ID) dist/$(BUNDLE_NAME)
357-
@echo "Plugin deployed. Run 'make dev-enable' to enable it, or enable via System Console."
380+
@PLUGIN_ID=$(PLUGIN_ID) BUNDLE_NAME=dist/$(BUNDLE_NAME) ./scripts/dev-deploy.sh
358381

359382
## Opens a shell in the Mattermost container.
360383
.PHONY: dev-shell
361384
dev-shell:
362-
$(DOCKER_COMPOSE) exec mattermost /bin/sh
385+
$(PODMAN_COMPOSE) exec mattermost /bin/sh
363386

364-
## Shows status of Docker Compose services.
387+
## Shows status of Podman Compose services.
365388
.PHONY: dev-status
366389
dev-status:
367-
$(DOCKER_COMPOSE) ps
390+
$(PODMAN_COMPOSE) ps
368391

369392
## Enables the plugin in the development environment.
370393
.PHONY: dev-enable
371394
dev-enable:
372-
@if ! $(DOCKER_COMPOSE) ps mattermost | grep -q "Up"; then \
373-
echo "Error: Mattermost container is not running. Run 'make dev-up' first."; \
374-
exit 1; \
375-
fi
376-
@if [ -f docker/.env ]; then \
377-
set -a && . docker/.env && set +a; \
378-
fi
379-
MM_SERVICESETTINGS_SITEURL=http://localhost:8065 \
395+
@./scripts/dev-check-container.sh
396+
@MM_SERVICESETTINGS_SITEURL=http://localhost:8065 \
380397
./build/bin/pluginctl enable $(PLUGIN_ID)
381398

382399
## Disables the plugin in the development environment.
383400
.PHONY: dev-disable
384401
dev-disable:
385-
@if ! $(DOCKER_COMPOSE) ps mattermost | grep -q "Up"; then \
386-
echo "Error: Mattermost container is not running. Run 'make dev-up' first."; \
387-
exit 1; \
388-
fi
389-
@if [ -f docker/.env ]; then \
390-
set -a && . docker/.env && set +a; \
391-
fi
392-
MM_SERVICESETTINGS_SITEURL=http://localhost:8065 \
402+
@./scripts/dev-check-container.sh
403+
@MM_SERVICESETTINGS_SITEURL=http://localhost:8065 \
393404
./build/bin/pluginctl disable $(PLUGIN_ID)
394405

395406
## Resets the plugin in the development environment (disables and re-enables).
396407
.PHONY: dev-reset
397408
dev-reset:
398-
@if ! $(DOCKER_COMPOSE) ps mattermost | grep -q "Up"; then \
399-
echo "Error: Mattermost container is not running. Run 'make dev-up' first."; \
400-
exit 1; \
401-
fi
402-
@if [ -f docker/.env ]; then \
403-
set -a && . docker/.env && set +a; \
404-
fi
405-
MM_SERVICESETTINGS_SITEURL=http://localhost:8065 \
409+
@./scripts/dev-check-container.sh
410+
@MM_SERVICESETTINGS_SITEURL=http://localhost:8065 \
406411
./build/bin/pluginctl reset $(PLUGIN_ID)
407412

408413
## Views plugin logs in the development environment.
409414
.PHONY: dev-plugin-logs
410415
dev-plugin-logs:
411-
@if ! $(DOCKER_COMPOSE) ps mattermost | grep -q "Up"; then \
412-
echo "Error: Mattermost container is not running. Run 'make dev-up' first."; \
413-
exit 1; \
414-
fi
415-
@if [ -f docker/.env ]; then \
416-
set -a && . docker/.env && set +a; \
417-
fi
418-
MM_SERVICESETTINGS_SITEURL=http://localhost:8065 \
416+
@./scripts/dev-check-container.sh
417+
@MM_SERVICESETTINGS_SITEURL=http://localhost:8065 \
419418
./build/bin/pluginctl logs $(PLUGIN_ID)
420419

421420
## Tails plugin logs in the development environment.
422421
.PHONY: dev-plugin-logs-watch
423422
dev-plugin-logs-watch:
424-
@if ! $(DOCKER_COMPOSE) ps mattermost | grep -q "Up"; then \
425-
echo "Error: Mattermost container is not running. Run 'make dev-up' first."; \
423+
@./scripts/dev-check-container.sh
424+
@MM_SERVICESETTINGS_SITEURL=http://localhost:8065 \
425+
./build/bin/pluginctl logs-watch $(PLUGIN_ID)
426+
427+
## Pings the Mattermost healthcheck endpoint to verify server is responding.
428+
.PHONY: dev-check-ping
429+
dev-check-ping:
430+
@echo "Checking Mattermost healthcheck endpoint..."
431+
@if $(CURL) -f -s http://localhost:8065/api/v4/system/ping > /dev/null 2>&1; then \
432+
echo "✓ Mattermost is responding (http://localhost:8065/api/v4/system/ping)"; \
433+
else \
434+
echo "✗ Mattermost is not responding. Is it running? (Try 'make dev-up')"; \
426435
exit 1; \
427436
fi
428-
@if [ -f docker/.env ]; then \
429-
set -a && . docker/.env && set +a; \
430-
fi
431-
MM_SERVICESETTINGS_SITEURL=http://localhost:8065 \
432-
./build/bin/pluginctl logs-watch $(PLUGIN_ID)
433437

434438
# Help documentation à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
435439
help:

0 commit comments

Comments
 (0)