Skip to content

Commit

Permalink
fix: make federated users on proteus selectable in certain situations…
Browse files Browse the repository at this point in the history
… [WPB-14458] (#18427)

* fix: make federated users on proteus selectable in certain situations

* fix: comments
  • Loading branch information
aweiss-dev authored Dec 5, 2024
1 parent d0ad643 commit 60e8e74
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
10 changes: 7 additions & 3 deletions src/script/components/UserSearchableList/UserSearchableList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const UserSearchableList = ({
// We shouldn't show any members that have the 'external' role and are not already locally known.
const nonExternalMembers = await teamRepository.filterExternals(uniqueMembers);
setRemoteTeamMembers(
filterRemoteTeamUsers ? teamRepository.filterRemoteDomainUsers(nonExternalMembers) : nonExternalMembers,
filterRemoteTeamUsers ? await teamRepository.filterRemoteDomainUsers(nonExternalMembers) : nonExternalMembers,
);
}, 300),
[],
Expand All @@ -103,6 +103,10 @@ export const UserSearchableList = ({
// Filter all list items if a filter is provided

useEffect(() => {
const setUsers = async (users: User[]) => {
setFilteredUsers(filterRemoteTeamUsers ? await teamRepository.filterRemoteDomainUsers(users) : users);
};

const {query: normalizedQuery} = searchRepository.normalizeQuery(filter);
const results = searchRepository
.searchUserInSet(filter, users)
Expand All @@ -119,15 +123,15 @@ export const UserSearchableList = ({
}

if (!selfFirst) {
setFilteredUsers(filterRemoteTeamUsers ? teamRepository.filterRemoteDomainUsers(results) : results);
void setUsers(results);
return;
}

// make sure the self user is the first one in the list
const [selfUser, otherUsers] = partition(results, user => user.isMe);

const concatUsers = selfUser.concat(otherUsers);
setFilteredUsers(filterRemoteTeamUsers ? teamRepository.filterRemoteDomainUsers(concatUsers) : concatUsers);
void setUsers(concatUsers);
}, [filter, users.length]);

const foundUserEntities = () => {
Expand Down
19 changes: 18 additions & 1 deletion src/script/team/TeamRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {NOTIFICATION_HANDLING_STATE} from '../event/NotificationHandlingState';
import {IntegrationMapper} from '../integration/IntegrationMapper';
import {ServiceEntity} from '../integration/ServiceEntity';
import {MLSMigrationStatus, getMLSMigrationStatus} from '../mls/MLSMigration/migrationStatus';
import {APIClient} from '../service/APIClientSingleton';
import {ROLE, ROLE as TEAM_ROLE, roleFromTeamPermissions} from '../user/UserPermission';
import {UserRepository} from '../user/UserRepository';
import {UserState} from '../user/UserState';
Expand All @@ -82,6 +83,7 @@ export class TeamRepository extends TypedEventEmitter<Events> {
private readonly teamMapper: TeamMapper;
private readonly userRepository: UserRepository;
private readonly assetRepository: AssetRepository;
private backendSupportsMLS: boolean | null = null;

constructor(
userRepository: UserRepository,
Expand Down Expand Up @@ -236,13 +238,28 @@ export class TeamRepository extends TypedEventEmitter<Events> {
await this.updateTeamMembersByIds(selfTeamId, newTeamMemberIds, true);
};

filterRemoteDomainUsers(users: User[]): User[] {
public async filterRemoteDomainUsers(users: User[]): Promise<User[]> {
const isMLS = this.teamState.teamFeatures()?.mls?.config.defaultProtocol === ConversationProtocol.MLS;

// IF MLS is enabled, THEN return all users
if (isMLS) {
return users;
}

const domain = this.userState.self()?.domain ?? this.teamState.teamDomain();
const hasFederatedUsers = users.some(user => user.domain !== domain);

if (this.backendSupportsMLS === null) {
const apiClient = container.resolve(APIClient);
this.backendSupportsMLS = await apiClient.supportsMLS();
}

// IF the backend does not support MLS, AND there are federated users, THEN return all users
if (!this.backendSupportsMLS && hasFederatedUsers) {
return users;
}

// IF the backend supports MLS, AND we use the proteus protocol, THEN filter out federated users
return users.filter(user => {
if (user.domain !== domain) {
this.logger.log(`Filtering out user ${user.id} because of domain mismatch, current protocol is not MLS`);
Expand Down

0 comments on commit 60e8e74

Please sign in to comment.