diff --git a/include/Group.h b/include/Group.h index a0d951e662..5d766f9852 100644 --- a/include/Group.h +++ b/include/Group.h @@ -118,6 +118,18 @@ public: return new Template; } + /** + * Sets suntone views in the group template if they are not set. Adds + * an attribute of the form: + * SUNSTONE=[ + * DEFAULT_VIEW = "cloud", + * GROUP_ADMIN_DEFAULT_VIEW = "groupadmin", + * GROUP_ADMIN_VIEWS = "cloud,groupadmin", + * VIEWS = "cloud" ] + */ + void sunstone_views(const string& user_default, const string& user_views, + const string& admin_default, const string& admin_views); + private: // ------------------------------------------------------------------------- diff --git a/src/group/Group.cc b/src/group/Group.cc index a4557d1958..3e6930c0cc 100644 --- a/src/group/Group.cc +++ b/src/group/Group.cc @@ -89,9 +89,7 @@ int Group::drop(SqlDB * db) int Group::insert(SqlDB *db, string& error_str) { - int rc; - - rc = insert_replace(db, false, error_str); + int rc = insert_replace(db, false, error_str); if (rc == 0) { @@ -493,3 +491,50 @@ void Group::del_admin_rules(int user_id) NebulaLog::log("GROUP",Log::ERROR,error_msg); } } + +/* ------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------ */ + +void Group::sunstone_views(const string& user_default, const string& user_views, + const string& admin_default, const string& admin_views) +{ + + VectorAttribute * sunstone = obj_template->get("SUNSTONE"); + + if ( sunstone == 0 ) + { + map vvalue; + + vvalue.insert(make_pair("DEFAULT_VIEW", user_default)); + vvalue.insert(make_pair("VIEWS", user_views)); + vvalue.insert(make_pair("GROUP_ADMIN_DEFAULT_VIEW", admin_default)); + vvalue.insert(make_pair("GROUP_ADMIN_VIEWS", admin_views)); + + sunstone = new VectorAttribute("SUNSTONE", vvalue); + + obj_template->set(sunstone); + } + else + { + if ( sunstone->vector_value("DEFAULT_VIEW").empty() ) + { + sunstone->replace("DEFAULT_VIEW", user_default); + } + + if ( sunstone->vector_value("VIEWS").empty() ) + { + sunstone->replace("VIEWS", user_views); + } + + if ( sunstone->vector_value("GROUP_ADMIN_DEFAULT_VIEW").empty() ) + { + sunstone->replace("GROUP_ADMIN_DEFAULT_VIEW", admin_default); + } + + if ( sunstone->vector_value("GROUP_ADMIN_VIEWS").empty() ) + { + sunstone->replace("GROUP_ADMIN_VIEWS", admin_views); + } + } +} + diff --git a/src/group/GroupPool.cc b/src/group/GroupPool.cc index 816b83e328..19b96f0a13 100644 --- a/src/group/GroupPool.cc +++ b/src/group/GroupPool.cc @@ -68,6 +68,8 @@ GroupPool::GroupPool(SqlDB * db, vector hook_mads, group = new Group(USERS_ID, USERS_NAME); + group->sunstone_views("cloud","cloud","group_admin","group_admin,cloud"); + rc = PoolSQL::allocate(group, error_str); if(rc < 0)