Skip to content
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 @@ -485,6 +485,7 @@ public async Task<IRpcMethodResult> DeleteRequest(string requestId)
/// Gets basic project metadata by Paratext ID. Only accessible to Serval admins.
/// Note: This is intended for external use by the onboarding script, not internal Scripture Forge use.
/// </summary>
[Obsolete("Use GetProjectMetadata with either paratextId or scriptureForgeId instead for more flexible querying")]
public async Task<IRpcMethodResult> GetProjectMetadataByParatextId(string paratextId)
{
try
Expand Down Expand Up @@ -533,4 +534,66 @@ public async Task<IRpcMethodResult> GetProjectMetadataByParatextId(string parate
throw;
}
}

/// <summary>
/// Gets basic project metadata by Paratext ID or Scripture Forge project ID. Only accessible to Serval admins.
/// Caller must provide exactly one identifier.
/// Note: This is intended for external use by the onboarding script, not internal Scripture Forge use.
/// </summary>
public async Task<IRpcMethodResult> GetProjectMetadata(string? paratextId = null, string? scriptureForgeId = null)
{
try
{
// Check if user is a Serval admin
if (!SystemRoles.Contains(SystemRole.ServalAdmin))
{
return ForbiddenError();
}

bool hasParatextId = !string.IsNullOrEmpty(paratextId);
bool hasScriptureForgeId = !string.IsNullOrEmpty(scriptureForgeId);
if (hasParatextId == hasScriptureForgeId)
{
return InvalidParamsError("Provide exactly one of: paratextId or scriptureForgeId");
}

IQueryable<SFProject> projectQuery = _realtimeService.QuerySnapshots<SFProject>();
SFProject? project;

project = hasParatextId
? projectQuery.FirstOrDefault(p => p.ParatextId == paratextId)
: projectQuery.FirstOrDefault(p => p.Id == scriptureForgeId);

if (project is null)
{
return NotFoundError("Project not found");
}

object result = new
{
project.Id,
project.ParatextId,
project.Name,
project.ShortName,
};

return Ok(result);
}
catch (ForbiddenException)
{
return ForbiddenError();
}
catch (Exception)
{
_exceptionHandler.RecordEndpointInfoForException(
new Dictionary<string, string>
{
{ "method", "GetProjectMetadata" },
{ "paratextId", paratextId },
{ "scriptureForgeId", scriptureForgeId },
}
);
throw;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,9 @@ public async Task<IRpcMethodResult> SetSyncDisabled(string projectId, bool isDis
}
}

[Obsolete(
"Use OnboardingRequestRpcController.GetProjectMetadata with either paratextId or scriptureForgeId instead for more flexible querying"
)]
public async Task<IRpcMethodResult> GetProjectIdByParatextId(string paratextId)
{
try
Expand Down
Loading