Skip to content

Commit fbbb88b

Browse files
committed
improve logic
1 parent a75041b commit fbbb88b

File tree

1 file changed

+32
-31
lines changed
  • services/static-webserver/client/source/class/osparc/support

1 file changed

+32
-31
lines changed

services/static-webserver/client/source/class/osparc/support/Conversation.js

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ qx.Class.define("osparc.support.Conversation", {
6060
this.getChildControl("share-project-layout").add(new qx.ui.core.Spacer(), { flex: 1 });
6161
this.getChildControl("share-project-layout").add(control);
6262
this.getChildControl("share-project-layout").add(new qx.ui.core.Spacer(), { flex: 1 });
63+
control.addListener("changeValue", e => this.__shareProjectWithSupport(e.getData()), this);
6364
break;
6465
}
6566
return control || this.base(arguments, id);
@@ -129,57 +130,57 @@ qx.Class.define("osparc.support.Conversation", {
129130
this.base(arguments, conversation);
130131

131132
this.__bookACallInfo = null;
132-
this.__populateShareProjectCheckbox();
133+
this.__evaluateShareProject();
133134
},
134135

135136
__postMessage: function(content) {
136137
const conversationId = this.getConversation().getConversationId();
137138
return osparc.store.ConversationsSupport.getInstance().postMessage(conversationId, content);
138139
},
139140

140-
__populateShareProjectCheckbox: function() {
141+
__evaluateShareProject: function() {
141142
const conversation = this.getConversation();
142143

143-
const shareProjectCB = this.getChildControl("share-project-checkbox");
144144
const shareProjectLayout = this.getChildControl("share-project-layout");
145145
const currentStudy = osparc.store.Store.getInstance().getCurrentStudy();
146-
let showCB = false;
147-
let enabledCB = false;
148-
if (conversation === null && currentStudy) {
149-
// initiating conversation
150-
showCB = true;
151-
enabledCB = true;
152-
} else if (conversation) {
146+
let showLayout = false;
147+
let enabledLayout = false;
148+
if (conversation && currentStudy) {
153149
// it was already set
154-
showCB = conversation.getContextProjectId();
155-
enabledCB = conversation.amIOwner();
150+
showLayout = conversation.getContextProjectId();
151+
enabledLayout = conversation.amIOwner() && osparc.data.model.Study.canIWrite(currentStudy.getAccessRights());
156152
}
157153
shareProjectLayout.set({
158-
visibility: showCB ? "visible" : "excluded",
159-
enabled: enabledCB,
154+
visibility: showLayout ? "visible" : "excluded",
155+
enabled: enabledLayout,
160156
});
161157

162-
if (conversation && conversation.getContextProjectId()) {
158+
if (showLayout) {
163159
const projectId = conversation.getContextProjectId();
164-
osparc.store.Study.getInstance().getOne(projectId)
165-
.then(studyData => {
166-
let isAlreadyShared = false;
167-
const accessRights = studyData["accessRights"];
168-
const supportGroupId = osparc.store.Groups.getInstance().getSupportGroup().getGroupId();
169-
if (supportGroupId && supportGroupId in accessRights) {
170-
isAlreadyShared = true;
171-
} else {
172-
isAlreadyShared = false;
173-
}
174-
shareProjectCB.setValue(isAlreadyShared);
175-
shareProjectCB.removeListener("changeValue", e => this.__shareProjectWithSupport(e.getData()), this);
176-
if (showCB) {
177-
shareProjectCB.addListener("changeValue", e => this.__shareProjectWithSupport(e.getData()), this);
178-
}
179-
});
160+
if (currentStudy && projectId === currentStudy.getUuid()) {
161+
this.__populateShareProjectCB();
162+
currentStudy.addListener("changeAccessRights", () => this.__populateShareProjectCB(), this);
163+
}
180164
}
181165
},
182166

167+
__populateShareProjectCB: function() {
168+
const projectId = conversation.getContextProjectId();
169+
osparc.store.Study.getInstance().getOne(projectId)
170+
.then(studyData => {
171+
let isAlreadyShared = false;
172+
const accessRights = studyData["accessRights"];
173+
const supportGroupId = osparc.store.Groups.getInstance().getSupportGroup().getGroupId();
174+
if (supportGroupId && supportGroupId in accessRights) {
175+
isAlreadyShared = true;
176+
} else {
177+
isAlreadyShared = false;
178+
}
179+
const shareProjectCB = this.getChildControl("share-project-checkbox");
180+
shareProjectCB.setValue(isAlreadyShared);
181+
});
182+
},
183+
183184
__shareProjectWithSupport: function(share) {
184185
const supportGroupId = osparc.store.Groups.getInstance().getSupportGroup().getGroupId();
185186
const projectId = this.getConversation().getContextProjectId();

0 commit comments

Comments
 (0)