@@ -715,7 +715,7 @@ public function updateMetadata($event)
715
715
// Only allow updating of metadata if event has publications
716
716
$ oc_event = $ api_event_client ->getEpisode ($ this ->episode );
717
717
718
- if (empty ($ oc_event) || in_array ( ' engage-player ' , ( array ) $ oc_event -> publication_status ) === false ) {
718
+ if (!Helpers:: canEventRunWorkflow ($ oc_event, $ this ) ) {
719
719
return false ;
720
720
}
721
721
@@ -751,23 +751,6 @@ public function updateMetadata($event)
751
751
$ response = $ api_event_client ->updateMetadata ($ this ->episode , $ metadata );
752
752
$ republish = in_array ($ response ['code ' ], [200 , 204 ]) === true ;
753
753
754
- $ result = null ;
755
-
756
- if (\Config::get ()->OPENCAST_ALLOW_PUBLIC_SHARING
757
- && $ this ->visibility != $ event ['visibility ' ]
758
- ) {
759
- $ result = $ this ->updateAcl ($ event ['visibility ' ]);
760
-
761
- if ($ result ['republish ' ]) {
762
- $ republish = true ;
763
- }
764
-
765
- if ($ result ['update ' ]) {
766
- $ this ->visibility = $ event ['visibility ' ];
767
- $ this ->store ();
768
- }
769
- }
770
-
771
754
if ($ republish ) {
772
755
$ api_wf_client = ApiWorkflowsClient::getInstance ($ this ->config_id );
773
756
@@ -817,6 +800,62 @@ public function removeVideo()
817
800
return $ this ->delete ();
818
801
}
819
802
803
+ public function setWorldVisibility ($ visibility )
804
+ {
805
+ // get current ACL for event in Opencast
806
+ $ api_client = ApiEventsClient::getInstance ($ this ->config_id );
807
+ $ current_acl = $ api_client ->getAcl ($ this ->episode );
808
+
809
+ if (empty ($ current_acl )) {
810
+ return false ;
811
+ }
812
+
813
+ // check if ACL contains ROLE_ANONYMOUS
814
+ $ has_anonymous_role = Helpers::isWorldReadable ($ current_acl );
815
+
816
+ if ($ visibility === 'public ' && $ this ->visibility !== 'public ' ) {
817
+ if (!$ has_anonymous_role ) {
818
+ // Add ROLE_ANONYMOUS to the ACL
819
+ $ current_acl [] = [
820
+ 'allow ' => true ,
821
+ 'role ' => 'ROLE_ANONYMOUS ' ,
822
+ 'action ' => 'read '
823
+ ];
824
+
825
+ // Update the ACL in Opencast
826
+ if ($ api_client ->setACL ($ this ->episode , $ current_acl )) {
827
+ // Update local visibility
828
+ $ this ->visibility = 'public ' ;
829
+ $ this ->store ();
830
+
831
+ return true ;
832
+ }
833
+
834
+ return false ;
835
+ }
836
+ } else if ($ visibility !== 'public ' && $ this ->visibility === 'public ' ) {
837
+ if ($ has_anonymous_role ) {
838
+ // Remove ROLE_ANONYMOUS from the ACL
839
+ $ current_acl = array_filter ($ current_acl , function ($ acl_entry ) {
840
+ return $ acl_entry ['role ' ] !== 'ROLE_ANONYMOUS ' ;
841
+ });
842
+
843
+ // Update the ACL in Opencast
844
+ if ($ api_client ->setACL ($ this ->episode , $ current_acl )) {
845
+ // Update local visibility
846
+ $ this ->visibility = $ visibility ;
847
+ $ this ->store ();
848
+
849
+ return true ;
850
+ }
851
+
852
+ return false ;
853
+ }
854
+ }
855
+
856
+ return true ;
857
+ }
858
+
820
859
/**
821
860
* Check that the episode has its unique ACL and set it if necessary
822
861
*
@@ -831,32 +870,21 @@ public function removeVideo()
831
870
public static function checkEventACL ($ eventType , $ episode , $ video )
832
871
{
833
872
// Only allow updating of metadata if event has publications
834
- if (empty ($ episode) || in_array ( ' engage-player ' , ( array ) $ episode -> publication_status ) === false ) {
873
+ if (!Helpers:: canEventRunWorkflow ($ episode, $ video ) ) {
835
874
return ;
836
875
}
837
876
838
- $ workflow_client = ApiWorkflowsClient::getInstance ($ video ->config_id );
839
-
840
- $ results = $ video ->updateAcl (null , json_decode (json_encode ($ episode ->acl ), true ));
841
-
842
- if ($ results ['republish ' ] == true ) {
843
- $ workflow_client ->republish ($ video ->episode );
844
- }
877
+ return $ video ->updateAcl (json_decode (json_encode ($ episode ->acl ), true ));
845
878
}
846
879
847
880
/**
848
881
* Update the ACL in Opencast if necessary
849
882
*
850
- * @param string $new_vis The targeted new visibility. If empty, use the current on to check
883
+ * @param string $current_acl The current ACL in Opencast
851
884
*
852
- * @return array Returns an array of the following form, stating if a republish is necessary and if the
853
- * update in was succesful:
854
- * [
855
- * republish' => boolean
856
- * 'update' => boolean
857
- * ]
885
+ * @return bool whether ACL was updated or not
858
886
*/
859
- public function updateAcl ($ new_vis = null , $ current_acl = null )
887
+ public function updateAcl ($ current_acl = null )
860
888
{
861
889
$ api_client = ApiEventsClient::getInstance ($ this ->config_id );
862
890
if (empty ($ current_acl )) {
@@ -869,6 +897,12 @@ public function updateAcl($new_vis = null, $current_acl = null)
869
897
}
870
898
871
899
$ acl = [];
900
+ if (Helpers::isWorldReadable ($ current_acl )) {
901
+ $ this ->visibility = 'public ' ;
902
+ } else {
903
+ $ this ->visibility = 'internal ' ;
904
+ }
905
+ $ this ->store ();
872
906
873
907
// Don't set event id roles if episode id role access is activated by user
874
908
if (!$ this ->config ->settings ['episode_id_role_access ' ] ?? true ) {
@@ -905,44 +939,17 @@ public function updateAcl($new_vis = null, $current_acl = null)
905
939
906
940
$ acl = array_merge ($ acl , Helpers::createACLsForCourses ($ courses ));
907
941
908
- // add anonymous role if video is world visible
909
- if (\Config::get ()->OPENCAST_ALLOW_PUBLIC_SHARING && (
910
- ($ new_vis && $ new_vis == 'public ' )
911
- || (!$ new_vis && $ this ->visibility == 'public ' )
912
- )) {
913
- $ acl [] = [
914
- 'allow ' => true ,
915
- 'role ' => 'ROLE_ANONYMOUS ' ,
916
- 'action ' => 'read '
917
- ];
918
- }
919
-
920
942
sort ($ acl );
921
943
922
944
$ oc_acls = Helpers::filterACLs ($ current_acl , $ acl );
923
945
924
946
if ($ acl <> $ oc_acls ['studip ' ]) {
925
947
$ new_acl = array_merge ($ oc_acls ['other ' ], $ acl );
926
948
927
- $ result = $ api_client ->setACL ($ this ->episode , $ new_acl );
928
-
929
- if (in_array ($ result ['code ' ], ['200 ' , '204 ' ]) === false ) {
930
- return [
931
- 'republish ' => false ,
932
- 'update ' => false
933
- ];
934
- }
935
-
936
- return [
937
- 'republish ' => true ,
938
- 'update ' => true
939
- ];
949
+ return $ api_client ->setACL ($ this ->episode , $ new_acl );
940
950
}
941
951
942
- return [
943
- 'republish ' => false ,
944
- 'update ' => true
945
- ];
952
+ return false ;
946
953
}
947
954
948
955
/**
0 commit comments