1
Fork 0
mirror of https://github.com/jech/galene.git synced 2024-11-09 10:15:58 +01:00

Implement "expires" and "not-before" for groups.

This commit is contained in:
Juliusz Chroboczek 2024-03-03 16:45:54 +01:00
parent 4fe31b4863
commit de0c42faaf
3 changed files with 24 additions and 0 deletions

2
README
View file

@ -157,6 +157,8 @@ nobody will be able to join the group. The following fields are allowed:
a time;
- `max-history-age`: the time, in seconds, during which chat history is
kept (default 14400, i.e. 4 hours);
- `not-before` and `expires`: the times (in ISO 8601 or RFC 3339 format)
between which joining the group is allowed;
- `allow-recording`: if true, then recording is allowed in this group;
- `unrestricted-tokens`: if true, then ordinary users (without the "op"
privilege) are allowed to create tokens;

View file

@ -46,6 +46,12 @@ type Description struct {
// The time for which history entries are kept.
MaxHistoryAge int `json:"max-history-age,omitempty"`
// Time after which joining is no longer allowed
Expires *time.Time `json:"expires"`
// Time before which joining is not allowed
NotBefore *time.Time `json:"not-before,omitempty"`
// Whether users are allowed to log in with an empty username.
AllowAnonymous bool `json:"allow-anonymous,omitempty"`

View file

@ -607,6 +607,22 @@ func AddClient(group string, c Client, creds ClientCredentials) (*Group, error)
}
return nil, UserError(m)
}
if g.description.NotBefore != nil ||
g.description.Expires != nil {
now := time.Now()
if g.description.NotBefore != nil &&
g.description.NotBefore.After(now) {
return nil, UserError(
"this group is not open yet",
)
}
if g.description.Expires != nil &&
g.description.Expires.Before(now) {
return nil, UserError(
"this group is closed",
)
}
}
if g.description.Autokick {
ops := false
for _, c := range clients {