mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Add stubs for affiliation-specific backend callbacks
This commit is contained in:
parent
3fc0eb4f5b
commit
06ce884aa8
@ -502,8 +502,8 @@ handle_event(destroy, StateName, StateData) ->
|
|||||||
handle_event({destroy, <<"">>}, StateName, StateData);
|
handle_event({destroy, <<"">>}, StateName, StateData);
|
||||||
handle_event({set_affiliations, Affiliations},
|
handle_event({set_affiliations, Affiliations},
|
||||||
StateName, StateData) ->
|
StateName, StateData) ->
|
||||||
{next_state, StateName,
|
NewStateData = set_affiliations(Affiliations, StateData),
|
||||||
StateData#state{affiliations = Affiliations}};
|
{next_state, StateName, NewStateData};
|
||||||
handle_event(_Event, StateName, StateData) ->
|
handle_event(_Event, StateName, StateData) ->
|
||||||
{next_state, StateName, StateData}.
|
{next_state, StateName, StateData}.
|
||||||
|
|
||||||
@ -1264,7 +1264,24 @@ set_affiliation(JID, Affiliation, StateData) ->
|
|||||||
set_affiliation(JID, Affiliation, StateData, <<"">>).
|
set_affiliation(JID, Affiliation, StateData, <<"">>).
|
||||||
|
|
||||||
-spec set_affiliation(jid(), affiliation(), state(), binary()) -> state().
|
-spec set_affiliation(jid(), affiliation(), state(), binary()) -> state().
|
||||||
|
set_affiliation(JID, Affiliation,
|
||||||
|
#state{config = #config{persistent = false}} = StateData,
|
||||||
|
Reason) ->
|
||||||
|
set_affiliation_fallback(JID, Affiliation, StateData, Reason);
|
||||||
set_affiliation(JID, Affiliation, StateData, Reason) ->
|
set_affiliation(JID, Affiliation, StateData, Reason) ->
|
||||||
|
ServerHost = StateData#state.server_host,
|
||||||
|
Room = StateData#state.room,
|
||||||
|
Host = StateData#state.host,
|
||||||
|
Mod = gen_mod:db_mod(ServerHost, mod_muc),
|
||||||
|
case Mod:set_affiliation(ServerHost, Room, Host, JID, Affiliation, Reason) of
|
||||||
|
ok ->
|
||||||
|
StateData;
|
||||||
|
{error, _} ->
|
||||||
|
set_affiliation_fallback(JID, Affiliation, StateData, Reason)
|
||||||
|
end.
|
||||||
|
|
||||||
|
-spec set_affiliation_fallback(jid(), affiliation(), state(), binary()) -> state().
|
||||||
|
set_affiliation_fallback(JID, Affiliation, StateData, Reason) ->
|
||||||
LJID = jid:remove_resource(jid:tolower(JID)),
|
LJID = jid:remove_resource(jid:tolower(JID)),
|
||||||
Affiliations = case Affiliation of
|
Affiliations = case Affiliation of
|
||||||
none ->
|
none ->
|
||||||
@ -1275,16 +1292,57 @@ set_affiliation(JID, Affiliation, StateData, Reason) ->
|
|||||||
end,
|
end,
|
||||||
StateData#state{affiliations = Affiliations}.
|
StateData#state{affiliations = Affiliations}.
|
||||||
|
|
||||||
|
-spec set_affiliations(?TDICT, state()) -> state().
|
||||||
|
set_affiliations(Affiliations,
|
||||||
|
#state{config = #config{persistent = false}} = StateData) ->
|
||||||
|
set_affiliations_fallback(Affiliations, StateData);
|
||||||
|
set_affiliations(Affiliations, StateData) ->
|
||||||
|
Room = StateData#state.room,
|
||||||
|
Host = StateData#state.host,
|
||||||
|
ServerHost = StateData#state.server_host,
|
||||||
|
Mod = gen_mod:db_mod(ServerHost, mod_muc),
|
||||||
|
case Mod:set_affiliations(ServerHost, Room, Host, Affiliations) of
|
||||||
|
ok ->
|
||||||
|
StateData;
|
||||||
|
{error, _} ->
|
||||||
|
set_affiliations_fallback(Affiliations, StateData)
|
||||||
|
end.
|
||||||
|
|
||||||
|
-spec set_affiliations_fallback(?TDICT, state()) -> state().
|
||||||
|
set_affiliations_fallback(Affiliations, StateData) ->
|
||||||
|
StateData#state{affiliations = Affiliations}.
|
||||||
|
|
||||||
-spec get_affiliation(jid(), state()) -> affiliation().
|
-spec get_affiliation(jid(), state()) -> affiliation().
|
||||||
get_affiliation(JID, StateData) ->
|
get_affiliation(JID, StateData) ->
|
||||||
{_AccessRoute, _AccessCreate, AccessAdmin,
|
case get_service_affiliation(JID, StateData) of
|
||||||
_AccessPersistent} =
|
owner ->
|
||||||
StateData#state.access,
|
owner;
|
||||||
Res = case acl:match_rule(StateData#state.server_host,
|
none ->
|
||||||
AccessAdmin, JID)
|
case do_get_affiliation(JID, StateData) of
|
||||||
of
|
{Affiliation, _Reason} -> Affiliation;
|
||||||
allow -> owner;
|
Affiliation -> Affiliation
|
||||||
_ ->
|
end
|
||||||
|
end.
|
||||||
|
|
||||||
|
-spec do_get_affiliation(jid(), state()) -> affiliation().
|
||||||
|
do_get_affiliation(JID, #state{config = #config{persistent = false}} = StateData) ->
|
||||||
|
do_get_affiliation_fallback(JID, StateData);
|
||||||
|
do_get_affiliation(JID, StateData) ->
|
||||||
|
Room = StateData#state.room,
|
||||||
|
Host = StateData#state.host,
|
||||||
|
LServer = JID#jid.lserver,
|
||||||
|
LUser = JID#jid.luser,
|
||||||
|
ServerHost = StateData#state.server_host,
|
||||||
|
Mod = gen_mod:db_mod(ServerHost, mod_muc),
|
||||||
|
case Mod:get_affiliation(ServerHost, Room, Host, LUser, LServer) of
|
||||||
|
{error, _} ->
|
||||||
|
do_get_affiliation_fallback(JID, StateData);
|
||||||
|
{ok, Affiliation} ->
|
||||||
|
Affiliation
|
||||||
|
end.
|
||||||
|
|
||||||
|
-spec do_get_affiliation_fallback(jid(), state()) -> affiliation().
|
||||||
|
do_get_affiliation_fallback(JID, StateData) ->
|
||||||
LJID = jid:tolower(JID),
|
LJID = jid:tolower(JID),
|
||||||
case (?DICT):find(LJID, StateData#state.affiliations) of
|
case (?DICT):find(LJID, StateData#state.affiliations) of
|
||||||
{ok, Affiliation} -> Affiliation;
|
{ok, Affiliation} -> Affiliation;
|
||||||
@ -1309,13 +1367,27 @@ get_affiliation(JID, StateData) ->
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
end,
|
|
||||||
case Res of
|
|
||||||
{A, _Reason} -> A;
|
|
||||||
_ -> Res
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
-spec get_affiliations(state()) -> ?TDICT.
|
||||||
|
get_affiliations(#state{config = #config{persistent = false}} = StateData) ->
|
||||||
|
get_affiliations_callback(StateData);
|
||||||
|
get_affiliations(StateData) ->
|
||||||
|
Room = StateData#state.room,
|
||||||
|
Host = StateData#state.host,
|
||||||
|
ServerHost = StateData#state.server_host,
|
||||||
|
Mod = gen_mod:db_mod(ServerHost, mod_muc),
|
||||||
|
case Mod:get_affiliations(ServerHost, Room, Host) of
|
||||||
|
{error, _} ->
|
||||||
|
get_affiliations_callback(StateData);
|
||||||
|
{ok, Affiliations} ->
|
||||||
|
Affiliations
|
||||||
|
end.
|
||||||
|
|
||||||
|
-spec get_affiliations_callback(state()) -> ?TDICT.
|
||||||
|
get_affiliations_callback(StateData) ->
|
||||||
|
StateData#state.affiliations.
|
||||||
|
|
||||||
-spec get_service_affiliation(jid(), state()) -> owner | none.
|
-spec get_service_affiliation(jid(), state()) -> owner | none.
|
||||||
get_service_affiliation(JID, StateData) ->
|
get_service_affiliation(JID, StateData) ->
|
||||||
{_AccessRoute, _AccessCreate, AccessAdmin,
|
{_AccessRoute, _AccessCreate, AccessAdmin,
|
||||||
@ -2600,8 +2672,27 @@ search_role(Role, StateData) ->
|
|||||||
-spec search_affiliation(affiliation(), state()) ->
|
-spec search_affiliation(affiliation(), state()) ->
|
||||||
[{ljid(),
|
[{ljid(),
|
||||||
affiliation() | {affiliation(), binary()}}].
|
affiliation() | {affiliation(), binary()}}].
|
||||||
|
search_affiliation(Affiliation,
|
||||||
|
#state{config = #config{persistent = false}} = StateData) ->
|
||||||
|
search_affiliation_fallback(Affiliation, StateData);
|
||||||
search_affiliation(Affiliation, StateData) ->
|
search_affiliation(Affiliation, StateData) ->
|
||||||
lists:filter(fun ({_, A}) ->
|
Room = StateData#state.room,
|
||||||
|
Host = StateData#state.host,
|
||||||
|
ServerHost = StateData#state.server_host,
|
||||||
|
Mod = gen_mod:db_mod(ServerHost, mod_muc),
|
||||||
|
case Mod:search_affiliation(ServerHost, Room, Host, Affiliation) of
|
||||||
|
{ok, AffiliationList} ->
|
||||||
|
AffiliationList;
|
||||||
|
{error, _} ->
|
||||||
|
search_affiliation_fallback(Affiliation, StateData)
|
||||||
|
end.
|
||||||
|
|
||||||
|
-spec search_affiliation_fallback(affiliation(), state()) ->
|
||||||
|
[{ljid(),
|
||||||
|
affiliation() | {affiliation(), binary()}}].
|
||||||
|
search_affiliation_fallback(Affiliation, StateData) ->
|
||||||
|
lists:filter(
|
||||||
|
fun({_, A}) ->
|
||||||
case A of
|
case A of
|
||||||
{A1, _Reason} -> Affiliation == A1;
|
{A1, _Reason} -> Affiliation == A1;
|
||||||
_ -> Affiliation == A
|
_ -> Affiliation == A
|
||||||
@ -3327,23 +3418,36 @@ set_config(Opts, Config, ServerHost, Lang) ->
|
|||||||
-spec change_config(#config{}, state()) -> {result, undefined, state()}.
|
-spec change_config(#config{}, state()) -> {result, undefined, state()}.
|
||||||
change_config(Config, StateData) ->
|
change_config(Config, StateData) ->
|
||||||
send_config_change_info(Config, StateData),
|
send_config_change_info(Config, StateData),
|
||||||
NSD = remove_subscriptions(StateData#state{config = Config}),
|
StateData0 = StateData#state{config = Config},
|
||||||
|
StateData1 = remove_subscriptions(StateData0),
|
||||||
|
StateData2 =
|
||||||
case {(StateData#state.config)#config.persistent,
|
case {(StateData#state.config)#config.persistent,
|
||||||
Config#config.persistent}
|
Config#config.persistent} of
|
||||||
of
|
{WasPersistent, true} ->
|
||||||
{_, true} ->
|
if not WasPersistent ->
|
||||||
store_room(NSD);
|
set_affiliations(StateData1#state.affiliations,
|
||||||
|
StateData1);
|
||||||
|
true ->
|
||||||
|
ok
|
||||||
|
end,
|
||||||
|
store_room(StateData1),
|
||||||
|
StateData1;
|
||||||
{true, false} ->
|
{true, false} ->
|
||||||
mod_muc:forget_room(NSD#state.server_host,
|
Affiliations = get_affiliations(StateData),
|
||||||
NSD#state.host, NSD#state.room);
|
mod_muc:forget_room(StateData1#state.server_host,
|
||||||
{false, false} -> ok
|
StateData1#state.host,
|
||||||
|
StateData1#state.room),
|
||||||
|
StateData1#state{affiliations = Affiliations};
|
||||||
|
{false, false} ->
|
||||||
|
StateData1
|
||||||
end,
|
end,
|
||||||
case {(StateData#state.config)#config.members_only,
|
case {(StateData#state.config)#config.members_only,
|
||||||
Config#config.members_only}
|
Config#config.members_only} of
|
||||||
of
|
|
||||||
{false, true} ->
|
{false, true} ->
|
||||||
NSD1 = remove_nonmembers(NSD), {result, undefined, NSD1};
|
StateData3 = remove_nonmembers(StateData2),
|
||||||
_ -> {result, undefined, NSD}
|
{result, undefined, StateData3};
|
||||||
|
_ ->
|
||||||
|
{result, undefined, StateData2}
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec send_config_change_info(#config{}, state()) -> ok.
|
-spec send_config_change_info(#config{}, state()) -> ok.
|
||||||
|
Loading…
Reference in New Issue
Block a user