From b127d65e62715cf191d4e0f479da54ae310ed863 Mon Sep 17 00:00:00 2001 From: Purodha Blissenbach Date: Fri, 21 Sep 2012 13:50:45 +0200 Subject: [PATCH 1/2] Database migration to version 2.2 begun. --- hsarback/database/database_update.sql | 80 +++++++++++++++++++++++++++ hsarback/database/schema.sql | 4 ++ 2 files changed, 84 insertions(+) diff --git a/hsarback/database/database_update.sql b/hsarback/database/database_update.sql index e69de29..3f3f5dd 100644 --- a/hsarback/database/database_update.sql +++ b/hsarback/database/database_update.sql @@ -0,0 +1,80 @@ +-- Migrate database from version 2.1 to version 2.2 +-- +-- domain options +-- +CREATE SEQUENCE domain_option_id_seq + INCREMENT BY 1 + NO MAXVALUE + NO MINVALUE + CACHE 1; + +CREATE TABLE domain_option ( + domain_option_id integer DEFAULT nextval(('"domain_option_id_seq"'::text)::regclass) NOT NULL, + domain_option_name character varying(50) NOT NULL +); + +ALTER TABLE ONLY domain_option + ADD CONSTRAINT pk_domain_option PRIMARY KEY (domain_option_id); + +CREATE UNIQUE INDEX domain_option_name_idx ON domain_option USING btree ( domain_option_name ); + +CREATE TABLE domain__domain_option ( + domain_option_id integer NOT NULL, + domain_id integer NOT NULL +); + +ALTER TABLE ONLY domain__domain_option + ADD CONSTRAINT pk_domain__domain_option PRIMARY KEY (domain_option_id, domain_id); + +ALTER TABLE ONLY domain__domain_option + ADD CONSTRAINT domain_option_id_fkey FOREIGN KEY (domain_option_id) + REFERENCES domain_option(domain_option_id) DEFERRABLE; + +ALTER TABLE ONLY domain__domain_option + ADD CONSTRAINT domain_id_fkey FOREIGN KEY (domain_id) + REFERENCES domain(domain_id) DEFERRABLE; + +-- +-- table: domain_option +-- +INSERT INTO domain_option (domain_option_name) + VALUES ('backupmxforexternalmx'); +INSERT INTO domain_option (domain_option_name) + VALUES ('greylisting'); +INSERT INTO domain_option (domain_option_name) + VALUES ('htdocsfallback'); +INSERT INTO domain_option (domain_option_name) + VALUES ('includes'); +INSERT INTO domain_option (domain_option_name) + VALUES ('indexes'); +INSERT INTO domain_option (domain_option_name) + VALUES ('multiviews'); +-- +-- new domain options settings +-- +-- existing default = ON +-- +INSERT INTO domain__domain_option SELECT domain_option_id, domain_id + FROM domain, domain_option + WHERE domain_option.domain_option_name = 'greylisting' ; +INSERT INTO domain__domain_option SELECT domain_option_id, domain_id + FROM domain, domain_option + WHERE domain_option.domain_option_name = 'htdocsfalback' ; +INSERT INTO domain__domain_option SELECT domain_option_id, domain_id + FROM domain, domain_option + WHERE domain_option.domain_option_name = 'includes' ; +INSERT INTO domain__domain_option SELECT domain_option_id, domain_id + FROM domain, domain_option + WHERE domain_option.domain_option_name = 'indexes' ; +INSERT INTO domain__domain_option SELECT domain_option_id, domain_id + FROM domain, domain_option + WHERE domain_option.domain_option_name = 'multiviews' ; +-- +-- existing default = OFF +-- +DELETE FROM domain__domain_option USING domain_option + WHERE domain__domain_option.domain_option_id = domain_option.domain_option_id + AND domain_option.domain_option_name = 'backupmxforexternalmx' ; +-- +-- End of migratino to version 2.2 +-- diff --git a/hsarback/database/schema.sql b/hsarback/database/schema.sql index 0424bd4..80bd3ac 100644 --- a/hsarback/database/schema.sql +++ b/hsarback/database/schema.sql @@ -900,6 +900,10 @@ ALTER TABLE ONLY component ALTER TABLE ONLY queue_task ADD CONSTRAINT queue_task_user_id_fkey FOREIGN KEY (user_id) REFERENCES unixuser(unixuser_id) ON DELETE SET NULL; +-- +-- domain options +-- + CREATE SEQUENCE domain_option_id_seq INCREMENT BY 1 NO MAXVALUE From da5f5cd6fb24dce252ebb6e3b816823659b0e8f8 Mon Sep 17 00:00:00 2001 From: Peter Hormanns Date: Fri, 21 Sep 2012 14:16:22 +0200 Subject: [PATCH 2/2] implement pac update --- hsarback/build.xml | 2 +- .../mods/dom/DomainProcessorFactory.java | 9 ++- hsarback/src/de/hsadmin/mods/pac/Pac.java | 2 +- .../de/hsadmin/mods/pac/PacModuleImpl.java | 26 +++++++- .../src/de/hsadmin/mods/user/UnixUser.java | 2 +- hsarback/src/de/hsadmin/remote/PacRemote.java | 66 ++++++++++++------- 6 files changed, 77 insertions(+), 30 deletions(-) diff --git a/hsarback/build.xml b/hsarback/build.xml index 80c9b57..a6bb7e4 100644 --- a/hsarback/build.xml +++ b/hsarback/build.xml @@ -39,7 +39,7 @@ - + diff --git a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java index 7572ddd..3afcaf6 100644 --- a/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java +++ b/hsarback/src/de/hsadmin/mods/dom/DomainProcessorFactory.java @@ -27,8 +27,13 @@ import de.hsadmin.mods.user.UnixUser; public class DomainProcessorFactory implements EntityProcessorFactory { - private static final String[] DW_STRUCTURE = new String[] { "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "cgi", "fastcgi", "cgi-ssl", "fastcgi-ssl", "etc", "var" }; - private static final String[] SW_STRUCTURE = new String[] { "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "etc", "var" }; + private static final String[] DW_STRUCTURE = new String[] { + "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "cgi", "fastcgi", "cgi-ssl", "fastcgi-ssl", "etc", "var" + }; + + private static final String[] SW_STRUCTURE = new String[] { + "htdocs", "htdocs-ssl", "subs", "subs/www", "subs-ssl", "subs-ssl/www", "etc", "var" + }; public Processor createCreateProcessor(EntityManager em, T entity) throws ProcessorException { String hiveName = entity.getHiveName(); diff --git a/hsarback/src/de/hsadmin/mods/pac/Pac.java b/hsarback/src/de/hsadmin/mods/pac/Pac.java index 28b8532..746811c 100644 --- a/hsarback/src/de/hsadmin/mods/pac/Pac.java +++ b/hsarback/src/de/hsadmin/mods/pac/Pac.java @@ -75,7 +75,7 @@ public class Pac extends AbstractEntity implements Serializable { @ManyToOne(fetch = EAGER) private INetAddress oldINetAddr; - @OneToMany(fetch = LAZY, cascade = ALL, mappedBy="pac") + @OneToMany(fetch = EAGER, cascade = ALL, mappedBy="pac") private Set pacComponents; @OneToMany(fetch = LAZY, cascade = ALL, mappedBy="pac") diff --git a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java index c3d848c..32ae06f 100644 --- a/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java +++ b/hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java @@ -110,9 +110,16 @@ public class PacModuleImpl extends AbstractModuleImpl { } @Override - public AbstractEntity update(AbstractEntity existingEntity) + public AbstractEntity update(AbstractEntity entity) throws HSAdminException { - throw new AuthorisationException(getTransaction().getLoginUser(), "update", existingEntity); + UnixUser loginUser = getTransaction().getLoginUser(); + if (entity instanceof Pac) { + Pac pac = (Pac) entity; + } else { + throw new AuthorisationException(loginUser, "update", entity); + } + needsWriteAccessOn(entity, "update"); + return super.update(entity); } @Override @@ -154,4 +161,19 @@ public class PacModuleImpl extends AbstractModuleImpl { super.delete(existingEntity); } + private void needsWriteAccessOn(AbstractEntity entity, String method) throws AuthorisationException { + UnixUser loginUser = getTransaction().getLoginUser(); + if (entity instanceof Pac) { + Pac pac = (Pac) entity; + String aLoginUserName = loginUser.getName(); + boolean isPacAdmin = loginUser.hasPacAdminRoleFor(pac); + boolean isCustomer = aLoginUserName.equals(pac.getCustomer().getName()); + boolean isHostmaster = loginUser.hasHostmasterRole(); + if (!isPacAdmin && !isCustomer && !isHostmaster) { + throw new AuthorisationException(loginUser, method, pac); + } + } else { + throw new AuthorisationException(loginUser, method, entity); + } + } } diff --git a/hsarback/src/de/hsadmin/mods/user/UnixUser.java b/hsarback/src/de/hsadmin/mods/user/UnixUser.java index a23b060..3a60bad 100644 --- a/hsarback/src/de/hsadmin/mods/user/UnixUser.java +++ b/hsarback/src/de/hsadmin/mods/user/UnixUser.java @@ -275,7 +275,7 @@ public class UnixUser extends AbstractEntity implements Serializable { return getName().equals(cust.getName()) || hasHostmasterRole(); } - public boolean hasPacAdminRoleFor(de.hsadmin.mods.pac.Pac pac) { + public boolean hasPacAdminRoleFor(Pac pac) { return pac != null && (pac.getName().equals(getName()) || hasCustomerRoleFor(pac.getCustomer()) ); diff --git a/hsarback/src/de/hsadmin/remote/PacRemote.java b/hsarback/src/de/hsadmin/remote/PacRemote.java index cb6ca52..9008a76 100644 --- a/hsarback/src/de/hsadmin/remote/PacRemote.java +++ b/hsarback/src/de/hsadmin/remote/PacRemote.java @@ -1,10 +1,9 @@ package de.hsadmin.remote; -import java.util.Comparator; import java.util.Date; +import java.util.HashMap; import java.util.Map; -import java.util.SortedSet; -import java.util.TreeSet; +import java.util.Set; import de.hsadmin.core.model.AbstractEntity; import de.hsadmin.core.util.TextUtil; @@ -27,27 +26,38 @@ public class PacRemote extends AbstractRemote { resultMap.put("curinetaddr", pac.getCurINetAddr().getInetAddr()); resultMap.put("created", TextUtil.format(pac.getCreated())); resultMap.put("basepac", pac.getBasepac().getName()); - SortedSet sortedComponents = new TreeSet(new Comparator() { - @Override - public int compare(PacComponent o1, PacComponent o2) { - return o2.getBaseComponent().getSorting() - o1.getBaseComponent().getSorting(); - } - }); - sortedComponents.addAll(pac.getPacComponents()); - StringBuffer bf = new StringBuffer(); - boolean empty = true; - for (PacComponent comp : sortedComponents) { - if (comp.getQuantity() > 0) { - if (!empty) { - bf.append("; "); - } - bf.append(comp.getBaseComponent().getFeature()); - bf.append("="); - bf.append(comp.getQuantity()); - empty = false; + + Map components = new HashMap(); + Set pacComponents = pac.getPacComponents(); + for (PacComponent comp : pacComponents) { + int quantity = comp.getQuantity(); + if (quantity > 0) { + components.put(comp.getBaseComponent().getFeature(), Integer.toString(quantity)); } } - resultMap.put("components", bf.toString()); + resultMap.put("components", components); + +// SortedSet sortedComponents = new TreeSet(new Comparator() { +// @Override +// public int compare(PacComponent o1, PacComponent o2) { +// return o2.getBaseComponent().getSorting() - o1.getBaseComponent().getSorting(); +// } +// }); +// sortedComponents.addAll(pac.getPacComponents()); +// StringBuffer bf = new StringBuffer(); +// boolean empty = true; +// for (PacComponent comp : sortedComponents) { +// if (comp.getQuantity() > 0) { +// if (!empty) { +// bf.append("; "); +// } +// bf.append(comp.getBaseComponent().getFeature()); +// bf.append("="); +// bf.append(comp.getQuantity()); +// empty = false; +// } +// } +// resultMap.put("components", bf.toString()); } @Override @@ -86,7 +96,17 @@ public class PacRemote extends AbstractRemote { hive.setName(hiveName); pac.setHive(hive); } - pac.setName((String) setParams.get("name")); + Object componentsObj = setParams.get("components"); + if (componentsObj != null && componentsObj instanceof Map) { + Map componentsMap = (Map) componentsObj; + for (Object key : componentsMap.keySet()) { + pac.getPacComponent(key.toString()).setQuantity(Integer.parseInt(componentsMap.get(key).toString())); + } + } + Object nameParamObj = setParams.get("name"); + if (nameParamObj != null && nameParamObj instanceof String) { + pac.setName((String) nameParamObj); + } } @Override