Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make federated users on proteus selectable in certain situations [WPB-14458] #18427

Merged
merged 2 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading