@@ -148,54 +148,56 @@ qx.Class.define("osparc.dashboard.CardBase", {
148148 return false ;
149149 } ,
150150
151- // groups -> [orgMembs, orgs, [productEveryone], [everyone]];
152- setIconAndTooltip : function ( shareIcon , accessRights , groups ) {
153- shareIcon . setSource ( osparc . dashboard . CardBase . SHARE_ICON ) ;
154- if ( osparc . data . model . Study . canIWrite ( accessRights ) ) {
155- shareIcon . set ( {
156- toolTipText : qx . locale . Manager . tr ( "Share" )
157- } ) ;
151+ populateShareIcon : async function ( shareIcon , accessRights ) {
152+ const gids = Object . keys ( accessRights ) . map ( key => parseInt ( key ) ) ;
153+
154+ const groupsStore = osparc . store . Groups . getInstance ( ) ;
155+
156+ // Icon
157+ const groupEveryone = groupsStore . getEveryoneGroup ( ) ;
158+ const groupProductEveryone = groupsStore . getEveryoneProductGroup ( ) ;
159+ const organizations = groupsStore . getOrganizations ( ) ;
160+ const organizationIds = Object . keys ( organizations ) . map ( key => parseInt ( key ) ) ;
161+ if ( gids . includes ( groupEveryone . getGroupId ( ) ) || gids . includes ( groupProductEveryone . getGroupId ( ) ) ) {
162+ shareIcon . setSource ( osparc . dashboard . CardBase . SHARED_ALL ) ;
163+ } else if ( organizationIds . filter ( value => gids . includes ( value ) ) . length ) { // find intersection
164+ shareIcon . setSource ( osparc . dashboard . CardBase . SHARED_ORGS ) ;
165+ } else if ( gids . length === 1 ) {
166+ shareIcon . setSource ( osparc . dashboard . CardBase . SHARE_ICON ) ;
167+ } else {
168+ shareIcon . setSource ( osparc . dashboard . CardBase . SHARED_USER ) ;
158169 }
159- let sharedGrps = [ ] ;
160- const myGroupId = osparc . auth . Data . getInstance ( ) . getGroupId ( ) ;
161- for ( let i = 0 ; i < groups . length ; i ++ ) {
162- if ( groups [ i ] . length === 0 ) {
163- // user has no read access to the productEveryone
164- continue ;
170+
171+ // Tooltip
172+ const sharedGrps = [ ] ;
173+ const groups = [ ] ;
174+ groups . push ( groupEveryone ) ;
175+ groups . push ( groupProductEveryone ) ;
176+ groups . push ( ...Object . values ( organizations ) ) ;
177+ groups . forEach ( group => {
178+ const idx = gids . indexOf ( group . getGroupId ( ) ) ;
179+ if ( idx > - 1 ) {
180+ sharedGrps . push ( group ) ;
181+ gids . splice ( idx , 1 ) ;
165182 }
166- const sharedGrp = [ ] ;
167- const gids = Object . keys ( accessRights ) ;
168- for ( let j = 0 ; j < gids . length ; j ++ ) {
169- const gid = parseInt ( gids [ j ] ) ;
170- if ( gid === myGroupId ) {
171- continue ;
172- }
173- const grp = groups [ i ] . find ( group => group . getGroupId ( ) === gid ) ;
174- if ( grp ) {
175- sharedGrp . push ( grp ) ;
183+ } ) ;
184+ // once the groups were removed, the remaining group ids are users' primary groups ids
185+ const usersStore = osparc . store . Users . getInstance ( ) ;
186+ const myGroupId = osparc . auth . Data . getInstance ( ) . getGroupId ( ) ;
187+ for ( let i = 0 ; i < gids . length ; i ++ ) {
188+ const gid = gids [ i ] ;
189+ if ( myGroupId !== gid ) {
190+ const user = await usersStore . getUser ( gid ) ;
191+ if ( user ) {
192+ sharedGrps . push ( user ) ;
176193 }
177194 }
178- if ( sharedGrp . length === 0 ) {
179- continue ;
180- } else {
181- sharedGrps = sharedGrps . concat ( sharedGrp ) ;
182- }
183- switch ( i ) {
184- case 0 :
185- shareIcon . setSource ( osparc . dashboard . CardBase . SHARED_USER ) ;
186- break ;
187- case 1 :
188- shareIcon . setSource ( osparc . dashboard . CardBase . SHARED_ORGS ) ;
189- break ;
190- case 2 :
191- case 3 :
192- shareIcon . setSource ( osparc . dashboard . CardBase . SHARED_ALL ) ;
193- break ;
194- }
195195 }
196196
197- // tooltip
198- if ( sharedGrps . length === 0 ) {
197+ if ( sharedGrps . length === 0 && osparc . data . model . Study . canIWrite ( accessRights ) ) {
198+ shareIcon . set ( {
199+ toolTipText : qx . locale . Manager . tr ( "Share" )
200+ } ) ;
199201 return ;
200202 }
201203 const sharedGrpLabels = [ ] ;
@@ -215,18 +217,6 @@ qx.Class.define("osparc.dashboard.CardBase", {
215217 shareIcon . addListener ( "mouseover" , ( ) => hint . show ( ) , this ) ;
216218 shareIcon . addListener ( "mouseout" , ( ) => hint . exclude ( ) , this ) ;
217219 } ,
218-
219- // groups -> [users, orgs, [productEveryone], [everyone]];
220- populateShareIcon : function ( shareIcon , accessRights ) {
221- const groupsStore = osparc . store . Groups . getInstance ( ) ;
222- const usersStore = osparc . store . Users . getInstance ( ) ;
223- const users = usersStore . getUsers ( ) ;
224- const orgs = Object . values ( groupsStore . getOrganizations ( ) ) ;
225- const productEveryone = [ groupsStore . getEveryoneProductGroup ( ) ] ;
226- const everyone = [ groupsStore . getEveryoneGroup ( ) ] ;
227- const groups = [ users , orgs , productEveryone , everyone ] ;
228- osparc . dashboard . CardBase . setIconAndTooltip ( shareIcon , accessRights , groups ) ;
229- } ,
230220 } ,
231221
232222 properties : {
0 commit comments