Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 904 → Rev 914

/sun/hostcaptain/trunk/src/ak/hostcaptain/core/model/MailboxManager.java
2,8 → 2,10
 
import java.util.*;
import net.sf.hibernate.*;
import net.sf.hibernate.type.Type;
import ak.hostcaptain.util.HibernateUtil;
import ak.hostcaptain.util.ModelException;
import ak.hostcaptain.util.ModelSecurityException;
 
public class MailboxManager
{
33,24 → 35,41
{
}
 
public Mailbox create()
public Mailbox create(User editor)
throws ModelException
{
if(!allowedToCreate(editor)) throw new ModelSecurityException();
 
return new Mailbox();
}
 
public Mailbox get(Long id)
public boolean allowedToCreate(User editor)
throws ModelException
{
return editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor);
}
 
public Mailbox get(User editor, Long id)
throws ModelException
{
Mailbox mailbox;
 
try {
return (Mailbox)HibernateUtil.currentSession().load(Mailbox.class, id);
mailbox = (Mailbox)HibernateUtil.currentSession().load(Mailbox.class, id);
}
catch(HibernateException ex)
{
throw new ModelException(ex);
}
 
if(!mailbox.viewableBy(editor))
throw new ModelSecurityException();
 
return mailbox;
}
 
public Mailbox findForLogin(String login)
protected Mailbox findForLogin(String login)
throws ModelException
{
try {
68,9 → 87,12
}
}
 
public void save(Mailbox mailbox)
public void save(User editor, Mailbox mailbox)
throws ModelException
{
if(!mailbox.editableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().saveOrUpdate(mailbox);
}
80,9 → 102,12
}
}
 
public void delete(Mailbox mailbox)
public void delete(User editor, Mailbox mailbox)
throws ModelException
{
if(!mailbox.deleteableBy(editor))
throw new ModelSecurityException();
 
try {
HibernateUtil.currentSession().delete(mailbox);
}
92,11 → 117,18
}
}
 
public Collection listMailboxes()
public Collection listMailboxes(User editor)
throws ModelException
{
try {
return HibernateUtil.currentSession().find("from Mailbox");
if(editor.isSuperuser())
return HibernateUtil.currentSession().find("from Mailbox");
else
return HibernateUtil.currentSession().find(
"select mb from Mailbox mb left join mb.domain as d"
+ " where d.owner=? or mb.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) } );
}
catch(HibernateException ex)
{
104,12 → 136,23
}
}
 
public Collection listMailboxes(User owner)
public boolean areMailboxesAvailable(User editor)
throws ModelException
{
try {
return HibernateUtil.currentSession().find(
"from Mailbox where owner=?", owner, Hibernate.entity(User.class));
if(editor.isSuperuser()
|| InetDomainManager.getInstance().areInetDomainsAvailable(editor))
{
return true;
}
else {
return ((Integer)HibernateUtil.currentSession().iterate(
"select count(*) from Mailbox mb left join mb.domain as d"
+ " where d.owner=? or mb.owner=?",
new Object[] { editor, editor },
new Type[] { Hibernate.entity(User.class), Hibernate.entity(User.class) })
.next()).intValue() > 0;
}
}
catch(HibernateException ex)
{