* Add guest invites * Fix tests and address copilot feedback * Fix test * Add magic link changes
59 lines
2.4 KiB
TypeScript
59 lines
2.4 KiB
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
import {withDatabase, withObservables} from '@nozbe/watermelondb/react';
|
|
import {combineLatest, of as of$} from 'rxjs';
|
|
import {switchMap, distinctUntilChanged, map} from 'rxjs/operators';
|
|
|
|
import {Permissions} from '@constants';
|
|
import {observePermissionForTeam} from '@queries/servers/role';
|
|
import {observeConfigBooleanValue} from '@queries/servers/system';
|
|
import {observeCurrentTeam} from '@queries/servers/team';
|
|
import {observeTeammateNameDisplay, observeCurrentUser} from '@queries/servers/user';
|
|
import {isSystemAdmin} from '@utils/user';
|
|
|
|
import Invite from './invite';
|
|
|
|
import type {WithDatabaseArgs} from '@typings/database/database';
|
|
|
|
const enhanced = withObservables([], ({database}: WithDatabaseArgs) => {
|
|
const team = observeCurrentTeam(database);
|
|
const currentUser = observeCurrentUser(database);
|
|
|
|
const guestAccountsEnabled = observeConfigBooleanValue(database, 'EnableGuestAccounts');
|
|
const emailInvitationsEnabled = observeConfigBooleanValue(database, 'EnableEmailInvitations');
|
|
const isGroupConstrained = team.pipe(
|
|
switchMap((t) => of$(Boolean(t?.isGroupConstrained))),
|
|
);
|
|
const hasPermissionToInviteGuests = combineLatest([team, currentUser]).pipe(
|
|
switchMap(([t, u]) => observePermissionForTeam(database, t, u, Permissions.INVITE_GUEST, false)),
|
|
);
|
|
const canInviteGuests = combineLatest([isGroupConstrained, guestAccountsEnabled, hasPermissionToInviteGuests]).pipe(
|
|
switchMap(([group, enabled, permission]) => of$(!group && enabled && permission)),
|
|
);
|
|
|
|
return {
|
|
teamId: team.pipe(
|
|
switchMap((t) => of$(t?.id)),
|
|
),
|
|
teamDisplayName: team.pipe(
|
|
switchMap((t) => of$(t?.displayName)),
|
|
),
|
|
teamLastIconUpdate: team.pipe(
|
|
switchMap((t) => of$(t?.lastTeamIconUpdatedAt)),
|
|
),
|
|
teamInviteId: team.pipe(
|
|
switchMap((t) => of$(t?.inviteId)),
|
|
),
|
|
teammateNameDisplay: observeTeammateNameDisplay(database),
|
|
isAdmin: observeCurrentUser(database).pipe(
|
|
map((user) => isSystemAdmin(user?.roles || '')),
|
|
distinctUntilChanged(),
|
|
),
|
|
emailInvitationsEnabled,
|
|
canInviteGuests,
|
|
allowGuestMagicLink: observeConfigBooleanValue(database, 'EnableGuestMagicLink'),
|
|
};
|
|
});
|
|
|
|
export default withDatabase(enhanced(Invite));
|