- (* If the ~restrict parameter is given, then we want to check that
- * the user has sufficient permission to run this script.
- *)
- let permitted =
- if not anonymous && user = Anonymous then false
- else
- match restrict with
- [] -> true (* empty list = no restrictions *)
- | rs ->
- List.fold_left (||) false
- (List.map (fun r -> test_permission host r user) rs) in
+ let rows =
+ PGSQL(dbh)
+ "select u.id, u.name, u.can_edit, u.can_manage_users,
+ u.can_manage_contacts, u.can_manage_site,
+ u.can_edit_global_css, u.can_import_mail,
+ u.email, u.email_notify
+ from usercookies uc, users u
+ where uc.cookie = $cookie
+ and uc.userid = u.id
+ and u.hostid = $hostid" in
+ match rows with
+ | [userid, name, can_edit, can_manage_users,
+ can_manage_contacts, can_manage_site,
+ can_edit_global_css, can_import_mail,
+ email, email_notify] ->
+ (* Every logged in user can view. *)
+ let perms = [CanView] in
+ let perms =
+ if can_edit then CanEdit :: perms
+ else perms in
+ let perms =
+ if can_manage_users then CanManageUsers :: perms
+ else perms in
+ let perms =
+ if can_manage_contacts then CanManageContacts :: perms
+ else perms in
+ let perms =
+ if can_manage_site then CanManageSite :: perms
+ else perms in
+ let perms =
+ if can_edit_global_css then CanEditGlobalCSS :: perms
+ else perms in
+ let perms =
+ if can_import_mail then CanImportMail :: perms
+ else perms in
+ (* Preferences. *)
+ let prefs = { email = email;
+ email_notify = email_notify; } in
+ User (userid, name, perms, prefs)
+ | [] -> raise Not_found
+ | _ -> assert false
+ with
+ Not_found -> Anonymous in