mirror of
https://github.com/writefreely/writefreely
synced 2024-11-10 11:24:13 +00:00
77f7b4a522
This renders all requests for that user's posts, collections and related ActivityPub endpoints with 404 responses. While suspended, users may not create or edit posts or collections. User status is listed in the admin user page Admin view of user details shows status and now has a button to activate or suspend a user.
91 lines
2.2 KiB
Go
91 lines
2.2 KiB
Go
/*
|
|
* Copyright © 2018 A Bunch Tell LLC.
|
|
*
|
|
* This file is part of WriteFreely.
|
|
*
|
|
* WriteFreely is free software: you can redistribute it and/or modify
|
|
* it under the terms of the GNU Affero General Public License, included
|
|
* in the LICENSE file in this source code package.
|
|
*/
|
|
|
|
package writefreely
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/writeas/go-webfinger"
|
|
"github.com/writeas/impart"
|
|
"github.com/writeas/web-core/log"
|
|
"github.com/writeas/writefreely/config"
|
|
)
|
|
|
|
type wfResolver struct {
|
|
db *datastore
|
|
cfg *config.Config
|
|
}
|
|
|
|
var wfUserNotFoundErr = impart.HTTPError{http.StatusNotFound, "User not found."}
|
|
|
|
func (wfr wfResolver) FindUser(username string, host, requestHost string, r []webfinger.Rel) (*webfinger.Resource, error) {
|
|
var c *Collection
|
|
var err error
|
|
if wfr.cfg.App.SingleUser {
|
|
c, err = wfr.db.GetCollectionByID(1)
|
|
} else {
|
|
c, err = wfr.db.GetCollection(username)
|
|
}
|
|
if err != nil {
|
|
log.Error("Unable to get blog: %v", err)
|
|
return nil, err
|
|
}
|
|
suspended, err := wfr.db.IsUserSuspended(c.OwnerID)
|
|
if err != nil {
|
|
log.Error("webfinger find user: check is suspended: %v", err)
|
|
return nil, err
|
|
}
|
|
if suspended {
|
|
return nil, wfUserNotFoundErr
|
|
}
|
|
c.hostName = wfr.cfg.App.Host
|
|
if wfr.cfg.App.SingleUser {
|
|
// Ensure handle matches user-chosen one on single-user blogs
|
|
if username != c.Alias {
|
|
log.Info("Username '%s' is not handle '%s'", username, c.Alias)
|
|
return nil, wfUserNotFoundErr
|
|
}
|
|
}
|
|
// Only return information if site has federation enabled.
|
|
// TODO: enable two levels of federation? Unlisted or Public on timelines?
|
|
if !wfr.cfg.App.Federation {
|
|
return nil, wfUserNotFoundErr
|
|
}
|
|
|
|
res := webfinger.Resource{
|
|
Subject: "acct:" + username + "@" + host,
|
|
Aliases: []string{
|
|
c.CanonicalURL(),
|
|
c.FederatedAccount(),
|
|
},
|
|
Links: []webfinger.Link{
|
|
{
|
|
HRef: c.CanonicalURL(),
|
|
Type: "text/html",
|
|
Rel: "https://webfinger.net/rel/profile-page",
|
|
},
|
|
{
|
|
HRef: c.FederatedAccount(),
|
|
Type: "application/activity+json",
|
|
Rel: "self",
|
|
},
|
|
},
|
|
}
|
|
return &res, nil
|
|
}
|
|
|
|
func (wfr wfResolver) DummyUser(username string, hostname string, r []webfinger.Rel) (*webfinger.Resource, error) {
|
|
return nil, wfUserNotFoundErr
|
|
}
|
|
|
|
func (wfr wfResolver) IsNotFoundError(err error) bool {
|
|
return err == wfUserNotFoundErr
|
|
}
|