From 0043ef02e09f134762ca34f49df14c7cdb4cf1c1 Mon Sep 17 00:00:00 2001 From: "David A. Cuadrado" Date: Thu, 27 Dec 2007 22:03:59 -0500 Subject: [PATCH] Finished permission support --- .../{commandprocessor.h => commandprocessor.cpp} | 41 ++--- src/dashserver/project/commandprocessor.h | 5 - src/dashserver/project/project.cpp | 205 ++++++++++++++++++++- src/dashserver/project/project.h | 3 +- src/dashserver/project/projectmanager.cpp | 2 +- src/dashserver/project/store.cpp | 4 +- src/dashserver/project/store.h | 2 +- 7 files changed, 225 insertions(+), 37 deletions(-) copy src/dashserver/project/{commandprocessor.h => commandprocessor.cpp} (72%) diff --git a/src/dashserver/project/commandprocessor.h b/src/dashserver/project/commandprocessor.cpp similarity index 72% copy from src/dashserver/project/commandprocessor.h copy to src/dashserver/project/commandprocessor.cpp index d5b730e..9b3d368 100644 --- a/src/dashserver/project/commandprocessor.h +++ b/src/dashserver/project/commandprocessor.cpp @@ -1,3 +1,5 @@ +// +// C++ Implementation: commandprocessor /*************************************************************************** * Copyright (C) 2007 by David Cuadrado * * krawek@gmail.com * @@ -18,39 +20,30 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ -#ifndef DASHSERVER_PROJECTCOMMANDPROCESSOR_H -#define DASHSERVER_PROJECTCOMMANDPROCESSOR_H +#include "commandprocessor.h" -#include -#include +#include "project.h" +#include "member.h" namespace DashServer { namespace Project { -class Project; -class Member; +struct CommandProcessor::Private { + Private() {} +}; -/** - * @author David Cuadrado -*/ -class DASHSERVER_EXPORT CommandProcessor : public YAMF::Command::Processor +CommandProcessor::CommandProcessor(Project *project) + : YAMF::Command::Processor(project), d(new Private) { - public: - CommandProcessor(Project *project); - virtual ~CommandProcessor(); - - void setCurrentMember(Member *member); - - protected: - virtual bool aboutToExecute(const QString &pkgname); - - private: - struct Private; - Private *const d; -}; +} + +CommandProcessor::~CommandProcessor() +{ + delete d; } + } -#endif +} diff --git a/src/dashserver/project/commandprocessor.h b/src/dashserver/project/commandprocessor.h index d5b730e..4812f57 100644 --- a/src/dashserver/project/commandprocessor.h +++ b/src/dashserver/project/commandprocessor.h @@ -39,11 +39,6 @@ class DASHSERVER_EXPORT CommandProcessor : public YAMF::Command::Processor CommandProcessor(Project *project); virtual ~CommandProcessor(); - void setCurrentMember(Member *member); - - protected: - virtual bool aboutToExecute(const QString &pkgname); - private: struct Private; Private *const d; diff --git a/src/dashserver/project/project.cpp b/src/dashserver/project/project.cpp index c9aa332..eab5922 100644 --- a/src/dashserver/project/project.cpp +++ b/src/dashserver/project/project.cpp @@ -87,18 +87,31 @@ Project::~Project() delete d; } -void Project::execute(const QString &xml, DashServer::Connection *source) +void Project::execute(const QString &cmdname, const QString &xml, DashServer::Connection *source) { if( d->connections.contains(source) ) { - d->processor->setCurrentMember( d->members.value(source->user()->login()) ); + Member *member = d->members.value(source->user()->login()); + int part = Project::partFromCommand(cmdname); + + if( ! member->canWriteOn(part) ) + { + source->sendError(tr("Permission denied"), Dash::Network::Package::Error::Err); + + source->sendToClient( "", true ); + return; + } + if( d->processor->execute(xml) ) { QString tosend = source->signXml(xml); foreach(DashServer::Connection *cnx, d->connections) { - cnx->sendToClient( tosend, false ); + if( d->members[cnx->user()->login()]->canReadOn(part) ) + { + cnx->sendToClient( tosend, false ); + } } } else @@ -291,6 +304,192 @@ QString Project::partName(int part) return QString(); } + +int Project::partFromCommand(const QString &pkgname) +{ + Project::Part part = Project::None; + + // LIBRARY + if( pkgname == "addlibraryfolder" ) + { + part = Project::Library; + } + else if( pkgname == "addlibraryobject" ) + { + part = Project::Library; + } + else if( pkgname == "modifysymbol" ) + { + part = Project::Library; + } + else if( pkgname == "renamelibraryobject" ) + { + part = Project::Library; + } + + + // OBJECT AND ITEM + if( pkgname == "additemfilter" ) + { + part = Project::Object; + } + else if( pkgname == "addobject" ) + { + part = Project::Object; + } + else if( pkgname == "addtweening" ) + { + part = Project::Object; + } + else if( pkgname == "bringforwardsitem" ) + { + part = Project::Object; + } + else if( pkgname == "bringtofrontitem" ) + { + part = Project::Object; + } + else if( pkgname == "changelayervisibility" ) + { + part = Project::Object; + } + else if( pkgname == "changetextfont" ) + { + part = Project::Object; + } + else if( pkgname == "changetext" ) + { + part = Project::Object; + } + else if( pkgname == "changetextwidth" ) + { + part = Project::Object; + } + else if( pkgname == "convertitem" ) + { + part = Project::Object; + } + else if( pkgname == "editnodesitem" ) + { + part = Project::Object; + } + else if( pkgname == "changeitembrush" ) + { + part = Project::Object; + } + else if( pkgname == "changeitempen" ) + { + part = Project::Object; + } + else if( pkgname == "groupitem" ) + { + part = Project::Object; + } + else if( pkgname == "modifyfilter" ) + { + part = Project::Object; + } + else if( pkgname == "modifyitem" ) + { + part = Project::Object; + } + else if( pkgname == "removelibraryobject" ) + { + part = Project::Object; + } + else if( pkgname == "removeobject" ) + { + part = Project::Object; + } + else if( pkgname == "sendbackwardsitem" ) + { + part = Project::Object; + } + else if( pkgname == "sendtobackitem" ) + { + part = Project::Object; + } + else if( pkgname == "ungroupitem" ) + { + part = Project::Object; + } + + + // FRAME + if( pkgname == "changeframevisibility" ) + { + part = Project::Frame; + } + else if( pkgname == "expandframe" ) + { + part = Project::Frame; + } + else if( pkgname == "insertframe" ) + { + part = Project::Frame; + } + else if( pkgname == "lockframe" ) + { + part = Project::Frame; + } + else if( pkgname == "moveframe" ) + { + part = Project::Frame; + } + else if( pkgname == "removeframe" ) + { + part = Project::Frame; + } + else if( pkgname == "renameframe" ) + { + part = Project::Frame; + } + + // LAYER + if( pkgname == "insertlayer" ) + { + part = Project::Layer; + } + else if( pkgname == "locklayer" ) + { + part = Project::Layer; + } + else if( pkgname == "movelayer" ) + { + part = Project::Layer; + } + else if( pkgname == "removelayer" ) + { + part = Project::Layer; + } + else if( pkgname == "renamelayer" ) + { + part = Project::Layer; + } + + + // SCENE + if( pkgname == "insertscene" ) + { + part = Project::Scene; + } + else if( pkgname == "movescene" ) + { + part = Project::Scene; + } + else if( pkgname == "removescene" ) + { + part = Project::Scene; + } + else if( pkgname == "renamescene" ) + { + part = Project::Scene; + } + + return part; +} + + } } diff --git a/src/dashserver/project/project.h b/src/dashserver/project/project.h index 8219992..f8833d4 100644 --- a/src/dashserver/project/project.h +++ b/src/dashserver/project/project.h @@ -52,7 +52,7 @@ class DASHSERVER_EXPORT Project : public Dash::Project, public XDBMS::Object Project(QObject *parent = 0); ~Project(); - void execute(const QString &xml, DashServer::Connection *source); + void execute(const QString &cmdname, const QString &xml, DashServer::Connection *source); void addClient(DashServer::Connection *cnx); void removeClient(DashServer::Connection *client); @@ -76,6 +76,7 @@ class DASHSERVER_EXPORT Project : public Dash::Project, public XDBMS::Object static QString partName(int part); + static int partFromCommand(const QString &cmdname); private: struct Private; diff --git a/src/dashserver/project/projectmanager.cpp b/src/dashserver/project/projectmanager.cpp index 0172609..1c0b406 100644 --- a/src/dashserver/project/projectmanager.cpp +++ b/src/dashserver/project/projectmanager.cpp @@ -71,7 +71,7 @@ void Manager::handlePackage(DashServer::Package* const pkg) if( pkg->root() == "command" ) { - if( !d->store->execute(pkg->xml(), pkg->source() ) ) + if( !d->store->execute(pkg->root(), pkg->xml(), pkg->source() ) ) { pkg->source()->sendError(QObject::tr("Cannot execute command"), Dash::Network::Package::Error::Err); } diff --git a/src/dashserver/project/store.cpp b/src/dashserver/project/store.cpp index 38a80f2..d7d3078 100644 --- a/src/dashserver/project/store.cpp +++ b/src/dashserver/project/store.cpp @@ -171,14 +171,14 @@ bool Store::contains(const QString &projectName) const return d->projects.contains(projectName); } -bool Store::execute(const QString &xml, DashServer::Connection *source) +bool Store::execute(const QString &cmdname, const QString &xml, DashServer::Connection *source) { QString projectName = source->data(ProjectName).toString(); if( d->projects.contains(projectName) ) { Project *project = d->projects.value(projectName); - project->execute(xml, source); + project->execute(cmdname, xml, source); return true; } diff --git a/src/dashserver/project/store.h b/src/dashserver/project/store.h index 80588df..bd47b13 100644 --- a/src/dashserver/project/store.h +++ b/src/dashserver/project/store.h @@ -52,7 +52,7 @@ class DASHSERVER_EXPORT Store void addToProject(const QString &projectName, DashServer::Connection *cnx); bool contains(const QString &projectName) const; - bool execute(const QString &xml, DashServer::Connection *source); + bool execute(const QString &cmdname, const QString &xml, DashServer::Connection *source); bool openProject(const QString &projectName, DashServer::Connection *source); -- 2.11.4.GIT