Commit Graph

223 Commits

Author SHA1 Message Date
Aine
74e7fa5f3b update README, closes #11 2022-08-29 20:40:52 +03:00
Aine
89d5ec8a91 adjust !pm mailboxes, relates to #15 2022-08-29 20:31:25 +03:00
Aine
e0bd71717c remove NOOWNER, closes #14 2022-08-29 20:21:37 +03:00
Aine
ba73b5a97c add !pm delete, closes #13 2022-08-29 20:18:25 +03:00
Aine
505a1b42d7 removed federation, closes #12 2022-08-29 19:58:54 +03:00
Aine
e52de55e1a update readme 2022-08-29 17:47:04 +03:00
Aine
d59ab94b13 Merge branch 'admin-support' into 'main'
Initial work on admin commands support

See merge request etke.cc/postmoogle!22
2022-08-29 14:45:27 +00:00
Aine
064346eef9 Merge branch 'main' into admin-support 2022-08-29 15:48:10 +03:00
Aine
5a5a649cba add cache 2022-08-29 15:28:37 +03:00
Aine
1a87929567 rename files; show commands by access level 2022-08-29 15:19:07 +03:00
Slavi Pantaleev
bc30f59e96 Move owner commands to their own file 2022-08-29 14:25:14 +03:00
Slavi Pantaleev
d20d4aa5bf Move mailboxes admin command to a separate file 2022-08-29 14:20:20 +03:00
Slavi Pantaleev
e59f5d5502 Make Match() with empty list not return a positive result
Now that we use Match() in allowAdmin() as well, it's awkward to
have it return `true` when called with an empty admin list.
No admins defined was taken to mean "everyone is an admin".

We can either have a `len(users) == 0` check in `allowAdmin` which
rejects the request, or we can change `Match()` so that it doesn't
return positive responses when called with an empty list. Doing the
latter sounds better. It's more natural that matching against an empty list
will yield "no match".
2022-08-29 14:10:52 +03:00
Aine
6623251695 refactored 2022-08-29 12:30:43 +03:00
Aine
ba2596afa2 Merge branch 'fix-double-domain' into 'main'
Do not append domain twice when updating mailbox

See merge request etke.cc/postmoogle!23
2022-08-29 08:08:30 +00:00
Slavi Pantaleev
97a4d6c7bc Do not append @domain twice when updating mailbox
Fixes a regression introduced in 13776ad7
2022-08-29 10:46:59 +03:00
Slavi Pantaleev
79775c0c13 Add basic mailboxes command
This can be improved in the future, to show some additional information
about each mailbox like:

- "how many users are in that room"
- "which users are in that room"
- "who is the owner of the mailbox"

This can all be done later though.
2022-08-29 10:28:19 +03:00
Slavi Pantaleev
a057654962 Put command access checks on the command level
Checking using `settings.Allowed` is odd. Not all commands are related
to setting configuration settings. Admin commands are coming in the
future, for which this is certainly not the case.

We now do access checks early on (during command processing), so command
handlers can be clean of access checks. If we're inside of a command
handler, the user is privileged to run it.
2022-08-29 10:27:53 +03:00
Slavi Pantaleev
a62dc0df4f Add POSTMOOGLE_ADMINS 2022-08-29 09:10:31 +03:00
Aine
77a7e9efc6 Merge branch 'show-option-value-in-help' into 'main'
Show option values in help

See merge request etke.cc/postmoogle!21
2022-08-28 15:37:29 +00:00
Aine
2397075717 Merge branch 'user-whitelisting' into 'main'
Add support for configuring user whitelisting

See merge request etke.cc/postmoogle!20
2022-08-28 15:36:53 +00:00
Aine
bd14987561 move settings.Allowed() to bot.Allowed() 2022-08-28 18:36:01 +03:00
Slavi Pantaleev
1d6b43a83a Reindent bot/bot.go 2022-08-28 17:56:19 +03:00
Slavi Pantaleev
dc5ed41723 Merge branch 'main' into 'user-whitelisting'
# Conflicts:
#   bot/bot.go
2022-08-28 14:50:57 +00:00
Aine
3174b21aec [skip ci] update readme 2022-08-28 17:35:53 +03:00
Aine
a150ada5c4 [skip ci] update readme 2022-08-28 17:35:15 +03:00
Aine
67fbc98c01 [skip ci] update readme 2022-08-28 17:34:02 +03:00
Aine
0e33107a4a add usage section in readme 2022-08-28 17:18:22 +03:00
Aine
9b1eb161e7 remove debug 2022-08-28 09:37:32 +03:00
Aine
13776ad7a6 properly update mailbox, fixes #9 2022-08-28 09:37:18 +03:00
Aine
6eae1a65c4 add utils.UnwrapError() to provide meaningful error messages 2022-08-27 22:38:23 +03:00
Aine
d1c48b9b31 add per-room mutex, possibly fixes #8 2022-08-27 22:10:22 +03:00
Aine
53bc5e6d59 proposed changes 2022-08-27 21:59:58 +03:00
Slavi Pantaleev
c8331e9958 Get rid of various duplicated optionMailbox formatting
`formatOptionValue` takes care of these now.

Besides fixing the duplication, this also fixes the lint error
affecting `sendHelp` - high complexity.
2022-08-27 19:35:45 +03:00
Slavi Pantaleev
972b4c11c5 Do not call getSettings() for each option in help
Retrieving the settings object for each and every option was wasteful

I don't like how we're doing custom formatting for optionMailbox in many
different places. This should be redone.
2022-08-27 19:22:21 +03:00
Slavi Pantaleev
0d88de9f77 Show option values in help
Before:

> * **`!pm help`** - Show this help message
> * **`!pm stop`** - Disable bridge for the room and clear all configuration
> * **`!pm mailbox`** - Get or set mailbox of the room
> * **`!pm owner`** - Get or set owner of the room
> * **`!pm nosender`** - Get or set `nosender` of the room (`true` - hide email sender; `false` - show email sender)
> * **`!pm nosubject`** - Get or set `nosubject` of the room (`true` - hide email subject; `false` - show email subject)
> * **`!pm nohtml`** - Get or set `nohtml` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails)
> * **`!pm nothreads`** - Get or set `nothreads` of the room (`true` - ignore email threads; `false` - convert email threads into matrix threads)
> * **`!pm nofiles`** - Get or set `nofiles` of the room (`true` - ignore email attachments; `false` - upload email attachments

After:

> * **`!pm help`** - Show this help message
> * **`!pm stop`** - Disable bridge for the room and clear all configuration
> * **`!pm mailbox`** (currently `something@example.com`) - Get or set mailbox of the room
> * **`!pm owner`** (currently `@someone:example.com`) - Get or set owner of the room
> * **`!pm nosender`** (currently `false`) - Get or set `nosender` of the room (`true` - hide email sender; `false` - show email sender)
> * **`!pm nosubject`** (currently `true`) - Get or set `nosubject` of the room (`true` - hide email subject; `false` - show email subject)
> * **`!pm nohtml`** (currently `false`) - Get or set `nohtml` of the room (`true` - ignore HTML in email; `false` - parse HTML in emails)
> * **`!pm nothreads`** (currently `false`) - Get or set `nothreads` of the room (`true` - ignore email threads; `false` - convert email threads into matrix threads)
> * **`!pm nofiles`** (currently `false`) - Get or set `nofiles` of the room (`true` - ignore email attachments; `false` - upload email attachments)
2022-08-27 17:47:16 +03:00
Slavi Pantaleev
3bc10bfe4f Honor allowed users list 2022-08-27 17:29:00 +03:00
Slavi Pantaleev
275ccbd9e5 Implement feedback 2022-08-27 08:11:36 +03:00
Slavi Pantaleev
1100ee6b5f Improve error when configuration reading fails 2022-08-27 07:51:56 +03:00
Slavi Pantaleev
58a1fa6b3f Do not check cognitive complexity in unit tests
Works around:

> utils/user_test.go:5:1: cognitive complexity 18 of func `TestRuleToRegex` is high (> 15) (gocognit)

Alternatively, we may look for a way to skip this test only.
It doesn't seem complex at all, so it looks like some false-positive.
2022-08-27 07:50:43 +03:00
Slavi Pantaleev
698cb6b8b9 Fix imports lint error 2022-08-27 07:50:43 +03:00
Slavi Pantaleev
bb754f9aa8 Simplify MatchUserWithAllowedRegexes
This used to return an error back when it was dealing with wildcards
(which may or may not have compiled to a valid regex).

But it now deals with pre-compiled regexes and has no chance of failing,
so we need no `error` returns.
2022-08-27 07:50:43 +03:00
Slavi Pantaleev
f8a168b8e7 Add a few more unit test cases 2022-08-27 07:50:43 +03:00
Slavi Pantaleev
8ad2e29930 Add support for configuring user whitelisting
This does not do anything useful just yet.
It will be hooked to access control checks later on.

Wildcards are converted to regular expressions, because it was simpler
to do that than to write (or include) some ugly wildcard matcher library.
It also provides more flexibility, should we wish to use it later.
Regular expressions should also work well performance-wise.

We compile wildcards to regexes early on (during configuration
processing) and fail if we detect a bad pattern. This is meant to
catch various problems (typos or other mistakes) that could happen.

For this to work, configuration building had to be redone, since it can
now return an error. This may be useful in the future for validating
other configuration settings.

Related to https://gitlab.com/etke.cc/postmoogle/-/issues/1
2022-08-27 07:50:41 +03:00
Aine
9484758f33 optimize introductions and help, kupo 2022-08-26 23:19:59 +03:00
Aine
f2d81495dc refactor Send(), fixes #6 2022-08-26 23:06:20 +03:00
Aine
4000b39480 add custom status message 2022-08-26 16:40:43 +03:00
Aine
2da1aacc7a automatically remove mailboxes in empty rooms, fixes #3 2022-08-26 16:22:44 +03:00
Aine
2dcba843cc add 'nofiles' option, refactored bot.Send(); fixes #2 2022-08-26 16:11:08 +03:00
Aine
42c9e15619 add 'nothreads' option, fixes #4 2022-08-26 16:00:37 +03:00