mira-dev team mailing list archive
-
mira-dev team
-
Mailing list archive
-
Message #00003
[Branch ~mira-dev/mira/trunk] Rev 186: Add Resource access list (Permissions) + fix bug in PlainTextDirectory::add_user/add_workplace
------------------------------------------------------------
revno: 186
committer: Alan Alvarez <aalvarez@xxxxxxxxxxxxx>
branch nick: trunk
timestamp: Sat 2009-10-31 01:49:42 -0500
message:
Add Resource access list (Permissions) + fix bug in PlainTextDirectory::add_user/add_workplace
added:
mira-server/include/Resource.h
modified:
mira-server/include/Field.h
mira-server/include/directory/Directory.h
mira-server/include/directory/plaintext/PlainTextDirectory.h
mira-server/src/main.cpp
--
lp:mira
https://code.launchpad.net/~mira-dev/mira/trunk
Your team Mira Core Development Team is subscribed to branch lp:mira.
To unsubscribe from this branch go to https://code.launchpad.net/~mira-dev/mira/trunk/+edit-subscription.
=== modified file 'mira-server/include/Field.h'
--- mira-server/include/Field.h 2008-08-22 07:57:11 +0000
+++ mira-server/include/Field.h 2009-10-31 06:49:42 +0000
@@ -1,3 +1,26 @@
+/*
+ * Field.h - by Alan Alvarez <alan.alvarez@xxxxxxxxxxx>
+ *
+ * Mira GroupWare
+ * Copyright (C) 2007-2009 Mira GroupWare Dev Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __MIRASERVER_FIELD_H
+#define __MIRASERVER_FIELD_H
+
#include <string>
#include <list>
@@ -50,3 +73,5 @@
std::string value;
std::list<std::string> value_list;
};
+
+#endif // __MIRASERVER__FIELD_H
=== added file 'mira-server/include/Resource.h'
--- mira-server/include/Resource.h 1970-01-01 00:00:00 +0000
+++ mira-server/include/Resource.h 2009-10-31 06:49:42 +0000
@@ -0,0 +1,122 @@
+/*
+ * Field.h - by Alan Alvarez <alan.alvarez@xxxxxxxxxxx>
+ *
+ * Mira GroupWare
+ * Copyright (C) 2007-2009 Mira GroupWare Dev Team
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef __MIRASERVER_RESOURCE_H
+#define __MIRASERVER_RESOURCE_H
+
+#include <string>
+#include <inttypes.h>
+
+class Resource
+{
+ public:
+ static const uint8_t READ_ACCESS = 0x01;
+ static const uint8_t WRITE_ACCESS = 0x10;
+ static const uint8_t READ_WRITE_ACCESS = 0x11;
+ static const uint8_t NO_ACCESS = 0x00;
+
+ Resource() : m_name(""), m_access_list()
+ {}
+
+ Resource(const std::string &name) : m_name(name), m_access_list()
+ {}
+
+ ~Resource()
+ {}
+
+ std::string get_name() const { return m_name; }
+
+ void set_access(const unsigned int user, const uint8_t access)
+ {
+ m_access_list[user] = access;
+ }
+ void give_read_access(const unsigned int user)
+ {
+ AccessListType::iterator Iter = m_access_list.find(user);
+ if (Iter != m_access_list.end())
+ Iter->second = READ_ACCESS | Iter->second;
+ else
+ set_access(user, READ_ACCESS);
+ }
+
+ void give_write_access(const unsigned int user)
+ {
+ AccessListType::iterator Iter = m_access_list.find(user);
+ if (Iter != m_access_list.end())
+ Iter->second = WRITE_ACCESS | Iter->second;
+ else
+ set_access(user, WRITE_ACCESS);
+ }
+
+ void remove_read_access(const unsigned int user)
+ {
+ AccessListType::iterator Iter = m_access_list.find(user);
+ if (Iter != m_access_list.end())
+ Iter->second = WRITE_ACCESS & Iter->second;
+
+ if (Iter->second == NO_ACCESS)
+ m_access_list.erase(Iter);
+ }
+
+ void remove_write_access(const unsigned int user)
+ {
+ AccessListType::iterator Iter = m_access_list.find(user);
+ if (Iter != m_access_list.end())
+ Iter->second = READ_ACCESS & Iter->second;
+
+ if (Iter->second == NO_ACCESS)
+ m_access_list.erase(Iter);
+ }
+
+ uint8_t get_access(const unsigned int user)
+ {
+ AccessListType::iterator Iter = m_access_list.find(user);
+ if (Iter != m_access_list.end())
+ return Iter->second;
+ else
+ return NO_ACCESS;
+ }
+
+ bool has_read_access(const unsigned int user)
+ {
+ return bool(get_access(user) & READ_ACCESS);
+ }
+
+ bool has_write_access(const unsigned int user)
+ {
+ return bool(get_access(user) & WRITE_ACCESS);
+ }
+
+ private:
+ friend class boost::serialization::access;
+ typedef std::map<unsigned int, uint8_t> AccessListType;
+
+ template<class Archive>
+ void serialize(Archive & ar, const unsigned int /* file_version */)
+ {
+ ar & BOOST_SERIALIZATION_NVP(m_name);
+ ar & BOOST_SERIALIZATION_NVP(m_access_list);
+ }
+
+ std::string m_name;
+ AccessListType m_access_list;
+};
+
+#endif // __MIRASERVER__FIELD_H
=== modified file 'mira-server/include/directory/Directory.h'
--- mira-server/include/directory/Directory.h 2008-08-24 19:59:32 +0000
+++ mira-server/include/directory/Directory.h 2009-10-31 06:49:42 +0000
@@ -28,6 +28,7 @@
#include "User.h"
#include "WorkPlace.h"
+#include "Resource.h"
namespace miraserver
{
@@ -46,14 +47,18 @@
virtual bool add_user(User& user) = 0;
virtual bool add_workplace(WorkPlace& workplace) = 0;
+ virtual bool add_resource(const Resource& resource) = 0;
virtual User find_user(const std::string& username) = 0;
virtual User find_user(const unsigned int user_id) = 0;
+
+ virtual Resource find_resource(const std::string& resource_name) = 0;
// Update User in backend
virtual bool update_user(const User& user) = 0;
// Update WorkPlace in backend
virtual bool update_workplace(const WorkPlace& workplace) = 0;
+ virtual bool update_resource(const Resource& resource) = 0;
virtual WorkPlace find_workplace(const std::string& workplace_name) = 0;
virtual WorkPlace find_workplace(const unsigned int workplace_id) = 0;
=== modified file 'mira-server/include/directory/plaintext/PlainTextDirectory.h'
--- mira-server/include/directory/plaintext/PlainTextDirectory.h 2009-10-30 22:46:18 +0000
+++ mira-server/include/directory/plaintext/PlainTextDirectory.h 2009-10-31 06:49:42 +0000
@@ -34,6 +34,7 @@
#include "Directory.h"
#include "User.h"
#include "WorkPlace.h"
+#include "Resource.h"
namespace miraserver
{
@@ -46,7 +47,7 @@
public:
PlainTextDirectory(const std::string &file_name) : Directory(), m_filename(file_name),
m_user_list(), m_workplace_list()
- { load(); }
+ { /*load();*/ }
virtual ~PlainTextDirectory()
{
@@ -62,7 +63,7 @@
if (m_user_list.size() > 0)
{
UserListType::iterator Iter = m_user_list.end();
- ++Iter;
+ --Iter;
user.set_id(Iter->first+1);
}
else
@@ -81,7 +82,7 @@
if (m_workplace_list.size() > 0)
{
WorkPlaceListType::iterator Iter = m_workplace_list.end();
- ++Iter;
+ --Iter;
workplace.set_id(Iter->first+1);
}
else
@@ -94,6 +95,21 @@
return ret_val;
}
+ virtual bool add_resource(const Resource& resource)
+ {
+ if (resource.get_name() != "")
+ {
+ bool ret_val = m_resource_list.insert(ResourceListType::value_type(resource.get_name(), resource)).second;
+ save();
+ return ret_val;
+ }
+ else
+ {
+ return false;
+ }
+
+ }
+
virtual User find_user(const unsigned int user_id)
{
UserListType::iterator Iter = m_user_list.find(user_id);
@@ -128,6 +144,19 @@
return WorkPlace();
}
+ virtual Resource find_resource(const std::string& resource_name)
+ {
+ ResourceListType::iterator Iter = m_resource_list.find(resource_name);
+ if (Iter != m_resource_list.end())
+ {
+ return Iter->second;
+ }
+ else
+ {
+ Resource("");
+ }
+ }
+
virtual bool update_user(const User& user)
{
UserListType::iterator Iter = m_user_list.find(user.get_id());
@@ -154,12 +183,28 @@
return false;
}
+ virtual bool update_resource(const Resource& resource)
+ {
+ ResourceListType::iterator Iter = m_resource_list.find(resource.get_name());
+ if (Iter != m_resource_list.end())
+ {
+ Iter->second = resource;
+ save();
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ }
+
void save();
void load();
private:
typedef std::map<unsigned int, User> UserListType;
typedef std::map<unsigned int, WorkPlace> WorkPlaceListType;
+ typedef std::map<std::string, Resource> ResourceListType;
friend class boost::serialization::access;
template<class Archive>
@@ -167,12 +212,14 @@
{
ar & BOOST_SERIALIZATION_NVP(m_user_list);
ar & BOOST_SERIALIZATION_NVP(m_workplace_list);
+ ar & BOOST_SERIALIZATION_NVP(m_resource_list);
}
std::string m_filename;
UserListType m_user_list;
WorkPlaceListType m_workplace_list;
+ ResourceListType m_resource_list;
};
} // namespace directory
=== modified file 'mira-server/src/main.cpp'
--- mira-server/src/main.cpp 2009-10-30 22:46:18 +0000
+++ mira-server/src/main.cpp 2009-10-31 06:49:42 +0000
@@ -36,6 +36,7 @@
#include "TcpConnection.h"
#include "field_defs.h"
#include "tools.h"
+#include "Resource.h"
using namespace miraserver;
using namespace directory;
@@ -93,8 +94,13 @@
field.value_list = std::list<std::string>(1, IntToString(mira.get_id()));
clsk.set_field(field);
Application::get_directory().update_user(clsk);
+
+
+ Resource server_new_user("server_new_user");
+ server_new_user.give_read_access(clsk.get_id());
+ server_new_user.give_write_access(clsk.get_id());
+ Application::get_directory().add_resource(server_new_user);
*/
-
}
catch (string error)
{