Merge pull request #6009 from matrix-org/t3chguy/fix/15359

Improve permissions error when adding new server to room directory
This commit is contained in:
Michael Telatynski 2021-05-11 12:36:40 +01:00 committed by GitHub
commit f0342b0ea7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 14 deletions

View file

@ -49,6 +49,18 @@ const inPlaceOf = (elementRect) => ({
}); });
const validServer = withValidation({ const validServer = withValidation({
deriveData: async ({ value }) => {
try {
// check if we can successfully load this server's room directory
await MatrixClientPeg.get().publicRooms({
limit: 1,
server: value,
});
return {};
} catch (error) {
return { error };
}
},
rules: [ rules: [
{ {
key: "required", key: "required",
@ -57,21 +69,11 @@ const validServer = withValidation({
}, { }, {
key: "available", key: "available",
final: true, final: true,
test: async ({ value }) => { test: async (_, { error }) => !error,
try {
const opts = {
limit: 1,
server: value,
};
// check if we can successfully load this server's room directory
await MatrixClientPeg.get().publicRooms(opts);
return true;
} catch (e) {
return false;
}
},
valid: () => _t("Looks good"), valid: () => _t("Looks good"),
invalid: () => _t("Can't find this server or its room list"), invalid: ({ error }) => error.errcode === "M_FORBIDDEN"
? _t("You are not allowed to view this server's rooms list")
: _t("Can't find this server or its room list"),
}, },
], ],
}); });

View file

@ -2020,6 +2020,7 @@
"Home": "Home", "Home": "Home",
"Enter a server name": "Enter a server name", "Enter a server name": "Enter a server name",
"Looks good": "Looks good", "Looks good": "Looks good",
"You are not allowed to view this server's rooms list": "You are not allowed to view this server's rooms list",
"Can't find this server or its room list": "Can't find this server or its room list", "Can't find this server or its room list": "Can't find this server or its room list",
"Your server": "Your server", "Your server": "Your server",
"Are you sure you want to remove <b>%(serverName)s</b>": "Are you sure you want to remove <b>%(serverName)s</b>", "Are you sure you want to remove <b>%(serverName)s</b>": "Are you sure you want to remove <b>%(serverName)s</b>",