@@ -708,8 +708,8 @@ public boolean canViewNews(News news, String authenticatedUser) {
708
708
|| isMemberOfsharedInSpaces (news , authenticatedUser ))) {
709
709
return false ;
710
710
}
711
- if (news .isPublished () && news .getAudience ().equals (NewsUtils .SPACE_NEWS_AUDIENCE )
712
- && !spaceService .isMember (space , authenticatedUser )) {
711
+ if (news .isPublished () && StringUtils . equals ( news . getPublicationState (), PUBLISHED ) && news .getAudience ().equals (NewsUtils .SPACE_NEWS_AUDIENCE )
712
+ && !( spaceService .isMember (space , authenticatedUser ) || isMemberOfsharedInSpaces ( news , authenticatedUser ) )) {
713
713
return false ;
714
714
}
715
715
if (StringUtils .equals (news .getPublicationState (), STAGED )
@@ -732,6 +732,35 @@ public void shareNews(News news,
732
732
org .exoplatform .social .core .identity .model .Identity userIdentity ,
733
733
String sharedActivityId ) throws Exception {
734
734
735
+ if (!canViewNews (news , userIdentity .getRemoteId ())) {
736
+ throw new IllegalAccessException ("User with id " + userIdentity .getRemoteId () + "doesn't have access to news" );
737
+ }
738
+ if (sharedActivityId != null ) {
739
+ // update article metadata activities
740
+ NewsPageObject newsPageObject = new NewsPageObject (NEWS_METADATA_PAGE_OBJECT_TYPE , news .getId (), null );
741
+ MetadataItem metadataItem = metadataService .getMetadataItemsByMetadataAndObject (NEWS_METADATA_KEY , newsPageObject ).stream ().findFirst ().orElse (null );
742
+ if (metadataItem == null ) {
743
+ throw new ObjectNotFoundException ("News metadata object with id " + news .getId () + " wasn't found" );
744
+ }
745
+
746
+ Map <String , String > properties = metadataItem .getProperties ();
747
+ if (properties == null ) {
748
+ properties = new HashMap <>();
749
+ }
750
+ if (properties .containsKey (NEWS_ACTIVITIES )) {
751
+ String newsActivities = properties .get (NEWS_ACTIVITIES );
752
+ newsActivities = newsActivities .concat (";" ).concat (space .getId ()).concat (":" ).concat (sharedActivityId );
753
+ properties .put (NEWS_ACTIVITIES , newsActivities );
754
+ } else {
755
+ properties .put (NEWS_ACTIVITIES , space .getId ().concat (":" ).concat (sharedActivityId ));
756
+ }
757
+
758
+ metadataItem .setProperties (properties );
759
+ metadataService .updateMetadataItem (metadataItem , Long .parseLong (userIdentity .getId ()));
760
+
761
+ NewsUtils .broadcastEvent (NewsUtils .SHARE_NEWS , userIdentity .getRemoteId (), news );
762
+ }
763
+
735
764
}
736
765
737
766
/**
0 commit comments