---------------------------------------------------------
-- Une seule fois par DB donner les droits de base
---------------------------------------------------------
-- anb

DO $$
BEGIN
    -- Créer le rôle bierlaire_normal s'il n'existe pas
    IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'nasani_normal') THEN
        CREATE ROLE nasani_normal;
    END IF;

    -- Créer le rôle nasani_lecture s'il n'existe pas
    IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'nasani_lecture') THEN
        CREATE ROLE nasani_lecture;
    END IF;

    -- Créer le rôle nasani_admin s'il n'existe pas
    IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'nasani_admin') THEN
        CREATE ROLE nasani_admin;
    END IF;

    -- Créer le rôle nasani_admin s'il n'existe pas
    IF NOT EXISTS (SELECT FROM pg_roles WHERE rolname = 'nasani_web') THEN
        CREATE ROLE nasani_web;
    END IF;
END
$$;

GRANT SELECT ON utilisateur, disponibilite TO nasani_normal, nasani_admin;
GRANT ALL ON utilisateur, disponibilite TO nasani_admin;

GRANT SELECT ON prospectbien_lastpub TO nasani_normal, nasani_admin;
GRANT SELECT ON prospectbien_lastpub TO nasani_web ;
GRANT ALL ON prospectbien_lastpub TO nasani_admin;


GRANT SELECT ON signatures TO nasani_normal, nasani_admin;
GRANT SELECT ON signatures TO nasani_web ;
GRANT ALL ON signatures TO nasani_admin;



GRANT SELECT ON utilisateur, disponibilite TO nasani_normal, nasani_admin;
GRANT ALL ON utilisateur, disponibilite TO nasani_admin;

DO $$
BEGIN
    IF EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = 'mandat') AND
       EXISTS (SELECT FROM pg_tables WHERE schemaname = 'public' AND tablename = 'mandat_observation_t') THEN
        GRANT SELECT ON mandat, mandat_observation_t TO nasani_normal, nasani_admin;
        GRANT ALL ON mandat_observation TO nasani_admin;
GRANT ALL ON mandat_observation_t TO nasani_admin;
GRANT ALL ON mandat_t TO nasani_admin;
GRANT ALL ON mandat TO nasani_admin;

GRANT select ON mandat_observation TO nasani_normal;
GRANT select ON mandat_observation_t TO nasani_normal;
GRANT select ON mandat_t TO nasani_normal;
GRANT select ON mandat TO nasani_normal;


GRANT select, insert on mandat_observation to nasani_admin, nasani_normal;
GRANT select on mandat_observation to nasani_lecture ;



CREATE SEQUENCE IF NOT EXISTS public.mandat_mandant_nmandant_seq
  INCREMENT 1 MINVALUE 1
  MAXVALUE 9223372036854775807 START 1
  CACHE 1 OWNED BY public.mandat_mandant.nmandant;

CREATE SEQUENCE IF NOT EXISTS public.mandat_nmandat_seq
  INCREMENT 1 MINVALUE 1
  MAXVALUE 9223372036854775807 START 1
  CACHE 1 OWNED BY NONE;

GRANT USAGE ON SEQUENCE mandat_observation_nobservation_seq TO nasani_normal,nasani_admin ;
GRANT USAGE ON SEQUENCE mandat_nmandat_seq TO nasani_normal,nasani_admin ;
GRANT select, insert, update ON mandat TO nasani_normal,nasani_admin ;
GRANT select, insert, update ON mandat_observation TO nasani_normal,nasani_admin ;

    END IF;
END
$$;





GRANT SELECT ON biencrit, agenda, prospectbien  TO nasani_normal, nasani_admin;
GRANT select, insert, update, delete on biencrit, agenda, prospectbien TO nasani_normal, nasani_admin;
--GRANT select, insert, update, delete on ids TO nasani_normal, nasani_admin;

--GRANT SELECT ON biencritfirst  TO nasani_normal, nasani_admin;
GRANT SELECT ON biencritfirst  TO nasani_normal, nasani_admin;
GRANT select, insert, update, delete on biencritfirst TO nasani_normal, nasani_admin;


GRANT EXECUTE  ON ALL FUNCTIONS IN SCHEMA public to nasani_lecture ,nasani_normal , nasani_admin ;

grant all on doc to nasani_normal,nasani_admin;


GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO nasani_normal, nasani_admin;


GRANT all on statutlead TO nasani_admin ;
GRANT select on statutlead TO nasani_normal ;
--GRANT select on ids TO nasani_normal ;


GRANT ALL ON agenda ,bien,biencrit ,detailbien ,doc ,htmlbien ,offre   ,photo  ,preference  ,prospect  ,prospectbien,prospectbienrv	to nasani_admin, nasani_normal ;
GRANT SELECT ON agenda ,bien,biencrit ,detailbien ,doc ,htmlbien ,offre   ,photo  ,preference  ,prospect  ,prospectbien,prospectbienrv	to nasani_lecture ;

GRANT all on typdetailmeta TO nasani_admin ;
GRANT select on typdetailmeta TO nasani_normal ;
GRANT select on typdetailmeta TO nasani_normal ;
GRANT select on typdetailmeta to nasani_normal,nasani_admin, nasani_lecture ;
GRANT select,insert,update on typdetailmeta to nasani_admin ;
GRANT select, insert, update, delete on preference TO nasani_admin,nasani_normal ;
GRANT select on preference TO nasani_lecture;
GRANT select, insert, update, delete on prospectbien TO nasani_admin,nasani_normal ;
GRANT select on prospectbien  TO nasani_lecture;
GRANT select, update on params TO nasani_admin,nasani_normal ;
GRANT select on params  TO nasani_lecture;
GRANT select, update on params TO nasani_admin,nasani_normal ;
GRANT select on params  TO nasani_lecture;
GRANT select, insert, update, delete on prospect TO nasani_admin,nasani_normal ;
GRANT select on prospect  TO nasani_lecture;
GRANT select, insert, update, delete on biencrit TO nasani_admin,nasani_normal ;
GRANT select on biencrit  TO nasani_lecture;
--GRANT execute on strip_nulls to nasani_admin , nasani_normal, nasani_lecture;
GRANT select, insert, update, delete on biencrit TO nasani_admin,nasani_normal ;
GRANT select on biencrit  TO nasani_lecture;
GRANT all on prospect TO nasani_admin ;
GRANT select,insert,update,delete on prospect TO nasani_normal ;
GRANT select on prospect TO nasani_normal ;
GRANT ALL ON prospect , prospectbien, bien, biencrit to nasani_admin, nasani_normal ;
GRANT SELECT ON prospect , prospectbien, bien, biencrit to nasani_lecture, nasani_normal ;
GRANT all on biencrit to nasani_admin, nasani_normal;
GRANT select on biencrit to nasani_lecture ;

GRANT select on mandat to nasani_lecture ;
GRANT update,insert on mandat to nasani_admin, nasani_normal;

GRANT select, insert on mandat_observation to nasani_admin, nasani_normal;
GRANT select on mandat_observation to nasani_lecture ;

GRANT USAGE, SELECT ON SEQUENCE nphoto TO nasani_admin, nasani_normal;

ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT execute ON FUNCTIONS TO nasani_normal,nasani_admin,nasani_lecture;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE ON SEQUENCES TO nasani_normal,nasani_admin,nasani_lecture;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO nasani_normal,nasani_admin,nasani_lecture;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT,INSERT,UPDATE,DELETE ON TABLES TO nasani_admin;
ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT REFERENCES,TRIGGER,RULE ON TABLES TO nasani_normal,nasani_admin,nasani_lecture;



--biencrit       biencritnego  detailbien  detailprospect  doc   htmlbien   photo  preference    prospectbien  prospectselectionitem   publication selection    selectionitem
--todo   bien   prospect portailagence
-- detailprospectbien     offre  statutoffre comnego    detailprospectbien  agenda   prospectbienrv    bien,prospect,utilisateuragence,agence,preference

--REFERENCES,TRIGGER,RULE

-----------------------------------------------------
-- Création et construction du groupe admin de dbname
-----------------------------------------------------


grant all on agence to group nasani_admin ;

-- Annulé le 19/10/2005
-- grant all on bien_t to group nasani_admin ;
-- grant all on prospect_t to group nasani_admin ;

grant all on biencrit to group nasani_admin ;
grant all on biencritnego to group nasani_admin ;
grant all on biendef to group nasani_admin ;
grant all on cat to group nasani_admin ;
grant select,update,insert on colors to group nasani_admin ;
grant all on converter to group nasani_admin ;
grant all on dept to group nasani_admin ;
grant all on detail to group nasani_admin ;
grant all on detailbien to group nasani_admin ;
grant all on detailprospect to group nasani_admin ;
grant all on disponibilite to group nasani_admin ;
grant all on doc to group nasani_admin ;
grant all on environnement to group nasani_admin ;
grant all on etat to group nasani_admin ;
grant all on htmlbien to group nasani_admin ;
grant all on htmlpage to group nasani_admin ;
grant all on htmlpageext to group nasani_admin ;
grant all on langue to group nasani_admin ;
grant all on natmandat to group nasani_admin ;
grant all on naturebien to group nasani_admin ;
grant all on originebien to group nasani_admin ;
grant all on origineprospect to group nasani_admin ;
grant all on pays to group nasani_admin ;
grant all on photo to group nasani_admin ;
grant all on polit to group nasani_admin ;
grant all on preference to group nasani_admin ;
grant all on privilege to group nasani_admin ;
grant all on prixann to group nasani_admin ;
grant all on prospectbien to group nasani_admin ;
grant all on prospectdef to group nasani_admin ;
grant all on prospectselectionitem to group nasani_admin ;
grant all on publication to group nasani_admin ;
grant all on region to group nasani_admin ;
grant all on regionmeta to group nasani_admin ;
grant all on regmat to group nasani_admin ;
grant all on rubrique to group nasani_admin ;
grant all on rubriquedef to group nasani_admin ;
grant all on selection to group nasani_admin ;
grant all on selectionitem to group nasani_admin ;
grant all on sequences to group nasani_admin ;
grant all on style to group nasani_admin ;
grant all on taux to group nasani_admin ;
grant all on texture to group nasani_admin ;
grant all on todo to group nasani_admin ;

grant all on trancheprix to group nasani_admin ;
grant all on typ to group nasani_admin ;
grant all on typchauf to group nasani_admin ;
grant all on typcivilite to group nasani_admin ;
grant all on typcuisine to group nasani_admin ;
grant all on typdetail to group nasani_admin ;
grant all on typdetailmeta to group nasani_admin ;

grant all on typmandat to group nasani_admin ;
grant all on typmeta to group nasani_admin ;
grant all on typrelation to group nasani_admin ;
grant all on typsexe to group nasani_admin ;
grant all on utilisateur to group nasani_admin ;
grant all on utilisateuragence to group nasani_admin ;
grant all on ville to group nasani_admin ;
--
grant all on bien to group nasani_admin ;
grant all on prospect to group nasani_admin ;

GRANT EXECUTE ON FUNCTION "public"."getprospects4" (integer) TO GROUP nasani_admin;

-------------------------------------------------------
-- Création du groupe consultation seule  nasani_lecture
-------------------------------------------------------

--CREATE GROUP "nasani_lecture";
grant select on agence to group  nasani_lecture ;

-- Annulé le 19/10/2005
-- grant all on bien_t to group nasani_admin ;
-- grant all on prospect_t to group nasani_admin ;


grant select,REFERENCES,TRIGGER on biencrit to group  nasani_lecture ;
grant select on biencritnego to group  nasani_lecture ;
grant select on biendef to group  nasani_lecture ;
grant select on cat to group  nasani_lecture ;
grant select,update,insert on colors to group  nasani_lecture ;
grant select on converter to group  nasani_lecture ;
grant select on dept to group  nasani_lecture ;
grant select on detail to group  nasani_lecture ;
grant select on detailbien to group  nasani_lecture ;
grant select on detailprospect to group  nasani_lecture ;
grant select on disponibilite to group  nasani_lecture ;
grant select on doc to group  nasani_lecture ;
grant select on environnement to group  nasani_lecture ;
grant select on etat to group  nasani_lecture ;
grant select on htmlbien to group  nasani_lecture ;
grant select on htmlpage to group  nasani_lecture ;
grant select on htmlpageext to group  nasani_lecture ;
grant select on langue to group  nasani_lecture ;
grant select on natmandat to group  nasani_lecture ;
grant select on naturebien to group  nasani_lecture ;
grant select on originebien to group  nasani_lecture ;
grant select on origineprospect to group  nasani_lecture ;
grant select on pays to group  nasani_lecture ;
grant select on photo to group  nasani_lecture ;
grant select on polit to group  nasani_lecture ;
grant select on preference to group  nasani_lecture ;
grant select on privilege to group  nasani_lecture ;
grant select on prixann to group  nasani_lecture ;

grant select on prospectbien to group  nasani_lecture ;
grant select on prospectdef to group  nasani_lecture ;
grant select on prospectselectionitem to group  nasani_lecture ;
grant select on publication to group  nasani_lecture ;
grant select on region to group  nasani_lecture ;
grant select on regionmeta to group  nasani_lecture ;
grant select on regmat to group  nasani_lecture ;
grant select on rubrique to group  nasani_lecture ;
grant select on rubriquedef to group  nasani_lecture ;
grant select,insert,update,delete on selection to group  nasani_lecture ;
grant select,insert,update,delete on selectionitem to group  nasani_lecture ;
grant select on sequences to group  nasani_lecture ;
grant select on style to group  nasani_lecture ;
grant select on taux to group  nasani_lecture ;
grant select on texture to group  nasani_lecture ;
grant select on todo to group  nasani_lecture ;

grant select on trancheprix to group  nasani_lecture ;
grant select on typ to group  nasani_lecture ;
grant select on typchauf to group  nasani_lecture ;
grant select on typcivilite to group  nasani_lecture ;
grant select on typcuisine to group  nasani_lecture ;
grant select on typdetail to group  nasani_lecture ;
grant select on typdetailmeta to group  nasani_lecture ;
grant select on typmandat to group  nasani_lecture ;
grant select on typmeta to group  nasani_lecture ;
grant select on typrelation to group  nasani_lecture ;
grant select on typsexe to group  nasani_lecture ;
grant select on utilisateur to group  nasani_lecture ;
grant select on utilisateuragence to group  nasani_lecture ;
grant select on ville to group  nasani_lecture ;

-- Modifié de select a all pour permettre la modification, etc.
grant select on bien to group  nasani_lecture ;
grant select on prospect to group  nasani_lecture ;

GRANT EXECUTE ON FUNCTION "public"."getprospects4" (integer) TO GROUP  nasani_lecture;

---------------------------------------------------------------------------------------------------------
-- Profil d'utilisation normal permettant la saisie de bien et contact mais sans aucune personnalisation
---------------------------------------------------------------------------------------------------------

--CREATE GROUP "nasani_normal";
grant select on agence to group  nasani_normal ;

-- Annulé le 19/10/2005
-- grant all on bien_t to group nasani_admin ;
-- grant all on prospect_t to group nasani_admin ;


grant select,update,insert,delete, REFERENCES,TRIGGER,RULE on biencrit to group  nasani_normal ;
grant select,update,insert,delete on biencritnego to group  nasani_normal ;
GRANT SELECT,INSERT,UPDATE,DELETE ON biencrit TO nasani_normal;
GRANT SELECT,INSERT,UPDATE,DELETE ON biencritnego TO nasani_normal;
GRANT SELECT ON biendef, cat, converter, dept, detail, environnement, etat, htmlpage, htmlpageext, langue, natmandat, naturebien, originebien, origineprospect, pays, polit, privilege, prixann, prospectdef, region, regionmeta, regmat, rubrique, rubriquedef, style, taux, texture, trancheprix, typ, typchauf, typcivilite, typcuisine, typdetail, typdetailmeta, typmandat, typmeta, typrelation, typsexe, utilisateur, utilisateuragence, ville TO group nasani_normal;

GRANT SELECT, UPDATE, INSERT, DELETE ON colors, detailbien, detailprospect, doc, htmlbien, photo, preference, prospectbien, prospectselectionitem, publication, selection, selectionitem, sequences, todo TO group nasani_normal;

-- Vues
grant select,update,insert,delete on bien to group  nasani_normal ;
grant select,update,insert,delete on prospect to group  nasani_normal ;

grant select,update,delete,insert on detailprospectbien to nasani_admin ;
grant select,update,delete,insert on offre to nasani_admin;
grant select,update,delete,insert on statutoffre to nasani_admin;
grant select,update,delete,insert on comnego to nasani_admin;

grant select on detailprospectbien to  nasani_lecture ;
grant select on offre to  nasani_lecture ;
grant select on statutoffre to  nasani_lecture ;
grant select on comnego to  nasani_lecture ;

grant select,update,delete,insert on detailprospectbien to  nasani_normal ;
grant select,update,insert on offre to  nasani_normal;
grant select on statutoffre to  nasani_normal;
grant select on comnego to  nasani_normal;


grant all privileges on agenda to  nasani_normal ;
grant all privileges on deletebienlog_nid_seq to  nasani_normal ;
grant all privileges on deleteprospectlog_nid_seq to  nasani_normal ;
grant all privileges on prospectbienrv to  nasani_normal ;


grant select,insert on deletebienlog to  nasani_normal ;
grant select,insert on deleteprospectlog to  nasani_normal ;


grant select on typorientation to  nasani_normal ;
grant all privileges on typorientation to nasani_admin ;

grant all on bien,prospect,utilisateuragence,agence,preference to nasani_admin ;
grant all on bien,prospect,utilisateuragence,agence,preference to nasani_normal ;
grant all on biencrit to nasani_admin ;
GRANT ALL ON FUNCTION f_validatedeletebien() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validatedeletedoc() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validatedeletehisto() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validatedeleteproprio() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validatedeleteprospect() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validateinsertbien() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validateinsertdoc() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validateinserthisto() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validateinsertproprio() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validateinsertprospect() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validateupdatebien() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validateupdatedoc() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validateupdatehisto() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validateupdateproprio() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION f_validateupdateprospect() TO  nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON FUNCTION getprospects5(integer, integer) TO nasani_normal,nasani_admin,nasani_lecture;
GRANT ALL ON SEQUENCE public.deletebienlog_nid_seq TO nasani_normal, nasani_admin,nasani_lecture ;
GRANT ALL ON SEQUENCE public.deleteprospectlog_nid_seq TO nasani_normal, nasani_admin,nasani_lecture ;
GRANT ALL ON SEQUENCE public.lead_nlead_seq TO nasani_normal, nasani_admin,nasani_lecture ;
GRANT execute ON FUNCTION f_build_select( biencrit_t) TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_convert( text,  text,  text) TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_epoch(timestamp without time zone)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_get_nbevent( integer,  integer,  integer, OUT  bigint) TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_get_nbevents( integer,  integer,  integer, OUT  bigint) TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_getbienpot(integer)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_getconverter( text,  text)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_getconverter( text,  text,  text)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_getnrelation( integer,  integer,  text)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_getnrelation( integer,  text) TO nasani_normal,nasani_admin,nasani_lecture;
grant execute on function f_getrepo(character varying,timestamp without time zone) TO nasani_admin ;
GRANT execute ON FUNCTION f_getrepo(character varying,timestamp without time zone) TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_insertdeleteprospectlog()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_nextval(as_csequence text)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_nvl(character varying)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_audit()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_biencrit_lsql()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_ncouleur() TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_ncouleurtexte()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_agence() TO nasani_normal,nasani_admin,nasani_lecture;
--GRANT execute ON FUNCTION f_set_nextval_portailagence()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_bien_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_biencrit_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_biencritnego()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_biendef()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_cat()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_commoffre()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_comnego()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_detail()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_detailbien_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_detailoption()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_detailprospect()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_detailprospectbien()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_disponibilite()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_doc_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_htmlpage()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_htmlpageext()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_log()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_natmandat()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_offre_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_photo_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_pige()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_preference_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_privilege()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_prixann()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_prospect_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_prospectbien_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_prospectdef()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_prospectselectionitem()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_publication()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_regmat()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_role()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_rubrique()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_selection()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_selectionitem()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_statutbien()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_todo()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_trancheprix()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_typcuisine()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_typdetail()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_typrelation()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_ville()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nextval_webpreferences()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_agence()  TO nasani_normal,nasani_admin,nasani_lecture;
--GRANT execute ON FUNCTION f_set_nexval_portailagence()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_bien_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_biencrit_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_biencritnego()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_biendef()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_cat()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_commoffre()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_comnego()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_detail()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_detailbien_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_detailoption()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_detailprospect()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_detailprospectbien()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_disponibilite()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_doc_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_htmlpage()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_htmlpageext()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_log()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_natmandat()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_offre_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_photo_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_pige()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_preference_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_privilege()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_prixann()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_prospect_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_prospectbien_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_prospectdef()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_prospectselectionitem()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_publication()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_regmat()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_role()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_rubrique()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_selection()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_selectionitem()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_statutbien()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_todo()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_trancheprix()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_typcuisine()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_typdetail()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_typrelation()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nexval_ville()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_nordre_photo_t()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_set_photo_n1()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_updatedmod()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_utc(timestamp without time zone)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_utf(timestamp without time zone)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION f_validatedeletebien()  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION getprospects4(integer)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION getprospects5(integer, integer)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION getprospects5(integer, text)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION lcase(integer)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION lcase(text) TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION lower(integer) TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION ucase(integer) TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION ucase(text)  TO nasani_normal,nasani_admin,nasani_lecture;
GRANT execute ON FUNCTION upper(integer)  TO nasani_normal,nasani_admin,nasani_lecture;
-- Combined insert permissions for specific logs
GRANT INSERT ON deletebienlog, deleteprospectlog, log TO nasani_normal, nasani_admin, nasani_lecture;

-- Combined select and insert permissions for specific logs
GRANT SELECT, INSERT ON deletebienlog, deleteprospectlog TO nasani_normal, nasani_admin, nasani_lecture;

-- Grant role permissions
GRANT nasani_lecture TO nasani_web;
-- Select permissions on tables specific to nasani_web role
GRANT SELECT ON bien_t, detailbien_t, htmlbien_t, photo_t, portailagence, prospectbien_t, prospect_t TO nasani_web;



-- Select permissions on various tables for nasani_lecture, removing duplicates
GRANT SELECT ON portailagence, agenda, bien, biencrit, detailbien, doc, htmlbien, lead, mitoyennete,  offre, photo, preference, prospect, prospectbien, role, statutbien, typmandatmeta, typorientation, webpreferences TO nasani_lecture;


-- Combined select permissions for biencrit, prospect, statutbien, typmandatmeta to various roles
GRANT SELECT ON biencrit, prospect, statutbien, typmandatmeta TO nasani_normal, nasani_admin, nasani_lecture;

-- Additional permissions
GRANT SELECT ON privilege TO nasani_normal, nasani_lecture, nasani_admin;

-- Permissions for nasani_normal
GRANT SELECT, INSERT, UPDATE ON bien, detailbien, doc, intervenant, mandat, mitoyennete, offre, portailagence, prospect, role, statutbien, statutmandat, typmandatmeta, typorientation TO nasani_normal;

-- Combined permissions for nasani_admin and nasani_normal
GRANT SELECT, INSERT, UPDATE, DELETE ON agenda, bien, biencrit, detailbien, doc, htmlbien, lead,  offre, photo, preference, prospect, prospectbien, typmandatmeta, utilisateuragence, webpreferences TO nasani_admin, nasani_normal;

-- mnemotpl

grant select, insert, update,delete on utilisateur TO nasani_admin ;
grant select, insert, update,delete on biendef TO nasani_admin ;
grant select, insert, update,delete on prospectdef TO nasani_admin ;

grant select, insert, update,delete on utilisateur TO nasani_normal ;

grant select, insert, update,delete on biendef TO nasani_normal ;
grant select, insert, update,delete on prospectdef TO nasani_normal ;

grant select on utilisateur TO nasani_lecture ;

grant select on biendef TO nasani_lecture ;
grant select on prospectdef TO nasani_lecture ;
--grant select on couverture TO nasani_lecture ;
--grant select on typfenetre TO nasani_lecture ;
--grant select on typassainissement TO nasani_lecture ;
grant select on typpiscine TO nasani_lecture ;

grant select, insert, update,delete on etat TO nasani_admin ;
grant select, insert, update on etat TO nasani_normal ;
grant select on etat TO nasani_lecture ;
--grant select on couverture TO nasani_lecture ;
--grant select on typfenetre TO nasani_normal ;
--grant select on typassainissement TO nasani_normal ;
grant select on typpiscine TO nasani_normal ;

GRANT SELECT, INSERT, UPDATE, DELETE ON bien, detailbien, doc, intervenant, mandat, mitoyennete, offre, portailagence, prospect, role, statutbien, statutmandat, typmandatmeta, typorientation, typpiscine, utilisateuragence TO nasani_admin;

-- The commented grants are as follows, uncomment if needed
-- GRANT SELECT, INSERT, UPDATE, DELETE ON couverture, typfenetre, typassainissement TO nasani_admin;

grant select on disponibilite TO nasani_lecture ;



grant select on preference_t to nasani_lecture ;
grant select on preference_t to nasani_normal ;

grant all on preference_t to nasani_admin ;

grant select on tpl to nasani_lecture ;
grant select on tpl to nasani_normal ;
grant all on tpl to nasani_admin ;

GRANT SELECT ON ALL TABLES IN SCHEMA public TO nasani_normal ;
GRANT SELECT,INSERT,UPDATE,DELETE ON ALL TABLES IN SCHEMA public TO nasani_admin ;

GRANT EXECUTE  ON ALL FUNCTIONS IN SCHEMA public to nasani_lecture ,nasani_normal , nasani_admin ;
GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO nasani_normal, nasani_admin;


GRANT USAGE, SELECT ON SEQUENCE nphoto TO nasani_normal, nasani_admin ;


grant select on tpl TO nasani_lecture ;
grant select, insert, update,delete on tpl TO nasani_admin, nasani_normal ;
grant select, insert, update,delete on tpl TO nasani_admin ;


grant select on preference_t TO nasani_lecture ;
grant select on preference_t TO nasani_admin ;


grant select on agencereport TO nasani_lecture ;
grant select, insert, update,delete on agencereport TO nasani_admin, nasani_normal ;
grant select, insert, update,delete on agencereport TO nasani_admin ;

-- prospectbien_lastpub
grant select on prospectbien_lastpub TO nasani_lecture ;
grant select, insert, update,delete on prospectbien_lastpub TO nasani_admin, nasani_normal ;
grant select, insert, update,delete on prospectbien_lastpub TO nasani_admin ;




CREATE EXTENSION IF NOT EXISTS unaccent;

--GRANT execute ON SEQUENCES TO nasani_normal,nasani_admin,nasani_lecture;

--GRANT USAGE ON SEQUENCES TO nasani_normal,nasani_admin,nasani_lecture;
--GRANT SELECT ON TABLES TO nasani_normal,nasani_admin,nasani_lecture;
--GRANT SELECT,INSERT,UPDATE,DELETE ON TABLES TO nasani_admin;
--GRANT REFERENCES,TRIGGER,RULE ON TABLES TO nasani_normal,nasani_admin,nasani_lecture;
--GRANT ALL ON SEQUENCES TO nasani_normal,nasani_admin,nasani_lecture;








-- grant select on prospectrel to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select,insert,update,delete on prospectrel to nasani_admin, nasani_normal ;

-- grant select on prospectrel to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select,insert,update,delete on prospectrel to nasani_admin, nasani_normal ;

-- GRANT USAGE, SELECT ON SEQUENCE agencereport_nagencereport_seq TO nasani_admin,nasani_normal;
-- grant select on agencereport to nasani_lecture ;
-- grant select,insert,update,delete on agencereport to nasani_admin,nasani_normal,nasani_lecture ;
-- grant all on agencereport to nasani_admin ;

-- GRANT USAGE, SELECT ON SEQUENCE agencereport_nagencereport_seq TO nasani_admin, nasani_normal;
-- grant select on agencereport to nasani_lecture ;
-- grant select,insert,update,delete on agencereport to nasani_admin, nasani_normal,nasani_lecture ;
-- grant all on agencereport to nasani_admin ;



-- grant select on prospect to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select on prospectbien to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select on bien to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select on preference to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select on htmlbien to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select on biencrit to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select on photo to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select on agenda to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select on mandat to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select on mandat_observation to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select on offre to nasani_admin, nasani_normal,nasani_lecture ;
-- grant select on doc to nasani_admin, nasani_normal,nasani_lecture ;

-- grant select,insert,update,delete on prospect to nasani_admin, nasani_normal ;
-- grant select,insert,update,delete on prospectbien to nasani_admin, nasani_normal ;
-- grant select,insert,update,delete on bien to nasani_admin, nasani_normal ;
-- grant select,insert,update,delete on preference to nasani_admin, nasani_normal ;
-- grant select,insert,update,delete on htmlbien to nasani_admin, nasani_normal ;
-- grant select,insert,update,delete on biencrit to nasani_admin, nasani_normal ;
-- grant select,insert,update,delete on photo to nasani_admin, nasani_normal;
-- grant select,insert,update,delete on  agenda to nasani_admin, nasani_normal ;
-- grant select,insert,update,delete on mandat to nasani_admin, nasani_normal ;
-- grant select,insert,update,delete on  mandat_observation to nasani_admin ;
-- grant select,insert,update,delete on offre to nasani_admin, nasani_normal ;
-- grant select,insert,update,delete on  doc to nasani_admin, nasani_normal ;

-- GRANT SELECT ON ALL TABLES IN SCHEMA public TO nasani_normal ;
-- GRANT SELECT,INSERT,UPDATE,DELETE ON ALL TABLES IN SCHEMA public TO nasani_admin ;

-- GRANT EXECUTE  ON ALL FUNCTIONS IN SCHEMA public to nasani_lecture ,nasani_normal , nasani_admin ;
-- GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO nasani_normal, nasani_admin;

-- --ALTER FUNCTION f_get_bien_detail(text,integer,  integer)     OWNER TO admin;
-- GRANT SELECT ON biencrit, agenda, prospectbien  TO nasani_normal, nasani_admin;
-- GRANT select, insert, update, delete on biencrit, agenda, prospectbien TO nasani_normal, nasani_admin;

-- GRANT select, insert on mandat_observation to nasani_admin, nasani_normal;
-- GRANT select on mandat_observation to nasani_lecture ;


-- grant all on doc to nasani_normal,nasani_admin;

-- GRANT select on mandat TO nasani_lecture ;
-- GRANT all on mandat TO nasani_normal,nasani_admin ;

-- GRANT select on mandat_observation TO nasani_lecture ;
-- GRANT all on mandat_observation TO nasani_normal,nasani_admin ;





-- GRANT USAGE ON SEQUENCE mandat_observation_nobservation_seq TO nasani_normal,nasani_admin ;
-- GRANT USAGE ON SEQUENCE mandat_nmandat_seq TO nasani_normal,nasani_admin ;
-- GRANT ALL ON mandat TO nasani_normal,nasani_admin ;
-- GRANT ALL ON mandat_observation TO nasani_normal,nasani_admin ;

-- GRANT all on statutlead TO nasani_admin ;
-- GRANT select on statutlead TO nasani_normal ;


-- GRANT ALL ON agenda ,bien,biencrit ,detailbien ,doc ,htmlbien ,offre   ,photo  ,preference  ,prospect  ,prospectbien,prospectbienrv	to nasani_admin, nasani_normal ;
-- GRANT SELECT ON agenda ,bien,biencrit ,detailbien ,doc ,htmlbien ,offre   ,photo  ,preference  ,prospect  ,prospectbien,prospectbienrv	to nasani_lecture ;

-- GRANT all on typdetailmeta TO nasani_admin ;
-- GRANT select on typdetailmeta TO nasani_normal ;
-- GRANT select on typdetailmeta TO nasani_normal ;
-- GRANT select on typdetailmeta to nasani_normal,nasani_admin, nasani_lecture ;
-- GRANT select,insert,update on typdetailmeta to nasani_admin ;
-- GRANT select, insert, update, delete on preference TO nasani_admin,nasani_normal ;
-- GRANT select on preference TO nasani_lecture;
-- GRANT select, insert, update, delete on prospectbien TO nasani_admin,nasani_normal ;
-- GRANT select on prospectbien  TO nasani_lecture;
-- GRANT select, update on params TO nasani_admin,nasani_normal ;
-- GRANT select on params  TO nasani_lecture;
-- GRANT select, update on params TO nasani_admin,nasani_normal ;
-- GRANT select on params  TO nasani_lecture;
-- GRANT select, insert, update, delete on prospect TO nasani_admin,nasani_normal ;
-- GRANT select on prospect  TO nasani_lecture;
-- GRANT select, insert, update, delete on biencrit TO nasani_admin,nasani_normal ;
-- GRANT select on biencrit  TO nasani_lecture;
-- --GRANT execute on strip_nulls to nasani_admin , nasani_normal, nasani_lecture;
-- GRANT select, insert, update, delete on biencrit TO nasani_admin,nasani_normal ;
-- GRANT select on biencrit  TO nasani_lecture;
-- GRANT all on prospect TO nasani_admin ;
-- GRANT select,insert,update,delete on prospect TO nasani_normal ;
-- GRANT select on prospect TO nasani_normal ;
-- GRANT ALL ON prospect , prospectbien, bien, biencrit to nasani_admin, nasani_normal ;
-- GRANT SELECT ON prospect , prospectbien, bien, biencrit to nasani_lecture, nasani_normal ;
-- GRANT all on biencrit to nasani_admin, nasani_normal;
-- GRANT select on biencrit to nasani_lecture ;

-- GRANT select on mandat to nasani_lecture ;
-- GRANT update,insert on mandat to nasani_admin, nasani_normal;

-- GRANT select, insert on mandat_observation to nasani_admin, nasani_normal;
-- GRANT select on mandat_observation to nasani_lecture ;

-- GRANT USAGE, SELECT ON SEQUENCE nphoto TO nasani_admin, nasani_normal;

-- --GRANT USAGE ON f_cdetail TO nasani_admin, nasani_normal, nasani_lecture;
-- --GRANT USAGE ON f_cdetail(real, varchar,varchar,varchar) TO nasani_admin, nasani_normal, nasani_lecture;




-- ---------------------------------------------------------
-- -- Une seule fois par DB donner les droits de base
-- ---------------------------------------------------------
-- -- terreimmo

-- CREATE GROUP nasani_admin;
-- CREATE GROUP nasani_normal;
-- CREATE GROUP nasani_lecture;

-- GRANT SELECT ON biencrit, agenda, prospectbien  TO nasani_normal, nasani_admin;
-- GRANT select, insert, update, delete on biencrit, agenda, prospectbien TO nasani_normal, nasani_admin;

-- GRANT select, insert on mandat_observation to nasani_admin, nasani_normal;
-- GRANT select on mandat_observation to nasani_lecture ;

-- GRANT EXECUTE  ON ALL FUNCTIONS IN SCHEMA public to nasani_lecture ,nasani_normal , nasani_admin ;

-- grant all on doc to nasani_normal,nasani_admin;

-- GRANT select on mandat TO nasani_lecture ;
-- GRANT all on mandat TO nasani_normal,nasani_admin ;

-- GRANT select on mandat_observation TO nasani_lecture ;
-- GRANT all on mandat_observation TO nasani_normal,nasani_admin ;


-- GRANT USAGE, SELECT ON ALL SEQUENCES IN SCHEMA public TO nasani_normal, nasani_admin;



-- GRANT USAGE ON SEQUENCE mandat_observation_nobservation_seq TO nasani_normal,nasani_admin ;
-- GRANT USAGE ON SEQUENCE mandat_nmandat_seq TO nasani_normal,nasani_admin ;
-- GRANT ALL ON mandat TO nasani_normal,nasani_admin ;
-- GRANT ALL ON mandat_observation TO nasani_normal,nasani_admin ;

-- GRANT all on statutlead TO nasani_admin ;
-- GRANT select on statutlead TO nasani_normal ;


-- GRANT ALL ON agenda ,bien,biencrit ,detailbien ,doc ,htmlbien ,offre   ,photo  ,preference  ,prospect  ,prospectbien,prospectbienrv	to nasani_admin, nasani_normal ;
-- GRANT SELECT ON agenda ,bien,biencrit ,detailbien ,doc ,htmlbien ,offre   ,photo  ,preference  ,prospect  ,prospectbien,prospectbienrv	to nasani_lecture ;

-- GRANT all on typdetailmeta TO nasani_admin ;
-- GRANT select on typdetailmeta TO nasani_normal ;
-- GRANT select on typdetailmeta TO nasani_normal ;
-- GRANT select on typdetailmeta to nasani_normal,nasani_admin, nasani_lecture ;
-- GRANT select,insert,update on typdetailmeta to nasani_admin ;
-- GRANT select, insert, update, delete on preference TO nasani_admin,nasani_normal ;
-- GRANT select on preference TO nasani_lecture;
-- GRANT select, insert, update, delete on prospectbien TO nasani_admin,nasani_normal ;
-- GRANT select on prospectbien  TO nasani_lecture;
-- GRANT select, update on params TO nasani_admin,nasani_normal ;
-- GRANT select on params  TO nasani_lecture;
-- GRANT select, update on params TO nasani_admin,nasani_normal ;
-- GRANT select on params  TO nasani_lecture;
-- GRANT select, insert, update, delete on prospect TO nasani_admin,nasani_normal ;
-- GRANT select on prospect  TO nasani_lecture;
-- GRANT select, insert, update, delete on biencrit TO nasani_admin,nasani_normal ;
-- GRANT select on biencrit  TO nasani_lecture;
-- GRANT execute on strip_nulls to nasani_admin , nasani_normal, nasani_lecture;
-- GRANT select, insert, update, delete on biencrit TO nasani_admin,nasani_normal ;
-- GRANT select on biencrit  TO nasani_lecture;
-- GRANT all on prospect TO nasani_admin ;
-- GRANT select,insert,update,delete on prospect TO nasani_normal ;
-- GRANT select on prospect TO nasani_normal ;
-- GRANT ALL ON prospect , prospectbien, bien, biencrit to nasani_admin, nasani_normal ;
-- GRANT SELECT ON prospect , prospectbien, bien, biencrit to nasani_lecture, nasani_normal ;
-- GRANT all on biencrit to nasani_admin, nasani_normal;
-- GRANT select on biencrit to nasani_lecture ;

-- GRANT select on mandat to nasani_lecture ;
-- GRANT update,insert on mandat to nasani_admin, nasani_normal;

-- GRANT select, insert on mandat_observation to nasani_admin, nasani_normal;
-- GRANT select on mandat_observation to nasani_lecture ;

-- GRANT USAGE, SELECT ON SEQUENCE nphoto TO nasani_admin, nasani_normal;

-- ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT execute ON FUNCTIONS TO nasani_normal,nasani_admin,nasani_lecture;
-- ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT USAGE ON SEQUENCES TO nasani_normal,nasani_admin,nasani_lecture;
-- ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT ON TABLES TO nasani_normal,nasani_admin,nasani_lecture;
-- ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT SELECT,INSERT,UPDATE,DELETE ON TABLES TO nasani_admin;
-- ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT REFERENCES,TRIGGER,RULE ON TABLES TO nasani_normal,nasani_admin,nasani_lecture;
