@@ -150,12 +150,20 @@ public async Task<string> CreateProjectAsync(string curUserId, SFProjectCreateSe
150150 // This will make the source project appear after the target, if it needs to be created
151151 if ( settings . SourceParatextId != null && settings . SourceParatextId != settings . ParatextId )
152152 {
153+ // Get the resources if the source is a resource
154+ IReadOnlyList < ParatextResource > resources = [ ] ;
155+ if ( _paratextService . IsResource ( settings . SourceParatextId ) )
156+ {
157+ resources = await _paratextService . GetResourcesAsync ( curUserId ) ;
158+ }
159+
153160 TranslateSource source = await GetTranslateSourceAsync (
154161 curUserId ,
155162 projectDoc . Id ,
156163 settings . SourceParatextId ,
157164 syncIfCreated : false ,
158- ptProjects
165+ ptProjects ,
166+ resources
159167 ) ;
160168
161169 await projectDoc . SubmitJson0OpAsync ( op => UpdateSetting ( op , p => p . TranslateConfig . Source , source ) ) ;
@@ -361,7 +369,8 @@ public async Task UpdateSettingsAsync(string curUserId, string projectId, SFProj
361369 settings . AdditionalTrainingSourceParatextId == ProjectSettingValueUnset ;
362370
363371 // Get the list of projects for setting the source or alternate source
364- IReadOnlyList < ParatextProject > ptProjects = new List < ParatextProject > ( ) ;
372+ IReadOnlyList < ParatextProject > ptProjects = [ ] ;
373+ IReadOnlyList < ParatextResource > resources = [ ] ;
365374 if (
366375 ( settings . SourceParatextId != null && ! unsetSourceProject )
367376 || ( settings . AlternateSourceParatextId != null && ! unsetAlternateSourceProject )
@@ -374,6 +383,17 @@ public async Task UpdateSettingsAsync(string curUserId, string projectId, SFProj
374383 throw new DataNotFoundException ( "The user does not exist." ) ;
375384
376385 ptProjects = await _paratextService . GetProjectsAsync ( userSecret ) ;
386+
387+ // Only get the resources if at least one of the paratext ids is a resource id
388+ if (
389+ _paratextService . IsResource ( settings . SourceParatextId )
390+ || _paratextService . IsResource ( settings . AlternateSourceParatextId )
391+ || _paratextService . IsResource ( settings . AlternateTrainingSourceParatextId )
392+ || _paratextService . IsResource ( settings . AdditionalTrainingSourceParatextId )
393+ )
394+ {
395+ resources = await _paratextService . GetResourcesAsync ( curUserId ) ;
396+ }
377397 }
378398
379399 // Get the source - any creation or permission updates are handled in GetTranslateSourceAsync
@@ -386,6 +406,7 @@ public async Task UpdateSettingsAsync(string curUserId, string projectId, SFProj
386406 settings . SourceParatextId ,
387407 syncIfCreated : false ,
388408 ptProjects ,
409+ resources ,
389410 projectDoc . Data . UserRoles
390411 ) ;
391412 if ( source . ProjectRef == projectId )
@@ -405,6 +426,7 @@ public async Task UpdateSettingsAsync(string curUserId, string projectId, SFProj
405426 settings . AlternateSourceParatextId ,
406427 syncIfCreated : true ,
407428 ptProjects ,
429+ resources ,
408430 projectDoc . Data . UserRoles
409431 ) ;
410432 if ( alternateSource . ProjectRef == projectId )
@@ -424,6 +446,7 @@ public async Task UpdateSettingsAsync(string curUserId, string projectId, SFProj
424446 settings . AlternateTrainingSourceParatextId ,
425447 syncIfCreated : true ,
426448 ptProjects ,
449+ resources ,
427450 projectDoc . Data . UserRoles
428451 ) ;
429452 if ( alternateTrainingSource . ProjectRef == projectId )
@@ -443,6 +466,7 @@ public async Task UpdateSettingsAsync(string curUserId, string projectId, SFProj
443466 settings . AdditionalTrainingSourceParatextId ,
444467 syncIfCreated : true ,
445468 ptProjects ,
469+ resources ,
446470 projectDoc . Data . UserRoles
447471 ) ;
448472 if ( additionalTrainingSource . ProjectRef == projectId )
@@ -1856,13 +1880,14 @@ private async Task<string> CreateResourceProjectInternalAsync(string curUserId,
18561880 }
18571881
18581882 /// <summary>
1859- /// Gets the translate source asynchronously.
1883+ /// Gets the translation source asynchronously.
18601884 /// </summary>
18611885 /// <param name="curUserId">The current user identifier.</param>
18621886 /// <param name="sfProjectId">The Scripture Forge project identifier.</param>
18631887 /// <param name="paratextId">The paratext identifier.</param>
18641888 /// <param name="syncIfCreated">If <c>true</c> sync the project if it is created.</param>
18651889 /// <param name="ptProjects">The paratext projects.</param>
1890+ /// <param name="resources">The paratext resources.</param>
18661891 /// <param name="userRoles">The ids and roles of the users who will need to access the source.</param>
18671892 /// <returns>The <see cref="TranslateSource"/> object for the specified resource.</returns>
18681893 /// <exception cref="DataNotFoundException">The source paratext project does not exist.</exception>
@@ -1872,6 +1897,7 @@ private async Task<TranslateSource> GetTranslateSourceAsync(
18721897 string paratextId ,
18731898 bool syncIfCreated ,
18741899 IEnumerable < ParatextProject > ptProjects ,
1900+ IEnumerable < ParatextResource > resources ,
18751901 IReadOnlyDictionary < string , string > ? userRoles = null
18761902 )
18771903 {
@@ -1880,7 +1906,6 @@ private async Task<TranslateSource> GetTranslateSourceAsync(
18801906 if ( sourcePTProject == null )
18811907 {
18821908 // If it is not a project, see if there is a matching resource
1883- IReadOnlyList < ParatextResource > resources = await _paratextService . GetResourcesAsync ( curUserId ) ;
18841909 sourcePTProject = resources . SingleOrDefault ( r => r . ParatextId == paratextId ) ;
18851910 if ( sourcePTProject == null )
18861911 {
@@ -1889,7 +1914,7 @@ private async Task<TranslateSource> GetTranslateSourceAsync(
18891914 }
18901915
18911916 // Get the users who will access this source resource or project
1892- IEnumerable < string > userIds = userRoles != null ? userRoles . Keys : new string [ ] { curUserId } ;
1917+ IEnumerable < string > userIds = userRoles != null ? userRoles . Keys : [ curUserId ] ;
18931918
18941919 // Get the project reference
18951920 SFProject sourceProject = RealtimeService
@@ -1903,7 +1928,7 @@ private async Task<TranslateSource> GetTranslateSourceAsync(
19031928 }
19041929 else
19051930 {
1906- sourceProjectRef = await CreateResourceProjectAsync ( curUserId , paratextId , addUser : false ) ;
1931+ sourceProjectRef = await CreateResourceProjectInternalAsync ( curUserId , sourcePTProject ) ;
19071932 projectCreated = true ;
19081933 }
19091934
0 commit comments