@@ -17,26 +17,19 @@ import { store as projects_store } from "@cocalc/frontend/projects/store";
17
17
import { webapp_client } from "@cocalc/frontend/webapp-client" ;
18
18
import { reuseInFlight } from "@cocalc/util/reuse-in-flight" ;
19
19
import { CourseActions , primary_key } from "../actions" ;
20
- import { DEFAULT_LICENSE_UPGRADE_HOST_PROJECT } from "../store" ;
20
+ import {
21
+ DEFAULT_LICENSE_UPGRADE_HOST_PROJECT ,
22
+ CourseSettingsRecord ,
23
+ PARALLEL_DEFAULT ,
24
+ } from "../store" ;
21
25
import { SiteLicenseStrategy , SyncDBRecord , UpgradeGoal } from "../types" ;
22
- import { StudentProjectFunctionality } from "./customize-student-project-functionality" ;
26
+ import {
27
+ StudentProjectFunctionality ,
28
+ completeStudentProjectFunctionality ,
29
+ } from "./customize-student-project-functionality" ;
23
30
import type { PurchaseInfo } from "@cocalc/util/licenses/purchase/types" ;
24
31
import { delay } from "awaiting" ;
25
32
26
- export const CONFIGURATION_GROUPS = [
27
- "collaborator-policy" ,
28
- "email-invitation" ,
29
- "copy-limit" ,
30
- "restrict-student-projects" ,
31
- "nbgrader" ,
32
- "network-file-systems" ,
33
- "env-variables" ,
34
- "upgrades" ,
35
- "software-environment" ,
36
- ] as const ;
37
-
38
- export type ConfigurationGroup = ( typeof CONFIGURATION_GROUPS ) [ number ] ;
39
-
40
33
interface ConfigurationTarget {
41
34
project_id : string ;
42
35
path : string ;
@@ -130,6 +123,10 @@ export class ConfigurationActions {
130
123
set_student_project_functionality = async (
131
124
student_project_functionality : StudentProjectFunctionality ,
132
125
) : Promise < void > => {
126
+ console . log (
127
+ "set_student_project_functionalit" ,
128
+ student_project_functionality ,
129
+ ) ;
133
130
this . set ( { student_project_functionality, table : "settings" } ) ;
134
131
await this . course_actions . student_projects . configure_all_projects ( ) ;
135
132
} ;
@@ -234,7 +231,7 @@ export class ConfigurationActions {
234
231
}
235
232
} ;
236
233
237
- set_copy_parallel = ( copy_parallel : number ) : void => {
234
+ set_copy_parallel = ( copy_parallel : number = PARALLEL_DEFAULT ) : void => {
238
235
this . set ( {
239
236
copy_parallel,
240
237
table : "settings" ,
@@ -437,7 +434,6 @@ export class ConfigurationActions {
437
434
groups : ConfigurationGroup [ ] ;
438
435
targets : ConfigurationTarget [ ] ;
439
436
} ) => {
440
- console . log ( "copyConfiguration" , { groups, targets } ) ;
441
437
const store = this . course_actions . get_store ( ) ;
442
438
if ( groups . length == 0 || targets . length == 0 || store == null ) {
443
439
return ;
@@ -449,17 +445,11 @@ export class ConfigurationActions {
449
445
maxTimeMs : 30000 ,
450
446
} ) ;
451
447
for ( const group of groups ) {
452
- console . log ( "copyConfiguration: copy " , target , {
453
- allow_collabs : ! ! settings . get ( "allow_collabs" ) ,
454
- table : "settings" ,
448
+ await configureGroup ( {
449
+ group,
450
+ settings,
451
+ actions : targetActions . course_actions ,
455
452
} ) ;
456
- if ( group == "collaborator-policy" ) {
457
- const allow_colabs = ! ! settings . get ( "allow_collabs" ) ;
458
- targetActions . course_actions . configuration . set_allow_collabs (
459
- allow_colabs ,
460
- ) ;
461
- }
462
- targetActions . course_actions . syncdb . save ( ) ;
463
453
}
464
454
}
465
455
// switch back
@@ -484,3 +474,50 @@ async function openCourseFileAndGetActions({ project_id, path, maxTimeMs }) {
484
474
}
485
475
throw Error ( `unable to open '${ path } '` ) ;
486
476
}
477
+
478
+ export const CONFIGURATION_GROUPS = [
479
+ "collaborator-policy" ,
480
+ "email-invitation" ,
481
+ "copy-limit" ,
482
+ "restrict-student-projects" ,
483
+ "nbgrader" ,
484
+ "network-file-systems" ,
485
+ "env-variables" ,
486
+ "upgrades" ,
487
+ "software-environment" ,
488
+ ] as const ;
489
+
490
+ export type ConfigurationGroup = ( typeof CONFIGURATION_GROUPS ) [ number ] ;
491
+
492
+ async function configureGroup ( {
493
+ group,
494
+ settings,
495
+ actions,
496
+ } : {
497
+ group : ConfigurationGroup ;
498
+ settings : CourseSettingsRecord ;
499
+ actions : CourseActions ;
500
+ } ) {
501
+ console . log ( "configureGroup:" , group ) ;
502
+ switch ( group ) {
503
+ case "collaborator-policy" :
504
+ const allow_colabs = ! ! settings . get ( "allow_collabs" ) ;
505
+ actions . configuration . set_allow_collabs ( allow_colabs ) ;
506
+ return ;
507
+ case "email-invitation" :
508
+ actions . configuration . set_email_invite ( settings . get ( "email_invite" ) ) ;
509
+ return ;
510
+ case "copy-limit" :
511
+ actions . configuration . set_copy_parallel ( settings . get ( "copy_parallel" ) ) ;
512
+ return ;
513
+ case "restrict-student-projects" :
514
+ actions . configuration . set_student_project_functionality (
515
+ completeStudentProjectFunctionality (
516
+ settings . get ( "student_project_functionality" ) ?. toJS ( ) ?? { } ,
517
+ ) ,
518
+ ) ;
519
+ return ;
520
+ default :
521
+ throw Error ( `configuring group ${ group } not implemented` ) ;
522
+ }
523
+ }
0 commit comments