Use auth API for visibility update

This commit is contained in:
Brendan Abolivier 2017-08-16 15:11:18 +01:00
parent 83f8effbed
commit 0afa14b153
No known key found for this signature in database
GPG key ID: 8EF1500759F70623
2 changed files with 11 additions and 3 deletions

View file

@ -20,6 +20,7 @@ import (
"os"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/common/config"
"github.com/matrix-org/dendrite/publicroomsapi/consumers"
@ -49,6 +50,11 @@ func main() {
log.Panicf("startup: failed to create public rooms server database with data source %s : %s", cfg.Database.PublicRoomsAPI, err)
}
deviceDB, err := devices.NewDatabase(string(cfg.Database.Device), cfg.Matrix.ServerName)
if err != nil {
log.Panicf("startup: failed to create device database with data source %s : %s", cfg.Database.Device, err)
}
roomConsumer, err := consumers.NewOutputRoomEvent(cfg, db)
if err != nil {
log.Panicf("startup: failed to create room server consumer: %s", err)
@ -60,7 +66,7 @@ func main() {
log.Info("Starting public rooms server on ", cfg.Listen.PublicRoomsAPI)
api := mux.NewRouter()
routing.Setup(api, db)
routing.Setup(api, deviceDB, db)
common.SetupHTTPAPI(http.DefaultServeMux, api)
log.Fatal(http.ListenAndServe(string(cfg.Listen.PublicRoomsAPI), nil))

View file

@ -18,6 +18,8 @@ import (
"net/http"
"github.com/gorilla/mux"
"github.com/matrix-org/dendrite/clientapi/auth/authtypes"
"github.com/matrix-org/dendrite/clientapi/auth/storage/devices"
"github.com/matrix-org/dendrite/common"
"github.com/matrix-org/dendrite/publicroomsapi/directory"
"github.com/matrix-org/dendrite/publicroomsapi/storage"
@ -27,7 +29,7 @@ import (
const pathPrefixR0 = "/_matrix/client/r0"
// Setup configures the given mux with publicroomsapi server listeners
func Setup(apiMux *mux.Router, publicRoomsDB *storage.PublicRoomsServerDatabase) {
func Setup(apiMux *mux.Router, deviceDB *devices.Database, publicRoomsDB *storage.PublicRoomsServerDatabase) {
r0mux := apiMux.PathPrefix(pathPrefixR0).Subrouter()
r0mux.Handle("/directory/list/room/{roomID}",
common.MakeAPI("directory_list", func(req *http.Request) util.JSONResponse {
@ -36,7 +38,7 @@ func Setup(apiMux *mux.Router, publicRoomsDB *storage.PublicRoomsServerDatabase)
}),
).Methods("GET")
r0mux.Handle("/directory/list/room/{roomID}",
common.MakeAPI("directory_list", func(req *http.Request) util.JSONResponse {
common.MakeAuthAPI("directory_list", deviceDB, func(req *http.Request, device *authtypes.Device) util.JSONResponse {
vars := mux.Vars(req)
return directory.SetVisibility(req, publicRoomsDB, vars["roomID"])
}),