--  
--  $Id$
--
--  This file is part of the OpenLink Software Virtuoso Open-Source (VOS)
--  project.
--  
--  Copyright (C) 1998-2018 OpenLink Software
--  
--  This project 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; only version 2 of the License, dated June 1991.
--  
--  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, write to the Free Software Foundation, Inc.,
--  51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
--  

set echo off;
set verbose off;
-- 'WikiAdmin' is for Wiki administrators, and 'Wiki' is the Almighty.
DB.DBA.USER_ROLE_CREATE ('WikiAdmin', 1);
-- 'WikiUsers' is for all Wiki users.
DB.DBA.USER_ROLE_CREATE ('WikiUser', 1);
-- 'Wiki' can do everything on Wiki and he is owner of VSP pages and procedures.
DB.DBA.USER_CREATE ('Wiki', 'Wiki', vector ('DAV_ENABLE', 1, 'SQL_ENABLE', 1, 'LOGIN_QUALIFIER', 'WV'));
user_set_password ('Wiki', 'Wiki');
--user_set_password ('Wiki', md5(cast (rnd(1000000000) as varchar)));
grant all privileges to "Wiki";
-- 'WikiGuest' is the user account for anonymous access.
DB.DBA.USER_CREATE ('WikiGuest', '', vector ('DAV_ENABLE', 1, 'SQL_ENABLE', 0, 'LOGIN_QUALIFIER', 'WV'));
-- No one of the following two lines work: error in handling SQL-disabled users?
--user_set_password ('WikiGuest', '');
--user_set_password ('WikiGuest', md5(cast (rnd(1000000000) as varchar)));
DB.DBA.USER_GRANT_ROLE ('Wiki', 'administrators', 0);
DB.DBA.USER_GRANT_ROLE ('Wiki', 'WikiAdmin', 1);
DB.DBA.USER_GRANT_ROLE ('Wiki', 'WikiUser', 1);
DB.DBA.USER_GRANT_ROLE ('WikiGuest', 'WikiUser', 0);
DB.DBA.USER_SET_QUALIFIER ('Wiki', 'WV');
DB.DBA.VHOST_DEFINE (lpath=>'/wiki/', ppath=>'/main.vsp', vsp_user=>'Wiki', opts=>vector('noinherit',1));
DB.DBA.VHOST_DEFINE (lpath=>'/wikiview/', ppath=>'/wikiview.vsp', vsp_user=>'Wiki', opts=>vector('noinherit',1));
DB.DBA.VHOST_DEFINE (lpath=>'/DAV/wikiview/', ppath=>'/wikiview.vsp', vsp_user=>'Wiki', opts=>vector('noinherit',1));
use "WV";
reconnect "Wiki";

load schema_on.sql;
load proc_on.sql;
load proc_on_vsp.sql;
load proc_on_macro.sql;
load proc_tmp.sql;

-- Preparing DAV
"CreateRootDavCollection" ();
"CreateGroup" ('WikiAdmin', 'WikiAdmin', 'A group of WikiV managers');
"CreateGroup" ('WikiUser', 'WikiUser', 'A group of all WikiV users');
"CreateUser" ('Wiki', 'WikiEngineAdmin', 'WikiAdmin', 'Main administrator of WikiV');
-- Preparing cluster for generic use
"CreateCluster" ('Main', 0, "WikiUId"(), "WikiAdminGId"());
-- Preparing cluster for Wiki doc and internal pages
"CreateCluster" ('Wiki', 0, "WikiUId"(), "WikiAdminGId"());
-- Preparing cluster for RDF imports (not yet in actual use but the name is reserved)
"CreateCluster" ('RawRDF', 0, "WikiUId"(), "WikiAdminGId"());
set echo on;
-- Loading initial set of pages, including docs.
"LoadClusterFromFiles" ('initial/Main', 'Main');
"LoadClusterFromFiles" ('initial/Wiki', 'Wiki');
