Skip to content

Commit

Permalink
feature-locking: send lock/restriction status from client session
Browse files Browse the repository at this point in the history
problem:
earlier restriction/lock status was sent to kit via browser,
now client session send this status directily to the kit.
this design will require less communication between server and browser

Signed-off-by: Pranam Lashkari <[email protected]>
Change-Id: I6b830f30fb326a5e6637e345250893cbba101de6
  • Loading branch information
lpranam committed Oct 17, 2023
1 parent 395d6c9 commit 93b5bdf
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 18 deletions.
1 change: 0 additions & 1 deletion browser/src/map/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ L.Map = L.Evented.extend({
this.on('docloaded', function(e) {
this._docLoaded = e.status;
if (this._docLoaded) {
app.socket.sendMessage('blockingcommandstatus isRestrictedUser=' + this.Restriction.isRestrictedUser + ' isLockedUser=' + this.Locking.isLockedUser);
app.idleHandler.notifyActive();
if (!document.hasFocus()) {
this.fire('editorgotfocus');
Expand Down
40 changes: 39 additions & 1 deletion wsd/ClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,7 +1249,24 @@ bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/,
#if ENABLE_FEATURE_LOCK
sendLockedInfo();
#endif
return forwardToChild(oss.str(), docBroker);

#if ENABLE_FEATURE_RESTRICTION
sendRestrictionInfo();
#endif

bool result = forwardToChild(oss.str(), docBroker);
#if ENABLE_FEATURE_LOCK || ENABLE_FEATURE_RESTRICTION
if (result)
{
forwardToChild(
std::string("blockingcommandstatus isRestrictedUser=") +
(CommandControl::RestrictionManager::isRestrictedUser() ? "true" : "false") +
std::string(" isLockedUser=") +
(CommandControl::LockManager::isLockedUser() ? "true" : "false"),
docBroker);
}
#endif
return result;
}
catch (const Poco::SyntaxException&)
{
Expand Down Expand Up @@ -1292,6 +1309,27 @@ void ClientSession::sendLockedInfo()
}
#endif

#if ENABLE_FEATURE_RESTRICTION
void ClientSession::sendRestrictionInfo()
{
Poco::JSON::Object::Ptr restrictionInfo = new Poco::JSON::Object();
restrictionInfo->set("IsRestrictedUser",
CommandControl::RestrictionManager::isRestrictedUser());

// Poco:Dynamic:Var does not support std::unordred_set so converted to std::vector
std::vector<std::string> restrictedCommandList(
CommandControl::RestrictionManager::getRestrictedCommandList().begin(),
CommandControl::RestrictionManager::getRestrictedCommandList().end());
restrictionInfo->set("RestrictedCommandList", restrictedCommandList);

std::ostringstream ossRestrictionInfo;
restrictionInfo->stringify(ossRestrictionInfo);
const std::string restrictionInfoString = ossRestrictionInfo.str();
LOG_TRC("Sending command restriction info to client: " << restrictionInfoString);
sendTextFrame("restrictedCommands: " + restrictionInfoString);
}
#endif

bool ClientSession::getCommandValues(const char *buffer, int length, const StringVector& tokens,
const std::shared_ptr<DocumentBroker>& docBroker)
{
Expand Down
4 changes: 4 additions & 0 deletions wsd/ClientSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ class ClientSession final : public Session
void sendLockedInfo();
#endif

#if ENABLE_FEATURE_RESTRICTION
void sendRestrictionInfo();
#endif

/// Process an SVG to replace embedded file:/// media URIs with public http URLs.
std::string processSVGContent(const std::string& svg);

Expand Down
16 changes: 0 additions & 16 deletions wsd/DocumentBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1002,22 +1002,6 @@ bool DocumentBroker::download(const std::shared_ptr<ClientSession>& session, con
}
}

#if ENABLE_FEATURE_RESTRICTION
Object::Ptr restrictionInfo = new Object();
restrictionInfo->set("IsRestrictedUser", CommandControl::RestrictionManager::isRestrictedUser());

// Poco:Dynamic:Var does not support std::unordred_set so converted to std::vector
std::vector<std::string> restrictedCommandList(CommandControl::RestrictionManager::getRestrictedCommandList().begin(),
CommandControl::RestrictionManager::getRestrictedCommandList().end());
restrictionInfo->set("RestrictedCommandList", restrictedCommandList);

std::ostringstream ossRestrictionInfo;
restrictionInfo->stringify(ossRestrictionInfo);
const std::string restrictionInfoString = ossRestrictionInfo.str();
LOG_TRC("Sending command restriction info to client: " << restrictionInfoString);
session->sendMessage("restrictedCommands: " + restrictionInfoString);
#endif

#if ENABLE_SUPPORT_KEY
if (!COOLWSD::OverrideWatermark.empty())
watermarkText = COOLWSD::OverrideWatermark;
Expand Down

0 comments on commit 93b5bdf

Please sign in to comment.