Subversion Repositories general

Rev

Rev 945 | Rev 1010 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
924 dev 1
package ak.hostadmiral.core.model;
919 dev 2
 
3
import java.util.Collection;
924 dev 4
import ak.hostadmiral.util.ModelException;
5
import ak.hostadmiral.util.ModelSecurityException;
919 dev 6
 
7
/**
8
 *
9
 * @hibernate.class table="mailaliases"
10
 */
11
public class MailAlias
12
	extends GeneralModelObject
13
{
14
	private String     address;
15
	private InetDomain domain;
16
	private User       owner;
17
	private Collection destinations; // Collection(MailAliasDestintion)
18
 
19
	protected MailAlias()
20
	{
21
	}
22
 
23
	/**
24
	 *
25
	 * @hibernate.property
26
	 */
27
	public String getAddress()
28
	{
29
		return address;
30
	}
31
 
921 dev 32
	protected void setAddress(String address)
919 dev 33
	{
34
		this.address = address;
35
	}
36
 
921 dev 37
	public void setAddress(User editor, String address)
38
		throws ModelException
39
	{
40
		if(!editableBy(editor))
41
			throw new ModelSecurityException();
42
 
43
		this.address = address;
44
	}
45
 
919 dev 46
	/**
47
	 *
48
	 * @hibernate.many-to-one
49
	 */
50
	public InetDomain getDomain()
51
	{
52
		return domain;
53
	}
54
 
921 dev 55
	protected void setDomain(InetDomain domain)
919 dev 56
	{
57
		this.domain = domain;
58
	}
59
 
921 dev 60
	public void setDomain(User editor, InetDomain domain)
61
		throws ModelException
62
	{
63
		if(!editableBy(editor))
64
			throw new ModelSecurityException();
65
 
66
		this.domain = domain;
67
	}
68
 
919 dev 69
	/**
70
	 *
71
	 * @hibernate.many-to-one
72
	 */
73
	public User getOwner()
74
	{
75
		return owner;
76
	}
77
 
921 dev 78
	protected void setOwner(User owner)
919 dev 79
	{
80
		this.owner = owner;
81
	}
82
 
921 dev 83
	public void setOwner(User editor, User owner)
84
		throws ModelException
85
	{
86
		if(!editableBy(editor))
87
			throw new ModelSecurityException();
88
 
89
		this.owner = owner;
90
	}
91
 
919 dev 92
 	/**
93
 	 * @return Collection(MailAliasDestination)
94
 	 *
95
 	 * @hibernate.bag inverse="true" cascade="all-delete-orphan"
96
	 * @hibernate.collection-key column="alias"
924 dev 97
     * @hibernate.collection-one-to-many class="ak.hostadmiral.core.model.MailAliasDestination"
919 dev 98
     */
921 dev 99
	protected Collection getDestinations()
919 dev 100
	{
101
		return destinations;
102
	}
103
 
921 dev 104
 	/**
105
 	 * @return Collection(MailAliasDestination)
106
	 */
107
	public Collection getDestinations(User editor)
108
		throws ModelException
109
	{
110
		if(mayChangeDestinations(editor))
111
			return destinations;
112
		else if(viewableBy(editor))
113
			return java.util.Collections.unmodifiableCollection(destinations);
114
		else
115
			throw new ModelSecurityException();
116
	}
117
 
919 dev 118
	/**
119
	 * @param destinations Collection(MailAliasDestination)
120
	 */
121
	protected void setDestinations(Collection destinations)
122
	{
123
		this.destinations = destinations;
124
	}
125
 
126
	public String getTypeKey()
127
	{
924 dev 128
		return ak.hostadmiral.core.CoreResources.TYPE_MAIL_ALIAS;
919 dev 129
	}
130
 
131
	public String getIdentKey()
132
	{
924 dev 133
		return ak.hostadmiral.core.CoreResources.IDENT_MAIL_ALIAS;
919 dev 134
	}
135
 
136
	public Object[] getIdentParams()
137
	{
138
		return new Object[] { getAddress(), getDomain().getName() };
139
	}
140
 
141
	public boolean viewableBy(User user)
142
	{
143
		return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
144
	}
145
 
146
	public boolean editableBy(User user)
147
	{
148
		return user.isSuperuser() || user.equals(domain.getOwner());
149
	}
150
 
921 dev 151
	public boolean mayChangeDestinations(User user)
152
	{
153
		return user.isSuperuser() || user.equals(domain.getOwner()) || user.equals(owner);
154
	}
155
 
919 dev 156
	public boolean deleteableBy(User user)
157
	{
158
		return user.isSuperuser() || user.equals(domain.getOwner());
159
	}
921 dev 160
 
161
	protected static boolean allowedToCreate(MailAliasManager manager, User editor)
162
		throws ModelException
163
	{
164
		return editor.isSuperuser()
165
			|| InetDomainManager.getInstance().areInetDomainsAvailable(editor);
166
	}
919 dev 167
}