|
@@ -282,6 +282,12 @@ nlohmann::json CredentialMetadata::toJson() const {
|
|
|
{"createdBy", created_by},
|
|
{"createdBy", created_by},
|
|
|
{"allowedWorkflows", allowed_workflows}
|
|
{"allowedWorkflows", allowed_workflows}
|
|
|
};
|
|
};
|
|
|
|
|
+ // Only written once a transfer has actually happened. Writing it
|
|
|
|
|
+ // unconditionally - even as a copy of created_by - would quietly migrate
|
|
|
|
|
+ // every legacy credential the first time anything else about it changed.
|
|
|
|
|
+ if (!owner_id.empty()) {
|
|
|
|
|
+ j["ownerId"] = owner_id;
|
|
|
|
|
+ }
|
|
|
if (!public_data.is_null() && !public_data.empty()) {
|
|
if (!public_data.is_null() && !public_data.empty()) {
|
|
|
j["publicData"] = public_data;
|
|
j["publicData"] = public_data;
|
|
|
}
|
|
}
|
|
@@ -305,6 +311,11 @@ CredentialMetadata CredentialMetadata::fromJson(const nlohmann::json& j) {
|
|
|
meta.description = j.value("description", "");
|
|
meta.description = j.value("description", "");
|
|
|
meta.type = credentialTypeFromString(j.value("type", "basic"));
|
|
meta.type = credentialTypeFromString(j.value("type", "basic"));
|
|
|
meta.created_by = j.value("createdBy", j.value("created_by", ""));
|
|
meta.created_by = j.value("createdBy", j.value("created_by", ""));
|
|
|
|
|
+ // Raw, not resolved: stays empty for a credential nobody has transferred
|
|
|
|
|
+ // yet. Callers that want the effective owner of a possibly-legacy
|
|
|
|
|
+ // credential fall back to created_by themselves, the way
|
|
|
|
|
+ // CredentialInfo::fromMetadata does for the API response.
|
|
|
|
|
+ meta.owner_id = j.value("ownerId", "");
|
|
|
meta.declared_type = j.value("declaredType", "");
|
|
meta.declared_type = j.value("declaredType", "");
|
|
|
meta.project_id = j.value("projectId", "");
|
|
meta.project_id = j.value("projectId", "");
|
|
|
if (j.contains("sharedWith") && j["sharedWith"].is_array()) {
|
|
if (j.contains("sharedWith") && j["sharedWith"].is_array()) {
|
|
@@ -355,6 +366,9 @@ nlohmann::json CredentialInfo::toJson() const {
|
|
|
{"description", description},
|
|
{"description", description},
|
|
|
{"type", credentialTypeToString(type)},
|
|
{"type", credentialTypeToString(type)},
|
|
|
{"createdBy", created_by},
|
|
{"createdBy", created_by},
|
|
|
|
|
+ // Always resolved by fromMetadata - equal to created_by until the
|
|
|
|
|
+ // credential has been transferred, the transferred-to user id after.
|
|
|
|
|
+ {"ownerId", owner_id},
|
|
|
{"createdAt", created_at},
|
|
{"createdAt", created_at},
|
|
|
{"updatedAt", updated_at},
|
|
{"updatedAt", updated_at},
|
|
|
{"allowedWorkflows", allowed_workflows}
|
|
{"allowedWorkflows", allowed_workflows}
|
|
@@ -379,6 +393,9 @@ CredentialInfo CredentialInfo::fromMetadata(const CredentialMetadata& metadata)
|
|
|
info.description = metadata.description;
|
|
info.description = metadata.description;
|
|
|
info.type = metadata.type;
|
|
info.type = metadata.type;
|
|
|
info.created_by = metadata.created_by;
|
|
info.created_by = metadata.created_by;
|
|
|
|
|
+ // The fallback a legacy credential needs: no transfer has ever written
|
|
|
|
|
+ // ownerId for it, so its owner is still whoever created it.
|
|
|
|
|
+ info.owner_id = metadata.owner_id.empty() ? metadata.created_by : metadata.owner_id;
|
|
|
info.created_at = metadata.created_at;
|
|
info.created_at = metadata.created_at;
|
|
|
info.updated_at = metadata.updated_at;
|
|
info.updated_at = metadata.updated_at;
|
|
|
info.allowed_workflows = metadata.allowed_workflows;
|
|
info.allowed_workflows = metadata.allowed_workflows;
|