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

Rename SyncUser::identity() to SyncUser::user_id() #7267

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

### Breaking changes
* `App::get_uncached_app(...)` and `App::get_shared_app(...)` have been replaced by `App::get_app(App::CacheMode, ...)`. The App constructor is now enforced to be unusable, use `App::get_app()` instead. ([#7237](https://github.com/realm/realm-core/issues/7237))
* Rename `SyncUser::identity()` and friends to `SyncUser::user_id()`. `SyncUser` used the word "identity" for two separate concepts and had both `identity()` and `identities()` which did unrelated things.

### Compatibility
* Fileformat: Generates files with format v23. Reads and automatically upgrade from fileformat v5.
Expand Down
3 changes: 1 addition & 2 deletions bindgen/spec.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1139,9 +1139,8 @@ classes:
properties:
all_sessions: std::vector<SharedSyncSession>
is_logged_in: bool
identity: const std::string&
user_id: const std::string&
provider_type: const std::string&
local_identity: const std::string&
access_token: std::string
refresh_token: std::string
device_id: std::string
Expand Down
6 changes: 3 additions & 3 deletions src/realm.h
Original file line number Diff line number Diff line change
Expand Up @@ -3278,11 +3278,11 @@ RLM_API void realm_app_sync_client_wait_for_sessions_to_terminate(realm_app_t*)
RLM_API char* realm_app_sync_client_get_default_file_path_for_realm(const realm_sync_config_t*,
const char* custom_filename);
/**
* Return the identiy for the user passed as argument
* Return the unique user id for the user passed as argument
* @param user ptr to the user for which the identiy has to be retrieved
* @return a ptr to the identity string
* @return a ptr to the user id string
*/
RLM_API const char* realm_user_get_identity(const realm_user_t* user) RLM_API_NOEXCEPT;
RLM_API const char* realm_user_get_id(const realm_user_t* user) RLM_API_NOEXCEPT;

/**
* Retrieve the state for the user passed as argument
Expand Down
7 changes: 3 additions & 4 deletions src/realm/object-store/audit.mm
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ explicit AuditRealmPool(Private, std::shared_ptr<SyncUser> user, std::string con
ErrorHandler error_handler) NO_THREAD_SAFETY_ANALYSIS
{
struct CachedPool {
std::string user_identity;
std::string user_id;
std::string partition_prefix;
std::string app_id;
std::weak_ptr<AuditRealmPool> pool;
Expand All @@ -685,8 +685,7 @@ explicit AuditRealmPool(Private, std::shared_ptr<SyncUser> user, std::string con

auto app_id = user->app().lock()->config().app_id;
auto it = std::find_if(s_pools.begin(), s_pools.end(), [&](auto& pool) {
return pool.user_identity == user->identity() && pool.partition_prefix == partition_prefix &&
pool.app_id == app_id;
return pool.user_id == user->user_id() && pool.partition_prefix == partition_prefix && pool.app_id == app_id;
});
if (it != s_pools.end()) {
if (auto pool = it->pool.lock()) {
Expand All @@ -696,7 +695,7 @@ explicit AuditRealmPool(Private, std::shared_ptr<SyncUser> user, std::string con

auto pool = std::make_shared<AuditRealmPool>(Private(), user, partition_prefix, error_handler, logger, app_id);
pool->scan_for_realms_to_upload();
s_pools.push_back({user->identity(), partition_prefix, app_id, pool});
s_pools.push_back({user->user_id(), partition_prefix, app_id, pool});
return pool;
}

Expand Down
4 changes: 2 additions & 2 deletions src/realm/object-store/c_api/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,9 +659,9 @@ RLM_API char* realm_app_sync_client_get_default_file_path_for_realm(const realm_
});
}

RLM_API const char* realm_user_get_identity(const realm_user_t* user) noexcept
RLM_API const char* realm_user_get_id(const realm_user_t* user) noexcept
{
return (*user)->identity().c_str();
return (*user)->user_id().c_str();
}

RLM_API realm_user_state_e realm_user_get_state(const realm_user_t* user) noexcept
Expand Down
12 changes: 6 additions & 6 deletions src/realm/object-store/sync/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ void App::get_profile(const std::shared_ptr<SyncUser>& sync_user,

sync_user->update_user_profile(std::move(identities),
SyncUserProfile(get<BsonDocument>(profile_json, "data")));
self->m_app_backing_store->set_current_user(sync_user->identity());
self->m_app_backing_store->set_current_user(sync_user->user_id());
self->emit_change_to_subscribers(*self);
}
catch (const AppError& err) {
Expand Down Expand Up @@ -807,7 +807,7 @@ std::shared_ptr<SyncUser> App::switch_user(const std::shared_ptr<SyncUser>& user
throw AppError(ErrorCodes::ClientUserNotFound, "User does not exist");
}

m_app_backing_store->set_current_user(user->identity());
m_app_backing_store->set_current_user(user->user_id());
emit_change_to_subscribers(*this);
return current_user();
}
Expand All @@ -824,12 +824,12 @@ void App::remove_user(const std::shared_ptr<SyncUser>& user, UniqueFunction<void
if (user->is_logged_in()) {
log_out(user, [user, completion = std::move(completion),
self = shared_from_this()](const Optional<AppError>& error) {
self->m_app_backing_store->remove_user(user->identity());
self->m_app_backing_store->remove_user(user->user_id());
return completion(error);
});
}
else {
m_app_backing_store->remove_user(user->identity());
m_app_backing_store->remove_user(user->user_id());
return completion({});
}
}
Expand All @@ -853,11 +853,11 @@ void App::delete_user(const std::shared_ptr<SyncUser>& user, UniqueFunction<void
req.url = url_for_path("/auth/delete");
do_authenticated_request(std::move(req), user,
[self = shared_from_this(), completion = std::move(completion),
identitiy = user->identity()](const Response& response) {
user_id = user->user_id()](const Response& response) {
auto error = AppUtils::check_for_errors(response);
if (!error) {
self->emit_change_to_subscribers(*self);
self->m_app_backing_store->delete_user(identitiy);
self->m_app_backing_store->delete_user(user_id);
}
completion(error);
});
Expand Down
39 changes: 18 additions & 21 deletions src/realm/object-store/sync/impl/sync_file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,21 +253,21 @@ std::string SyncFileManager::get_special_directory(std::string directory_name) c
return dir_path;
}

std::string SyncFileManager::user_directory(const std::string& user_identity) const
std::string SyncFileManager::user_directory(const std::string& user_id) const
{
std::string user_path = get_user_directory_path(user_identity);
std::string user_path = get_user_directory_path(user_id);
util::try_make_dir(user_path);
return user_path;
}

void SyncFileManager::remove_user_realms(const std::string& user_identity,
void SyncFileManager::remove_user_realms(const std::string& user_id,
const std::vector<std::string>& realm_paths) const
{
for (auto& path : realm_paths) {
remove_realm(path);
}
// The following is redundant except for apps built before file tracking.
std::string user_path = get_user_directory_path(user_identity);
std::string user_path = get_user_directory_path(user_id);
util::try_remove_dir_recursive(user_path);
}

Expand Down Expand Up @@ -300,11 +300,10 @@ bool SyncFileManager::copy_realm_file(const std::string& old_path, const std::st
return true;
}

bool SyncFileManager::remove_realm(const std::string& user_identity,
const std::vector<std::string>& legacy_user_identities,
bool SyncFileManager::remove_realm(const std::string& user_id, const std::vector<std::string>& legacy_user_identities,
const std::string& raw_realm_path, const std::string& partition) const
{
auto existing = get_existing_realm_file_path(user_identity, legacy_user_identities, raw_realm_path, partition);
auto existing = get_existing_realm_file_path(user_id, legacy_user_identities, raw_realm_path, partition);
if (existing) {
return remove_realm(*existing);
}
Expand Down Expand Up @@ -333,11 +332,11 @@ static bool try_file_remove(const std::string& path) noexcept
}

util::Optional<std::string>
SyncFileManager::get_existing_realm_file_path(const std::string& user_identity,
SyncFileManager::get_existing_realm_file_path(const std::string& user_id,
const std::vector<std::string>& legacy_user_identities,
const std::string& realm_file_name, const std::string& partition) const
{
std::string preferred_name_without_suffix = preferred_realm_path_without_suffix(user_identity, realm_file_name);
std::string preferred_name_without_suffix = preferred_realm_path_without_suffix(user_id, realm_file_name);
if (try_file_exists(preferred_name_without_suffix)) {
return preferred_name_without_suffix;
}
Expand All @@ -364,7 +363,7 @@ SyncFileManager::get_existing_realm_file_path(const std::string& user_identity,
// We used to hash the string value of the partition. For compatibility, check that SHA256
// hash file name exists, and if it does, continue to use it.
if (!partition.empty()) {
std::string hashed_partition_path = legacy_hashed_partition_path(user_identity, partition);
std::string hashed_partition_path = legacy_hashed_partition_path(user_id, partition);
if (try_file_exists(hashed_partition_path)) {
return hashed_partition_path;
}
Expand All @@ -386,20 +385,19 @@ SyncFileManager::get_existing_realm_file_path(const std::string& user_identity,
return util::none;
}

std::string SyncFileManager::realm_file_path(const std::string& user_identity,
std::string SyncFileManager::realm_file_path(const std::string& user_id,
const std::vector<std::string>& legacy_user_identities,
const std::string& realm_file_name, const std::string& partition) const
{
auto existing_path =
get_existing_realm_file_path(user_identity, legacy_user_identities, realm_file_name, partition);
auto existing_path = get_existing_realm_file_path(user_id, legacy_user_identities, realm_file_name, partition);
if (existing_path) {
return *existing_path;
}

// since this appears to be a new file, test the normal location
// we use a test file with the same name and a suffix of the
// same length, so we can catch "filename too long" errors on windows
std::string preferred_name_without_suffix = preferred_realm_path_without_suffix(user_identity, realm_file_name);
std::string preferred_name_without_suffix = preferred_realm_path_without_suffix(user_id, realm_file_name);
std::string preferred_name_with_suffix = preferred_name_without_suffix + c_realm_file_suffix;
try {
std::string test_path = preferred_name_without_suffix + c_realm_file_test_suffix;
Expand Down Expand Up @@ -455,12 +453,11 @@ bool SyncFileManager::remove_metadata_realm() const
}
}

std::string SyncFileManager::preferred_realm_path_without_suffix(const std::string& user_identity,
std::string SyncFileManager::preferred_realm_path_without_suffix(const std::string& user_id,
const std::string& realm_file_name) const
{
auto escaped_file_name = util::validate_and_clean_path(realm_file_name);
std::string preferred_name =
util::file_path_by_appending_component(user_directory(user_identity), escaped_file_name);
std::string preferred_name = util::file_path_by_appending_component(user_directory(user_id), escaped_file_name);
if (StringData(preferred_name).ends_with(c_realm_file_suffix)) {
preferred_name = preferred_name.substr(0, preferred_name.size() - strlen(c_realm_file_suffix));
}
Expand All @@ -476,14 +473,14 @@ std::string SyncFileManager::fallback_hashed_realm_file_path(const std::string&
return hashed_name;
}

std::string SyncFileManager::legacy_hashed_partition_path(const std::string& user_identity,
std::string SyncFileManager::legacy_hashed_partition_path(const std::string& user_id,
const std::string& partition) const
{
std::array<unsigned char, 32> hash;
util::sha256(partition.data(), partition.size(), hash.data());
std::string legacy_hashed_file_name = util::hex_dump(hash.data(), hash.size(), "");
std::string legacy_partition_path = util::file_path_by_appending_component(
get_user_directory_path(user_identity), legacy_hashed_file_name + c_realm_file_suffix);
get_user_directory_path(user_id), legacy_hashed_file_name + c_realm_file_suffix);
return legacy_partition_path;
}

Expand All @@ -509,9 +506,9 @@ std::string SyncFileManager::legacy_local_identity_path(const std::string& local
return path;
}

std::string SyncFileManager::get_user_directory_path(const std::string& user_identity) const
std::string SyncFileManager::get_user_directory_path(const std::string& user_id) const
{
return file_path_by_appending_component(m_app_path, util::validate_and_clean_path(user_identity),
return file_path_by_appending_component(m_app_path, util::validate_and_clean_path(user_id),
util::FilePathType::Directory);
}

Expand Down
17 changes: 8 additions & 9 deletions src/realm/object-store/sync/impl/sync_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,23 @@ class SyncFileManager {
SyncFileManager(const std::string& base_path, const std::string& app_id);

/// Remove the Realms at the specified absolute paths along with any associated helper files.
void remove_user_realms(const std::string& user_identity,
void remove_user_realms(const std::string& user_id,
const std::vector<std::string>& realm_paths) const; // throws

/// A non throw version of File::exists(), returning false if any exceptions are thrown when attempting to access
/// this file.
static bool try_file_exists(const std::string& path) noexcept;

util::Optional<std::string> get_existing_realm_file_path(const std::string& user_identity,
util::Optional<std::string> get_existing_realm_file_path(const std::string& user_id,
const std::vector<std::string>& legacy_user_identities,
const std::string& realm_file_name,
const std::string& partition) const;
/// Return the path for a given Realm, creating the user directory if it does not already exist.
std::string realm_file_path(const std::string& user_identity,
const std::vector<std::string>& legacy_user_identities,
std::string realm_file_path(const std::string& user_id, const std::vector<std::string>& legacy_user_identities,
const std::string& realm_file_name, const std::string& partition) const;

/// Remove the Realm at a given path for a given user. Returns `true` if the remove operation fully succeeds.
bool remove_realm(const std::string& user_identity, const std::vector<std::string>& legacy_user_identities,
bool remove_realm(const std::string& user_id, const std::vector<std::string>& legacy_user_identities,
const std::string& realm_file_name, const std::string& partition) const;

/// Remove the Realm whose primary Realm file is located at `absolute_path`. Returns `true` if the remove
Expand Down Expand Up @@ -134,15 +133,15 @@ class SyncFileManager {
return get_special_directory(c_utility_directory);
}
/// Return the user directory for a given user, creating it if it does not already exist.
std::string user_directory(const std::string& identity) const;
std::string user_directory(const std::string& user_id) const;
// Construct the absolute path to the users directory
std::string get_user_directory_path(const std::string& user_identity) const;
std::string legacy_hashed_partition_path(const std::string& user_identity, const std::string& partition) const;
std::string get_user_directory_path(const std::string& user_id) const;
std::string legacy_hashed_partition_path(const std::string& user_id, const std::string& partition) const;
std::string legacy_realm_file_path(const std::string& local_user_identity,
const std::string& realm_file_name) const;
std::string legacy_local_identity_path(const std::string& local_user_identity,
const std::string& realm_file_name) const;
std::string preferred_realm_path_without_suffix(const std::string& user_identity,
std::string preferred_realm_path_without_suffix(const std::string& user_id,
const std::string& realm_file_name) const;
std::string fallback_hashed_realm_file_path(const std::string& preferred_path) const;
};
Expand Down
Loading