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

Ability to disable all identity server functionality via the config file #2645

Merged
merged 9 commits into from
Aug 14, 2019
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Improvements:
* Reactions: Emoji picker (#2370).
* Widgets: Whitelist https://scalar-staging.vector.im/api (#2612).
* Reactions: Show who reacted (#2591).
* Media picking: Use native camera and use separate actions for camera and media picker (#638).
* Media picking: Use native camera and use separate actions for camera and media picker (#638).
* Ability to disable all identity server functionality via the config file (#2643).

Bug fix:
* Crash when leaving settings due to backup section refresh animation.
Expand Down
2 changes: 1 addition & 1 deletion Riot/Assets/en.lproj/InfoPlist.strings
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
"NSCameraUsageDescription" = "The camera is used to take photos and videos, make video calls.";
"NSPhotoLibraryUsageDescription" = "The photo library is used to send photos and videos.";
"NSMicrophoneUsageDescription" = "The microphone is used to take videos, make calls.";
"NSContactsUsageDescription" = "In order to show you which of your contacts are already using Riot or Matrix, we can send the email addresses and phone numbers in your address book to your Matrix Identity Server. New Vector does not store this data or use it for any other purpose. For more information please see the privacy policy page in application settings.";
"NSContactsUsageDescription" = "In order to show you which of your contacts are already using Riot or Matrix, we can send the email addresses and phone numbers in your address book to your Matrix identity server. New Vector does not store this data or use it for any other purpose. For more information please see the privacy policy page in application settings.";
"NSCalendarsUsageDescription" = "See your scheduled meetings in the app.";

3 changes: 3 additions & 0 deletions Riot/Assets/en.lproj/Vector.strings
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"auth_password_dont_match" = "Passwords don't match";
"auth_username_in_use" = "Username in use";
"auth_forgot_password" = "Forgot password?";
"auth_forgot_password_error_no_configured_identity_server" = "No identity server is configured: add one to reset your password.";
"auth_email_not_found" = "Failed to send email: This email address was not found";
"auth_use_server_options" = "Use custom server options (advanced)";
"auth_email_validation_message" = "Please check your email to continue registration";
Expand Down Expand Up @@ -144,6 +145,7 @@
"room_creation_make_private" = "Make private";
"room_creation_wait_for_creation" = "A room is already being created. Please wait.";
"room_creation_invite_another_user" = "Search / invite by User ID, Name or email";
"room_creation_error_invite_user_by_email_without_identity_server" = "No identity server is configured so you cannot add a participant with an email.";

// Room recents
"room_recents_directory_section" = "ROOM DIRECTORY";
Expand Down Expand Up @@ -218,6 +220,7 @@
"room_participants_invite_malformed_id_title" = "Invite Error";
"room_participants_invite_malformed_id" = "Malformed ID. Should be an email address or a Matrix ID like '@localpart:domain'";
"room_participants_invited_section" = "INVITED";
"room_participants_start_new_chat_error_using_user_email_without_identity_server" = "No identity server is configured so you cannot start a chat with a contact using an email.";

"room_participants_online" = "Online";
"room_participants_offline" = "Offline";
Expand Down
12 changes: 12 additions & 0 deletions Riot/Generated/Strings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ internal enum VectorL10n {
internal static var authForgotPassword: String {
return VectorL10n.tr("Vector", "auth_forgot_password")
}
/// No Identity Server is configured: add one to reset your password.
internal static var authForgotPasswordErrorNoConfiguredIdentityServer: String {
return VectorL10n.tr("Vector", "auth_forgot_password_error_no_configured_identity_server")
}
/// URL (e.g. https://matrix.org)
internal static var authHomeServerPlaceholder: String {
return VectorL10n.tr("Vector", "auth_home_server_placeholder")
Expand Down Expand Up @@ -1498,6 +1502,10 @@ internal enum VectorL10n {
internal static var roomCreationAppearancePicture: String {
return VectorL10n.tr("Vector", "room_creation_appearance_picture")
}
/// No Identity Server is configured so you cannot add a participant with an email.
internal static var roomCreationErrorInviteUserByEmailWithoutIdentityServer: String {
return VectorL10n.tr("Vector", "room_creation_error_invite_user_by_email_without_identity_server")
}
/// Search / invite by User ID, Name or email
internal static var roomCreationInviteAnotherUser: String {
return VectorL10n.tr("Vector", "room_creation_invite_another_user")
Expand Down Expand Up @@ -2118,6 +2126,10 @@ internal enum VectorL10n {
internal static var roomParticipantsRemoveThirdPartyInviteMsg: String {
return VectorL10n.tr("Vector", "room_participants_remove_third_party_invite_msg")
}
/// No Identity Server is configured so you cannot start a chat with a contact using an email.
internal static var roomParticipantsStartNewChatErrorUsingUserEmailWithoutIdentityServer: String {
return VectorL10n.tr("Vector", "room_participants_start_new_chat_error_using_user_email_without_identity_server")
}
/// Participants
internal static var roomParticipantsTitle: String {
return VectorL10n.tr("Vector", "room_participants_title")
Expand Down
46 changes: 39 additions & 7 deletions Riot/Modules/Authentication/AuthenticationViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ @interface AuthenticationViewController ()
MXAutoDiscovery *autoDiscovery;
}

@property (nonatomic, readonly) BOOL isIdentityServerConfigured;

@end

@implementation AuthenticationViewController
Expand Down Expand Up @@ -188,6 +190,11 @@ - (void)userInterfaceThemeDidChange
[forgotPasswordTitle addAttribute:NSForegroundColorAttributeName value:ThemeService.shared.theme.tintColor range:NSMakeRange(0, forgotPasswordTitle.length)];
[self.forgotPasswordButton setAttributedTitle:forgotPasswordTitle forState:UIControlStateNormal];
[self.forgotPasswordButton setAttributedTitle:forgotPasswordTitle forState:UIControlStateHighlighted];

NSMutableAttributedString *forgotPasswordTitleDisabled = [[NSMutableAttributedString alloc] initWithAttributedString:forgotPasswordTitle];
[forgotPasswordTitleDisabled addAttribute:NSForegroundColorAttributeName value:[ThemeService.shared.theme.tintColor colorWithAlphaComponent:0.3] range:NSMakeRange(0, forgotPasswordTitle.length)];
[self.forgotPasswordButton setAttributedTitle:forgotPasswordTitleDisabled forState:UIControlStateDisabled];

[self updateForgotPwdButtonVisibility];

NSAttributedString *serverOptionsTitle = [[NSAttributedString alloc] initWithString:NSLocalizedStringFromTable(@"auth_use_server_options", @"Vector", nil) attributes:@{NSForegroundColorAttributeName : ThemeService.shared.theme.textSecondaryColor, NSFontAttributeName: [UIFont systemFontOfSize:14]}];
Expand Down Expand Up @@ -256,6 +263,11 @@ - (void)destroy
autoDiscovery = nil;
}

- (BOOL)isIdentityServerConfigured
{
return self.identityServerTextField.text.length > 0;
}

- (void)setAuthType:(MXKAuthenticationType)authType
{
if (self.authType == MXKAuthenticationTypeRegister)
Expand Down Expand Up @@ -533,8 +545,21 @@ - (IBAction)onButtonPressed:(id)sender
}
else if (sender == self.forgotPasswordButton)
{
// Update UI to reset password
self.authType = MXKAuthenticationTypeForgotPassword;
if (!self.isIdentityServerConfigured)
{
UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSBundle mxk_localizedStringForKey:@"error"]
message:NSLocalizedStringFromTable(@"auth_forgot_password_error_no_configured_identity_server", @"Vector", nil)
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:YES completion:nil];

return;
}
else
{
// Update UI to reset password
self.authType = MXKAuthenticationTypeForgotPassword;
}
}
else if (sender == self.rightBarButtonItem)
{
Expand Down Expand Up @@ -609,11 +634,18 @@ - (IBAction)onButtonPressed:(id)sender
else
{
[self.authenticationActivityIndicator stopAnimating];

// Show the supported 3rd party ids which may be added to the account
authInputsview.thirdPartyIdentifiersHidden = NO;

[self updateRegistrationScreenWithThirdPartyIdentifiersHidden:NO];

if (self.isIdentityServerConfigured)
{
// Show the supported 3rd party ids which may be added to the account
authInputsview.thirdPartyIdentifiersHidden = NO;
[self updateRegistrationScreenWithThirdPartyIdentifiersHidden:NO];
}
else
{
// Do not propose to add 3rd party ids if there is no configured identity server
[super onButtonPressed:sender];
}
}
}];
}
Expand Down
11 changes: 7 additions & 4 deletions Riot/Modules/Contacts/Details/ContactDetailsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1011,10 +1011,13 @@ - (void)onActionButtonPressed:(id)sender
// The identity server must be defined
if (!self.mainSession.matrixRestClient.identityServer)
{
MXError *error = [[MXError alloc] initWithErrorCode:kMXSDKErrCodeStringMissingParameters error:@"No supplied identity server URL"];
NSLog(@"[ContactDetailsViewController] Invite %@ failed", participantId);
// Alert user
[[AppDelegate theDelegate] showErrorAsAlert:[error createNSError]];
[self removePendingActionMask];

UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSBundle mxk_localizedStringForKey:@"error"]
message:NSLocalizedStringFromTable(@"room_participants_start_new_chat_error_using_user_email_without_identity_server", @"Vector", nil)
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:YES completion:nil];

return;
}
Expand Down
29 changes: 21 additions & 8 deletions Riot/Modules/Settings/SettingsViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -1220,22 +1220,35 @@ - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger
else if (section == SETTINGS_SECTION_USER_SETTINGS_INDEX)
{
MXKAccount* account = [MXKAccountManager sharedManager].activeAccounts.firstObject;

userSettingsProfilePictureIndex = 0;
userSettingsDisplayNameIndex = 1;
userSettingsChangePasswordIndex = 2;
userSettingsEmailStartIndex = 3;
userSettingsNewEmailIndex = userSettingsEmailStartIndex + account.linkedEmails.count;
userSettingsPhoneStartIndex = userSettingsNewEmailIndex + 1;
userSettingsNewPhoneIndex = userSettingsPhoneStartIndex + account.linkedPhoneNumbers.count;


// Hide some unsupported account settings
userSettingsFirstNameIndex = -1;
userSettingsSurnameIndex = -1;
userSettingsNightModeSepIndex = -1;
userSettingsNightModeIndex = -1;

count = userSettingsNewPhoneIndex + 1;

if (self.mainSession.matrixRestClient.identityServer.length)
{
userSettingsEmailStartIndex = 3;
userSettingsNewEmailIndex = userSettingsEmailStartIndex + account.linkedEmails.count;
userSettingsPhoneStartIndex = userSettingsNewEmailIndex + 1;
userSettingsNewPhoneIndex = userSettingsPhoneStartIndex + account.linkedPhoneNumbers.count;

count = userSettingsNewPhoneIndex + 1;
}
else
{
userSettingsEmailStartIndex = -1;
userSettingsNewEmailIndex = -1;
userSettingsPhoneStartIndex = -1;
userSettingsNewPhoneIndex = -1;

count = userSettingsChangePasswordIndex + 1;
}
}
else if (section == SETTINGS_SECTION_NOTIFICATIONS_SETTINGS_INDEX)
{
Expand Down
9 changes: 1 addition & 8 deletions Riot/Modules/StartChat/StartChatViewController.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@
/**
'StartChatViewController' instance is used to prepare new room creation.
*/
@interface StartChatViewController : ContactsTableViewController <UITableViewDataSource, UISearchBarDelegate, ContactsTableViewControllerDelegate>

@property (weak, nonatomic) IBOutlet UIView *searchBarHeader;
@property (weak, nonatomic) IBOutlet UISearchBar *searchBarView;
@property (weak, nonatomic) IBOutlet UIView *searchBarHeaderBorder;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *searchBarTopConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewBottomConstraint;
@interface StartChatViewController : ContactsTableViewController

/**
Tell whether a search session is in progress
Expand Down
45 changes: 40 additions & 5 deletions Riot/Modules/StartChat/StartChatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#import "AppDelegate.h"
#import "Riot-Swift.h"

@interface StartChatViewController ()
@interface StartChatViewController () <UITableViewDataSource, UISearchBarDelegate, ContactsTableViewControllerDelegate>
{
// The contact used to describe the current user.
MXKContact *userContact;
Expand All @@ -42,6 +42,13 @@ @interface StartChatViewController ()
NSMutableDictionary <NSString*, NSNumber*> *isMultiUseNameByDisplayName;
}

@property (weak, nonatomic) IBOutlet UIView *searchBarHeader;
@property (weak, nonatomic) IBOutlet UISearchBar *searchBarView;
@property (weak, nonatomic) IBOutlet UIView *searchBarHeaderBorder;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *searchBarTopConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *tableViewBottomConstraint;

@end

@implementation StartChatViewController
Expand Down Expand Up @@ -522,11 +529,7 @@ - (IBAction)onButtonPressed:(id)sender
// The identity server must be defined
if (!self.mainSession.matrixRestClient.identityServer)
{
MXError *error = [[MXError alloc] initWithErrorCode:kMXSDKErrCodeStringMissingParameters error:@"No supplied identity server URL"];
NSLog(@"[StartChatViewController] Invite %@ failed", participantId);
// Alert user
[[AppDelegate theDelegate] showErrorAsAlert:[error createNSError]];

continue;
}

Expand Down Expand Up @@ -681,6 +684,38 @@ - (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar

- (void)contactsTableViewController:(ContactsTableViewController *)contactsTableViewController didSelectContact:(MXKContact*)contact
{
// If contact has only an email the identity server must be defined
if (!self.mainSession.matrixRestClient.identityServer && contact.matrixIdentifiers.count == 0)
{
NSString *participantId;

if (contact.emailAddresses.count)
{
MXKEmail *email = contact.emailAddresses.firstObject;
participantId = email.emailAddress;
}
else
{
// This is the text filled by the user.
participantId = contact.displayName;
}

if ([MXTools isEmailAddress:participantId])
{
NSLog(@"[StartChatViewController] No identity server is configured, do not add participant with email");

[contactsTableViewController refreshCurrentSelectedCell:YES];

UIAlertController *alert = [UIAlertController alertControllerWithTitle:[NSBundle mxk_localizedStringForKey:@"error"]
message:NSLocalizedStringFromTable(@"room_creation_error_invite_user_by_email_without_identity_server", @"Vector", nil)
preferredStyle:UIAlertControllerStyleAlert];
[alert addAction:[UIAlertAction actionWithTitle:[NSBundle mxk_localizedStringForKey:@"ok"] style:UIAlertActionStyleDefault handler:nil]];
[self presentViewController:alert animated:YES completion:nil];

return;
}
}

if (contact)
{
// Update here the mutable list of participants
Expand Down