Remoto - VFS: aclEditor.cpp Source File
Remoto - VFS
aclEditor.cpp
Go to the documentation of this file.
1 
2 #include "VFS.h"
3 #include "VFS_icons.h"
4 #include "VFS_acl.h"
5 #include "utilities/rutils.h"
7 
8 #include "aclEditor.h"
9 
16 : VFS_application ()
17 {
18 }
19 
21 {
22 
23 }
24 
26 {
27  return false;
28 }
29 
30 QByteArray aclEditor::icon()
31 {
32  return "data:image/svg+xml;utf8,<svg class=\"menuIcon\" xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 32 32\"><g id=\"acl\"><rect x=\"3.36\" y=\"3.38\" width=\"25.67\" height=\"7.09\"/><ellipse fill=\"rgb(255,255,255)\" class=\"iconWhite\" cx=\"6.48\" cy=\"7.09\" rx=\"1.38\" ry=\"1.34\"/><rect fill=\"rgb(27,186,217)\" class=\"iconColor\" x=\"8.79\" y=\"4.59\" width=\"18.92\" height=\"4.68\" rx=\"2.34\" ry=\"2.34\"/><rect x=\"3.37\" y=\"11.84\" width=\"25.67\" height=\"7.09\"/><ellipse fill=\"rgb(255,255,255)\" class=\"iconWhite\" cx=\"6.48\" cy=\"15.55\" rx=\"1.38\" ry=\"1.34\"/><rect fill=\"rgb(27,186,217)\" class=\"iconColor\" x=\"8.79\" y=\"13.05\" width=\"18.92\" height=\"4.68\" rx=\"2.34\" ry=\"2.34\"/><rect x=\"3.38\" y=\"20.3\" width=\"25.67\" height=\"7.09\"/><ellipse fill=\"rgb(255,255,255)\" class=\"iconWhite\" cx=\"6.49\" cy=\"24.01\" rx=\"1.38\" ry=\"1.34\"/><rect fill=\"rgb(27,186,217)\" class=\"iconColor\" x=\"8.8\" y=\"21.5\" width=\"18.92\" height=\"4.68\" rx=\"2.34\" ry=\"2.34\"/></g></svg>";
33  //return VFS_icons::get("preferences");
34 }
35 
37 {
38  QJsonObject a;
39  a["type"] = "openLayout";
40 
41  r->_metadata["icon"] = QString(icon());
42  r->_metadata["action"] = a;
43 
44  QJsonObject l = rutils::jsonResource(":/admin/templates/basicLayout.json");
45  l["icon"] = "@icon@";
46  QJsonObject t;
47  t["openLayout"] = l;
48 
49  r->_metadata["template"] = t;
50  r->_metadata["where"] = "nearest";
51  r->_metadata["type"] = "aclEditor:aclEditor.js";
52  r->_success = true;
53 }
54 
56 {
57  //QJsonArray a = QJsonArray::fromStringList( VFS_acl::fetchACLPaths() );
58  QStringList l = VFS_acl::fetchACLPaths();
59  QJsonObject a;
60  for (int i=0;i<l.length();i++)
61  a[ l[i] ] = false;
62 
63  bool readwrite = VFS_acl::checkAllowAccess(r,"readwrite");
64 
65  QMutexLocker m(&VFS_tcp_mount::_mountsLock);
66 
67  QList<VFS_tcp_mount *> mounts = VFS_tcp_mount::_mounts;
68 
69  for (int i=0;i<mounts.length();i++)
70  {
71  if (mounts[i]->isMounted())
72  {
73  //a << mounts[i]->path()+"/__ACL__";
74  //printf("MOUNT: %s\n",qUtf8Printable(mounts[i]->path()+"/__ACL__"));
75  a[ mounts[i]->path()+"/__ACL__" ] = true;
76  }
77  }
78 
79  QJsonObject o;
80  o["paths"] = a;
81  o["readwrite"] = readwrite;
82  r->_data.setObject(o);
83 
84  r->_success = true;
85 }
86 
95 QString aclEditor::code(QString nodename, QString libname, QString &error)
96 {
97  if (libname == "aclEditor.js")
98  return rutils::resourceContents(":/admin/html/aclEditor.js");
99 
100  if (libname == "aclEditor.css")
101  return rutils::resourceContents(":/admin/html/aclEditor.css");
102 
103  return VFS_application::code(nodename,libname,error);
104 }
105 
107 {
108  QJsonObject acl;
109 
110  // allow by default
111  addACLDefault( acl, true );
112 
113  // add feature "readwrite"
114  addACLFeature( acl, "readwrite", true, "Allow editing ACL values.\n\nIt is recommended to set the default value to false once admin groups have been added.");
115  addACLFeatureGroup( acl, "readwrite", "admin", true ); // make "readwrite" true for "admin" by default
116  addACLFeatureGroup( acl, "readwrite", "developer", true ); // make "readwrite" true for "developer" by default
117 
118  r->_data.setObject(acl);
119  r->_success = true;
120 }
static bool checkAllowAccess(VFS_session *s, QString path, QString feature="")
Check if a session has access to a resource.
Definition: VFS_acl.cpp:407
static QStringList fetchACLPaths()
Fetch the VFS path to each registered ACL file.
Definition: VFS_acl.cpp:597
A common base class for all things that want to act like an application or include ACL support.
void addACLFeature(QJsonObject &acl, QString feature, bool value, QString description="")
Add a feature to the acl object.
Definition: VFS_node.cpp:2183
static QString code(QString nodename, QString libname, QString &error)
Fetch code or any other resource from a node.
Definition: VFS_node.cpp:1038
void addACLFeatureGroup(QJsonObject &acl, QString feature, QString group, bool value)
Add a feature group to the acl object.
Definition: VFS_node.cpp:2205
void addACLDefault(QJsonObject &acl, bool value, QString description="")
Add a default value to the acl object.
Definition: VFS_node.cpp:2131
The base class for all requests between nodes.
Definition: VFS_node.h:54
bool _success
if the request was successfully completed
Definition: VFS_node.h:107
QJsonDocument _data
the request payload
Definition: VFS_node.h:102
QJsonObject _metadata
the request payload
Definition: VFS_node.h:101
static QList< VFS_tcp_mount * > _mounts
The list of existing mounts.
Definition: VFS_tcp_mount.h:54
static QMutex _mountsLock
A mutex for modifying the _mounts entry.
Definition: VFS_tcp_mount.h:53
virtual void metadata(VFS_request *r)
Fetch the metadata of this node.
Definition: aclEditor.cpp:36
virtual QByteArray icon()
Fetch the application icon.
Definition: aclEditor.cpp:30
virtual void aclDefaults(VFS_request *r)
Return default values and features associated wth this node.
Definition: aclEditor.cpp:106
virtual bool isContainer()
A VFS_node may have children.
Definition: aclEditor.cpp:25
virtual ~aclEditor()
Definition: aclEditor.cpp:20
virtual void read(VFS_request *r)
Return the data contents of this node, or if it's a container call ls()
Definition: aclEditor.cpp:55
static QString code(QString nodename, QString libname, QString &error)
Fetch code from this node.
Definition: aclEditor.cpp:95
Q_INVOKABLE aclEditor()
Definition: aclEditor.cpp:15
setter error
Set the error value of this widget.
QJsonObject jsonResource(QString resource, bool *ok=nullptr)
Fetch the contents of a Qt resource as a QJsonObject.
Definition: rutils.cpp:90
QByteArray resourceContents(QString resource, bool *ok=nullptr, bool squashHash=false)
Fetch the contents of a Qt resource file.
Definition: rutils.cpp:53