Skip to content

Commit

Permalink
account token warnings fix; cancel send btn move before server send
Browse files Browse the repository at this point in the history
  • Loading branch information
KatKatKateryna committed Jan 18, 2024
1 parent d743e8b commit 55abee1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 66 deletions.
109 changes: 45 additions & 64 deletions speckle/utils/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,72 +12,53 @@

def tryGetClient(sw: StreamWrapper, dataStorage, write=False, dockwidget=None):
# only streams with write access
try:
client = None
savedRole = None
savedStreamId = None
for acc in dataStorage.accounts:
# only check accounts on selected server
if acc.serverInfo.url in sw.server_url:
client = SpeckleClient(
acc.serverInfo.url, acc.serverInfo.url.startswith("https")
)
try:
client.authenticate_with_account(acc)
if client.account.token is not None:
break
except SpeckleException as ex:
if "already connected" in ex.message:
logToUser(
"Dependencies versioning error.\nClick here for details.",
url="dependencies_error",
level=2,
plugin=dockwidget,
)
return
else:
raise ex

# if token still not found
if client is None or client.account.token is None:
for acc in dataStorage.accounts:
client = sw.get_client()
if client is not None:
break

if client is not None:
stream = client.stream.get(
id=sw.stream_id, branch_limit=100, commit_limit=100
client = None
savedRole = None
savedStreamId = None
for acc in dataStorage.accounts:
# only check accounts on selected server
if acc.serverInfo.url in sw.server_url:
client = SpeckleClient(
acc.serverInfo.url, acc.serverInfo.url.startswith("https")
)
if isinstance(stream, Stream):
# print(stream.role)
if write == False:
# try get stream, only read access needed
# print("only read access needed")
return client, stream
try:
client.authenticate_with_account(acc)
if client.account.token is not None:
break
except SpeckleException as ex:
if "already connected" in ex.message:
logToUser(
"Dependencies versioning error.\nClick here for details.",
url="dependencies_error",
level=2,
plugin=dockwidget,
)
return None, None
else:
# check write access
# print("write access needed")
if stream.role is None or (
isinstance(stream.role, str) and "reviewer" in stream.role
):
savedRole = stream.role
savedStreamId = stream.id
else:
return client, stream

if savedRole is not None and savedStreamId is not None:
logToUser(
f"You don't have write access to the stream '{savedStreamId}'. You role is '{savedRole}'",
level=2,
func=inspect.stack()[0][3],
plugin=dockwidget,
)

return None, None
except Exception as e:
logToUser(e, level=2, func=inspect.stack()[0][3], plugin=dockwidget)
return None, None
raise ex

# if token still not found
if client is None or client.account.token is None:
client = sw.get_client()

if client is not None:
stream = client.stream.get(id=sw.stream_id, branch_limit=100, commit_limit=100)
if isinstance(stream, Stream):
if write is False:
# try get stream, only read access needed
return client, stream
else:
# check write access
if stream.role is None:
raise Exception(
f"You don't have write access to the stream '{stream.id}'. You role is '{stream.role}'"
)
elif isinstance(stream.role, str) and "reviewer" in stream.role:
raise Exception(
f"You don't have write access to the stream '{savedStreamId}'. You role is '{savedRole}'"
)
else:
return client, stream


def tryGetStream(
Expand Down
4 changes: 2 additions & 2 deletions speckle_qgis.py
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ def onSend(self, message: str):
return

# data transfer

self.dockwidget.signal_remove_btn_url.emit("cancel")
time_start_transfer = datetime.now()
try:
# this serialises the block and sends it to the transport
Expand All @@ -591,8 +593,6 @@ def onSend(self, message: str):
return
time_end_transfer = datetime.now()

self.dockwidget.signal_remove_btn_url.emit("cancel")

try:
# you can now create a commit on your stream with this object
commit_id = client.commit.create(
Expand Down

0 comments on commit 55abee1

Please sign in to comment.