Skip to content

Commit

Permalink
Pass IsAdminUser property to the client
Browse files Browse the repository at this point in the history
- use app.isAdminUser for storing it
- use adminuser: message to pass it from the server
  which is sent before serveraudit: and after viewinfo:

Signed-off-by: Szymon Kłos <szymon.klos@collabora.com>
Change-Id: I993f34fc35d621bb83ead12f245541acdcb292a5
  • Loading branch information
eszkadev committed Jun 11, 2024
1 parent 05d6b1f commit 5861786
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 28 deletions.
14 changes: 2 additions & 12 deletions browser/src/control/Control.ServerAuditDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,6 @@ class ServerAuditDialog {
}

private onServerAudit() {
var docLayer = this.map._docLayer || {};
var viewInfo = this.map._viewInfo
? this.map._viewInfo[docLayer._viewId]
: null;

if (app.serverAudit.length) {
let hasErrors = false;
app.serverAudit.forEach((entry: any) => {
Expand All @@ -176,13 +171,8 @@ class ServerAuditDialog {
});

// only show the snackbar if there are specific warnings
// and if the current view is_admin
if (
hasErrors &&
viewInfo &&
viewInfo.userextrainfo &&
viewInfo.userextrainfo.is_admin === true
) {
// and if the current view isadminuser
if (hasErrors && app.isAdminUser) {
this.map.uiManager.showSnackbar(
_('Check security warnings of your server'),
_('OPEN'),
Expand Down
6 changes: 0 additions & 6 deletions browser/src/control/Control.UIManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -976,12 +976,6 @@ L.Control.UIManager = L.Control.extend({
this.map.zotero.updateUserID();
}
}

// if is_admin property is not set by integration - show audit dialog for all users
var userExtraInfo = myViewData.userextrainfo;
if (!userExtraInfo || userExtraInfo.is_admin !== false) {
this._map.serverAuditDialog = JSDialog.serverAuditDialog(this._map);
}
},

enterReadonlyOrClose: function() {
Expand Down
1 change: 1 addition & 0 deletions browser/src/docstate.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ window.app = {
roundedDpiScale: Math.round(window.devicePixelRatio),
canvasSize: null, // To be assigned SimplePoint.
viewId: null, // Unique view id of the user.
isAdminUser: null, // Is admin on the integrator side - used eg. to show update warnings
calc: {
cellAddress: null, // To be assigned SimplePoint.
cellCursorVisible: false,
Expand Down
14 changes: 13 additions & 1 deletion browser/src/layer/tile/CanvasTileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* L.CanvasTileLayer is a layer with canvas based rendering.
*/

/* global app L CanvasSectionContainer CanvasOverlay CDarkOverlay CSplitterLine $ _ CPointSet CPolyUtil CPolygon Cursor CCellCursor CCellSelection PathGroupType UNOKey UNOModifier Uint8ClampedArray Uint8Array Uint32Array */
/* global app L JSDialog CanvasSectionContainer CanvasOverlay CDarkOverlay CSplitterLine $ _ CPointSet CPolyUtil CPolygon Cursor CCellCursor CCellSelection PathGroupType UNOKey UNOModifier Uint8ClampedArray Uint8Array Uint32Array */

/*eslint no-extend-native:0*/
if (typeof String.prototype.startsWith !== 'function') {
Expand Down Expand Up @@ -1603,6 +1603,18 @@ L.CanvasTileLayer = L.Layer.extend({
var json = JSON.parse(textMsg.substr(12));
app.serverAudit = json.serverAudit;
app.map.fire('receivedserveraudit');
} else if (textMsg.startsWith('adminuser:')) {
var value = textMsg.substr(10).trim();
if (value === 'true')
app.isAdminUser = true;
else if (value === 'false')
app.isAdminUser = false;
else
app.isAdminUser = null;

// if isAdminUser property is not set by integration - show audit dialog for all users
if (app.isAdminUser !== false)
this._map.serverAuditDialog = JSDialog.serverAuditDialog(this._map);
}
},

Expand Down
6 changes: 1 addition & 5 deletions browser/src/map/handler/Map.VersionBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@ L.Map.VersionBar = L.Handler.extend({
},

onUpdateInfo: function () {
var docLayer = this._map._docLayer || {};
var viewInfo = this._map._viewInfo[docLayer._viewId];

if (viewInfo && viewInfo.userextrainfo &&
viewInfo.userextrainfo.is_admin) {
if (app.isAdminUser) {
var laterDate = new Date();
var currentDate = new Date();
var timeValue = window.prefs.getNumber('InfoBarLaterDate');
Expand Down
1 change: 1 addition & 0 deletions common/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Session::Session(const std::shared_ptr<ProtocolHandlerInterface> &protocol,
_isAllowChangeComments(false),
_haveDocPassword(false),
_isDocPasswordProtected(false),
_isAdminUser(false),
_watermarkOpacity(0.2),
_accessibilityState(false)
{
Expand Down
7 changes: 7 additions & 0 deletions common/Session.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ class Session : public MessageHandlerInterface

void setWatermarkText(const std::string& watermarkText) { _watermarkText = watermarkText; }

void setIsAdminUser(const bool isAdminUser) { _isAdminUser = isAdminUser; }

void setUserExtraInfo(const std::string& userExtraInfo) { _userExtraInfo = userExtraInfo; }

void setUserPrivateInfo(const std::string& userPrivateInfo) { _userPrivateInfo = userPrivateInfo; }
Expand Down Expand Up @@ -239,6 +241,8 @@ class Session : public MessageHandlerInterface

const std::string& getDocPassword() const { return _docPassword; }

bool getIsAdminUser() const { return _isAdminUser; }

const std::string& getUserExtraInfo() const { return _userExtraInfo; }

const std::string& getUserPrivateInfo() const { return _userPrivateInfo; }
Expand Down Expand Up @@ -347,6 +351,9 @@ class Session : public MessageHandlerInterface
/// Name of the user to whom the session belongs to, anonymized for logging.
std::string _userNameAnonym;

/// If user is admin on the integrator side
bool _isAdminUser;

/// Extra info per user, mostly mail, avatar, links, etc.
std::string _userExtraInfo;

Expand Down
3 changes: 2 additions & 1 deletion test/httpwstest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ void HTTPWSTest::testInactiveClient()
token == "tableselected:" ||
token == "colorpalettes:" ||
token == "jsdialog:" ||
token == "serveraudit:");
token == "serveraudit:" ||
token == "adminuser:");

// End when we get state changed.
return (token != "statechanged:");
Expand Down
15 changes: 12 additions & 3 deletions wsd/ClientSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2393,10 +2393,19 @@ bool ClientSession::handleKitToClientMessage(const std::shared_ptr<Message>& pay
#if !MOBILEAPP
if (tokens.equals(0, "viewinfo:"))
{
// send server audit results after we received information about users (who is admin)
const std::string message = std::string("serveraudit: ") + docBroker->getServerAudit();
bool status = forwardToClient(payload);
forwardToClient(std::make_shared<Message>(message, Message::Dir::In));

if (docBroker && !docBroker->isUnloading())
{
// send information about admin user
const std::string admin = std::string("adminuser: ") + std::string(getIsAdminUser() ? "true" : "false");
forwardToClient(std::make_shared<Message>(admin, Message::Dir::Out));

// send server audit results after we received information about users (who is admin)
const std::string serverAudit = std::string("serveraudit: ") + docBroker->getServerAudit();
forwardToClient(std::make_shared<Message>(serverAudit, Message::Dir::Out));
}

return status;
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions wsd/DocumentBroker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,7 @@ DocumentBroker::updateSessionWithWopiInfo(const std::shared_ptr<ClientSession>&
: wopiFileInfo->getWatermarkText();
const std::string templateSource = wopiFileInfo->getTemplateSource();

const bool isAdminUser = wopiFileInfo->getIsAdminUser();
if (!wopiFileInfo->getIsAdminUserError().empty())
_serverAudit.set("is_admin", wopiFileInfo->getIsAdminUserError());

Expand Down Expand Up @@ -1299,6 +1300,7 @@ DocumentBroker::updateSessionWithWopiInfo(const std::shared_ptr<ClientSession>&
session->setUserId(userId);
session->setUserName(username);
session->setUserExtraInfo(userExtraInfo);
session->setIsAdminUser(isAdminUser);
session->setUserPrivateInfo(userPrivateInfo);
session->setWatermarkText(watermarkText);

Expand Down

0 comments on commit 5861786

Please sign in to comment.