@@ -86,10 +86,23 @@ export const WORKFLOW_STOP_INIT = "Initialize workflow stopping";
86
86
export const WORKFLOW_STOPPED = "Workflow stopped" ;
87
87
export const OPEN_STOP_WORKFLOW_MODAL = "Open stop workflow modal" ;
88
88
export const CLOSE_STOP_WORKFLOW_MODAL = "Close stop workflow modal" ;
89
+ export const OPEN_SHARE_WORKFLOW_MODAL = "Open share workflow modal" ;
90
+ export const CLOSE_SHARE_WORKFLOW_MODAL = "Close share workflow modal" ;
89
91
export const WORKFLOW_LIST_REFRESH = "Refresh workflow list" ;
90
92
export const OPEN_INTERACTIVE_SESSION_MODAL = "Open interactive session modal" ;
91
93
export const CLOSE_INTERACTIVE_SESSION_MODAL =
92
94
"Close interactive session modal" ;
95
+ export const WORKFLOW_SHARE_STATUS_FETCH = "Fetch workflow share status" ;
96
+ export const WORKFLOW_SHARE_STATUS_RECEIVED = "Workflow share status received" ;
97
+ export const WORKFLOW_SHARE_STATUS_FETCH_ERROR =
98
+ "Fetch workflow share status error" ;
99
+ export const WORKFLOW_SHARE_INIT = "Initialise workflow sharing" ;
100
+ export const WORKFLOW_SHARED_SUCCESSFULLY = "Workflow shared successfully" ;
101
+ export const WORKFLOW_SHARED_ERROR = "Workflow shared error" ;
102
+ export const WORKFLOW_SHARE_FINISH = "Finish workflow sharing" ;
103
+ export const WORKFLOW_UNSHARE_INIT = "Initialise workflow unsharing" ;
104
+ export const WORKFLOW_UNSHARED = "Workflow unshared" ;
105
+ export const WORKFLOW_UNSHARE_ERROR = "Workflow unshare error" ;
93
106
94
107
export const USERS_SHARED_WITH_YOU_FETCH =
95
108
"Fetch users who shared workflows with you" ;
@@ -540,6 +553,14 @@ export function closeInteractiveSession(id) {
540
553
} ;
541
554
}
542
555
556
+ export function openShareWorkflowModal ( workflow ) {
557
+ return { type : OPEN_SHARE_WORKFLOW_MODAL , workflow } ;
558
+ }
559
+
560
+ export function closeShareWorkflowModal ( ) {
561
+ return { type : CLOSE_SHARE_WORKFLOW_MODAL } ;
562
+ }
563
+
543
564
export function fetchUsersSharedWithYou ( ) {
544
565
return async ( dispatch ) => {
545
566
dispatch ( { type : USERS_SHARED_WITH_YOU_FETCH } ) ;
@@ -577,3 +598,90 @@ export function fetchUsersYouSharedWith() {
577
598
} ) ;
578
599
} ;
579
600
}
601
+
602
+ export function fetchWorkflowShareStatus ( id ) {
603
+ return async ( dispatch ) => {
604
+ dispatch ( { type : WORKFLOW_SHARE_STATUS_FETCH } ) ;
605
+ return await client
606
+ . getWorkflowShareStatus ( id )
607
+ . then ( ( resp ) => {
608
+ dispatch ( {
609
+ type : WORKFLOW_SHARE_STATUS_RECEIVED ,
610
+ id,
611
+ workflow_share_status : resp . data . shared_with ,
612
+ } ) ;
613
+ return resp ;
614
+ } )
615
+ . catch ( ( err ) => {
616
+ dispatch ( errorActionCreator ( err , WORKFLOW_SHARE_STATUS_FETCH_ERROR ) ) ;
617
+ } ) ;
618
+ } ;
619
+ }
620
+
621
+ export function shareWorkflow (
622
+ id ,
623
+ user_id ,
624
+ user_emails_to_share_with ,
625
+ valid_until ,
626
+ ) {
627
+ return async ( dispatch ) => {
628
+ dispatch ( { type : WORKFLOW_SHARE_INIT } ) ;
629
+
630
+ const users_shared_with = [ ] ;
631
+ const users_not_shared_with = [ ] ;
632
+
633
+ for ( const user_email_to_share_with of user_emails_to_share_with ) {
634
+ await client
635
+ . shareWorkflow ( id , {
636
+ user_id,
637
+ user_email_to_share_with,
638
+ valid_until,
639
+ } )
640
+ . then ( ( ) => {
641
+ users_shared_with . push ( user_email_to_share_with ) ;
642
+ } )
643
+ . catch ( ( err ) => {
644
+ const error_message = err . response . data . message ;
645
+ users_not_shared_with . push ( {
646
+ user_email_to_share_with,
647
+ error_message,
648
+ } ) ;
649
+ } ) ;
650
+
651
+ if ( users_shared_with . length > 0 ) {
652
+ dispatch ( {
653
+ type : WORKFLOW_SHARED_SUCCESSFULLY ,
654
+ users_shared_with,
655
+ } ) ;
656
+ }
657
+
658
+ if ( users_not_shared_with . length > 0 ) {
659
+ dispatch ( {
660
+ type : WORKFLOW_SHARED_ERROR ,
661
+ users_not_shared_with,
662
+ } ) ;
663
+ }
664
+ }
665
+
666
+ dispatch ( { type : WORKFLOW_SHARE_FINISH } ) ;
667
+ } ;
668
+ }
669
+
670
+ export function unshareWorkflow ( id , user_id , user_email_to_unshare_with ) {
671
+ return async ( dispatch ) => {
672
+ dispatch ( { type : WORKFLOW_UNSHARE_INIT } ) ;
673
+
674
+ return await client
675
+ . unshareWorkflow ( id , {
676
+ user_id,
677
+ user_email_to_unshare_with,
678
+ } )
679
+ . then ( ( ) => {
680
+ dispatch ( { type : WORKFLOW_UNSHARED , user_email_to_unshare_with } ) ;
681
+ } )
682
+ . catch ( ( err ) => {
683
+ const error_message = err . response . data . message ;
684
+ dispatch ( { type : WORKFLOW_UNSHARE_ERROR , error_message } ) ;
685
+ } ) ;
686
+ } ;
687
+ }
0 commit comments