Skip to content

Commit

Permalink
Merge branch 'master' into feature/listeners
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Feb 11, 2025
2 parents ed4c58c + d668a33 commit ae010af
Show file tree
Hide file tree
Showing 72 changed files with 274 additions and 297 deletions.
53 changes: 40 additions & 13 deletions big_tests/tests/pep_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
-export([
disco_test/1,
disco_sm_test/1,
disco_sm_node_test/1,
disco_sm_items_test/1,
disco_sm_items_node_test/1,
pep_caps_test/1,
publish_and_notify_test/1,
auto_create_with_publish_options_test/1,
Expand Down Expand Up @@ -68,7 +70,9 @@ groups() ->
[
disco_test,
disco_sm_test,
disco_sm_node_test,
disco_sm_items_test,
disco_sm_items_node_test,
pep_caps_test,
publish_and_notify_test,
auto_create_with_publish_options_test,
Expand Down Expand Up @@ -148,20 +152,39 @@ disco_test(Config) ->
end).

disco_sm_test(Config) ->
disco_sm_test(Config, undefined).

disco_sm_node_test(Config) ->
disco_sm_test(Config, random_node_ns()).

disco_sm_test(Config, Node) ->
escalus:fresh_story(
Config,
[{alice, 1}],
fun(Alice) ->
AliceJid = escalus_client:short_jid(Alice),
escalus:send(Alice, escalus_stanza:disco_info(AliceJid)),
Stanza = escalus:wait_for_stanza(Alice),
?assertNot(escalus_pred:has_identity(<<"pubsub">>, <<"service">>, Stanza)),
escalus:assert(has_identity, [<<"pubsub">>, <<"pep">>], Stanza),
escalus:assert(has_feature, [?NS_PUBSUB], Stanza),
escalus:assert(is_stanza_from, [AliceJid], Stanza)
end).
Config,
[{alice, 1}],
fun(Alice) ->
AliceJid = escalus_client:short_jid(Alice),
Disco =
case Node of
undefined ->
escalus_stanza:disco_info(AliceJid);
_ ->
escalus_stanza:disco_info(AliceJid, Node)
end,
escalus:send(Alice, Disco),
Stanza = escalus:wait_for_stanza(Alice),
?assertNot(escalus_pred:has_identity(<<"pubsub">>, <<"service">>, Stanza)),
escalus:assert(has_identity, [<<"pubsub">>, <<"pep">>], Stanza),
escalus:assert(has_feature, [?NS_PUBSUB], Stanza),
escalus:assert(is_stanza_from, [AliceJid], Stanza)
end).

disco_sm_items_test(Config) ->
disco_sm_items_test(Config, false).

disco_sm_items_node_test(Config) ->
disco_sm_items_test(Config, true).

disco_sm_items_test(Config, UseNode) ->
NodeNS = random_node_ns(),
escalus:fresh_story(
Config,
Expand All @@ -170,7 +193,11 @@ disco_sm_items_test(Config) ->
AliceJid = escalus_client:short_jid(Alice),

%% Node not present yet
escalus:send(Alice, escalus_stanza:disco_items(AliceJid)),
DiscoStanza = case UseNode of
true -> escalus_stanza:disco_items(AliceJid, NodeNS);
false -> escalus_stanza:disco_items(AliceJid)
end,
escalus:send(Alice, DiscoStanza),
Stanza1 = escalus:wait_for_stanza(Alice),
Query1 = exml_query:subelement(Stanza1, <<"query">>),
?assertEqual(undefined, exml_query:subelement_with_attr(Query1, <<"node">>, NodeNS)),
Expand All @@ -180,7 +207,7 @@ disco_sm_items_test(Config) ->
pubsub_tools:publish(Alice, <<"item1">>, {pep, NodeNS}, []),

%% Node present
escalus:send(Alice, escalus_stanza:disco_items(AliceJid)),
escalus:send(Alice, DiscoStanza),
Stanza2 = escalus:wait_for_stanza(Alice),
Query2 = exml_query:subelement(Stanza2, <<"query">>),
Item = exml_query:subelement_with_attr(Query2, <<"node">>, NodeNS),
Expand Down
5 changes: 5 additions & 0 deletions doc/configuration/Services.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ The number of seconds between cleaning attempts of the `domain_events` table.

The number of seconds after an event must be deleted from the `domain_events` table.

## service_translations

Enables translations for system messages.
Support is minimal, you can check `priv/translations/` for translated messages.

## Example configuration

```toml
Expand Down
45 changes: 45 additions & 0 deletions doc/migrations/6.3.1_6.x.y.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,48 @@ It is also possible to completely disable client certificate verification during
handshake in `just_tls` by setting `tls.verify_mode` to `none`.

For more information regarding configuration of TLS for C2S see [Listener modules](../listeners/listen-c2s/#tls-options-for-c2s)

## `exml` upgraded to 4.0

### Change of internal format of XML messages affects the ways to upgrade MongooseIM cluster

`exml` library used for parsing and emitting of XML messages was upgraded to version 4.0.
In this new version internal representation of XML elements changed - element attributes
are stored in a map (previously in a key value list).

This is a disruptive change, and rollback to previous version is not possible.

Parsed XML messages are being sent within MongooseIM cluster between Erlang nodes in internal representation,
so to understand received messages (Erlang terms), all nodes must have the same code that handle XML elements. This makes a rolling upgrade
(an upgrade of a cluster node by node) not viable for this release.

One solution is to stop the whole MongooseIM cluster, upgrade and start again.

The second solution is to configure a new cluster running new version
alongside the old cluster, and migrate traffic from the old one to the new one.

There is a third solution, which allows to maintain service availability but not requiring building a full new cluster.
In this solution, you upgrade nodes one by one (like in the rolling upgrade), but change configuration to not allow
upgraded node to rejoin the old cluster, but instead run as a new cluster.
That way all nodes are migrated one by one to the newly formed cluster. Both clusters have access the same database.

One warning regarding this solution: There is a corner case regarding access to archived messages only while both clusters
are operating simultaneously. It may happen that users still connected to the old cluster try to retrieve newly archived messages.
This will result in errors and possibly crashes as the old code doesn't recognise new internal representation.
We just want to warn the operator about such possibility, the chance of it happening is slight, as we recommend the upgrade
to be undertaken during the time of minimal traffic.

### Archived XML - mod_mam

Change of XML element representation also affects stored or archived messages, if they are stored in the internal Erlang term format.

There is a config setting `modules.mod_mam.db_message_format` which controls the message format for archived messages
and its default is different depending on the database backend used.
The default for RDBMS databases is `mam_message_compressed_eterm` (which is Erlang term format) while for Cassandra it is `mam_message_xml`.

Messages stored in XML textual format (`mam_message_xml`) are not affected by `exml` version change.

For messages stored as Erlang term (`mam_message_compressed_eterm` or `mam_message_eterm`), we provide transparent retrieval of the old format, while new messages will be written in the archive in
the new format. This means that the change of the format is transparent in operations of MongooseIM.
However if you have external tools accessing message archive, you may need to verify that they work correctly with the new internal XML element representation.

2 changes: 1 addition & 1 deletion include/mod_vcard.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
-export_type([vcard_search/0]).

-define(TLFIELD(Type, Label, Var),
#{var => Var, type => Type, label => translate:translate(Lang, Label)}).
#{var => Var, type => Type, label => service_translations:do(Lang, Label)}).

-define(FIELD(Var, Val),
#{var => Var, values => [Val]}).
7 changes: 0 additions & 7 deletions priv/graphql/schemas/user/account.gql
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
"""
Allow user to get information about account.
"""
type AccountUserQuery @protected{
field: Boolean
}

"""
Allow user to manage own account.
"""
Expand Down
2 changes: 0 additions & 2 deletions priv/graphql/schemas/user/user_schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Only an authenticated user can execute these queries.
type UserQuery{
"Check authorization status"
checkAuth: UserAuthInfo
"Account management"
account: AccountUserQuery
"Last activity management"
last: LastUserQuery
"MUC room management"
Expand Down
160 changes: 52 additions & 108 deletions priv/graphql/wsite/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,138 +2,82 @@
* Copyright (c) 2021 GraphQL Contributors
* All rights reserved.
*
* This source code is licensed under the license
* https://github.com/graphql/graphiql/blob/main/LICENSE.
* the original version of the file:
* https://github.com/graphql/graphiql/blob/[email protected]/examples/graphiql-cdn/index.html
*
* This source code is licensed under the license found at:
* https://github.com/graphql/graphiql/blob/[email protected]/LICENSE
-->
<!DOCTYPE html>
<html>
<!doctype html>
<html lang="en">
<head>
<title>GraphiQL</title>
<style>
body {
height: 100%;
margin: 0;
width: 100%;
overflow: hidden;
}

#graphiql {
height: 100vh;
}
</style>
<title>GraphiQL MongooseIM Api</title>
<link href="https://unpkg.com/[email protected]/graphiql.min.css" rel="stylesheet" />
</head>
<body style="margin: 0;">
<div id="graphiql">Loading...</div>
<!--
This GraphiQL example depends on Promise and fetch, which are available in
modern browsers, but can be "polyfilled" for older browsers.
GraphiQL itself depends on React DOM.
If you do not want to rely on a CDN, you can host these files locally or
include them directly in your favored resource bundler.
-->
<script
crossorigin
src="https://unpkg.com/react/umd/react.production.min.js"></script>
src="https://unpkg.com/react@18/umd/react.production.min.js"
></script>
<script
crossorigin
src="https://unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"
></script>
<!--
These two files can be found in the npm module, however you may wish to
copy them directly into your environment, or perhaps include them in your
favored resource bundler.
-->
<script
src="https://unpkg.com/graphiql/graphiql.min.js"
type="application/javascript"
></script>
<link rel="stylesheet" href="https://unpkg.com/graphiql/graphiql.min.css" />
<!--
These are imports for the GraphIQL Explorer plugin.
-->
<script
src="https://unpkg.com/@graphiql/plugin-explorer/dist/index.umd.js"
crossorigin
src="https://unpkg.com/[email protected]/graphiql.min.js"></script>
<script>
></script>

/**
* This GraphiQL example illustrates how to use some of GraphiQL's props
* in order to enable reading and updating the URL parameters, making
* link sharing of queries a little bit easier.
*
* This is only one example of this kind of feature, GraphiQL exposes
* various React params to enable interesting integrations.
*/
<link
rel="stylesheet"
href="https://unpkg.com/@graphiql/plugin-explorer/dist/style.css"
/>
</head>

// Parse the search string to get url parameters.
var search = window.location.search;
var parameters = {};
search.substr(1).split('&').forEach(function (entry) {
var eq = entry.indexOf('=');
if (eq >= 0) {
parameters[decodeURIComponent(entry.slice(0, eq))] =
decodeURIComponent(entry.slice(eq + 1));
}
<body>
<div id="graphiql">Loading...</div>
<script>
const root = ReactDOM.createRoot(document.getElementById('graphiql'));
const fetcher = GraphiQL.createFetcher({
url: '/api/graphql/',
headers: { 'X-Example-Header': 'foo' },
});

// if variables was provided, try to format it.
if (parameters.variables) {
try {
parameters.variables =
JSON.stringify(JSON.parse(parameters.variables), null, 2);
} catch (e) {
// Do nothing, we want to display the invalid JSON as a string, rather
// than present an error.
}
}

// When the query and variables string is edited, update the URL bar so
// that it can be easily shared
function onEditQuery(newQuery) {
parameters.query = newQuery;
updateURL();
}

function onEditVariables(newVariables) {
parameters.variables = newVariables;
updateURL();
}

function onEditOperationName(newOperationName) {
parameters.operationName = newOperationName;
updateURL();
}

function updateURL() {
var newSearch = '?' + Object.keys(parameters).filter(function (key) {
return Boolean(parameters[key]);
}).map(function (key) {
return encodeURIComponent(key) + '=' +
encodeURIComponent(parameters[key]);
}).join('&');
history.replaceState(null, null, newSearch);
}

// Defines a GraphQL fetcher using the fetch API. You're not required to
// use fetch, and could instead implement graphQLFetcher however you like,
// as long as it returns a Promise or Observable.
function graphQLFetcher(graphQLParams, opts = {headers: {}}) {
// This example expects a GraphQL server at the path /graphql.
// Change this to point wherever you host your GraphQL server.
return fetch('/api/graphql/', {
method: 'post',
headers: Object.assign({
'Accept': 'application/json',
'Content-Type': 'application/json'}, opts.headers),
body: JSON.stringify(graphQLParams),
credentials: 'include',
}).then(function (response) {
return response.text();
}).then(function (responseBody) {
try {
return JSON.parse(responseBody);
} catch (error) {
return responseBody;
}
});
}

// Render <GraphiQL /> into the body.
// See the README in the top level of this module to learn more about
// how you can customize GraphiQL by providing different values or
// additional child elements.
ReactDOM.render(
const explorerPlugin = GraphiQLPluginExplorer.explorerPlugin();
root.render(
React.createElement(GraphiQL, {
fetcher: graphQLFetcher,
query: parameters.query,
variables: parameters.variables,
operationName: parameters.operationName,
onEditQuery: onEditQuery,
onEditVariables: onEditVariables,
headerEditorEnabled: true,
headers: '{}',
onEditOperationName: onEditOperationName
fetcher,
defaultEditorToolsVisibility: true,
plugins: [explorerPlugin],
}),
document.getElementById('graphiql')
);
</script>
</body>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion src/config/mongoose_config_spec.erl
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,8 @@ services() ->

configurable_services() ->
[service_mongoose_system_metrics,
service_domain_db].
service_domain_db,
service_translations].

%% path: (host_config[].)modules
modules() ->
Expand Down
1 change: 0 additions & 1 deletion src/ejabberd_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ do_start() ->
mongoose_config:start(),
mongoose_internal_databases:init(),
mongoose_graphql:init(),
translate:start(),
mongoose_graphql_commands:start(),
mongoose_logs:set_global_loglevel(mongoose_config:get_opt(loglevel)),
mongoose_deprecations:start(),
Expand Down
1 change: 0 additions & 1 deletion src/graphql/mongoose_graphql.erl
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,6 @@ user_mapping_rules() ->
'UserQuery' => mongoose_graphql_user_query,
'UserMutation' => mongoose_graphql_user_mutation,
'UserSubscription' => mongoose_graphql_user_subscription,
'AccountUserQuery' => mongoose_graphql_account_user_query,
'AccountUserMutation' => mongoose_graphql_account_user_mutation,
'InboxUserMutation' => mongoose_graphql_inbox_user_mutation,
'MUCUserMutation' => mongoose_graphql_muc_user_mutation,
Expand Down
Loading

0 comments on commit ae010af

Please sign in to comment.