1 # This file is part of Indico.
2 # Copyright (C) 2002 - 2015 European Organization for Nuclear Research (CERN).
4 # Indico is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License as
6 # published by the Free Software Foundation; either version 3 of the
7 # License, or (at your option) any later version.
9 # Indico is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with Indico; if not, see <http://www.gnu.org/licenses/>.
17 from persistent
import Persistent
19 from MaKaC
.common
.ObjectHolders
import ObjectHolder
20 from MaKaC
.common
.Locators
import Locator
21 from MaKaC
.common
import filters
22 from MaKaC
.conference
import TrashCanManager
25 class Domain(Persistent
):
26 """This class represents the domains which are configured inside the system.
27 A domain is a set of IP filters which given an IP can determine if it
28 belongs to it or not depending on the filter application result.
37 def getLocator( self
):
39 d
["domainId"] = self
.getId()
42 def setId( self
, newId
):
48 def setName( self
, newName
):
49 self
.name
= newName
.strip()
54 def setDescription( self
, newDescription
):
55 self
.description
= newDescription
.strip()
57 def getDescription( self
):
58 return self
.description
60 def setFilterList(self
, fl
):
63 def getFilterList( self
):
64 return self
.filterList
66 def addFilter( self
, filter ):
68 #ToDo: We have to check a filter is specified in the good format (IP)
69 if f
in self
.filterList
:
71 self
.filterList
.append(f
)
73 def addFiltersFromStr( self
, filters
):
76 for filter in filters
.split(";"):
77 self
.addFilter( filter.strip() )
79 def setFiltersFromStr( self
, filters
):
83 self
.addFiltersFromStr( filters
)
85 def removeFilter( self
, filter ):
87 if f
not in self
.filterList
:
89 self
.filterList
.remove(f
)
91 def belongsTo( self
, IP
):
93 #ToDo: check that the IP is in the correct format
94 for filt
in self
.getFilterList():
95 if ip
.startswith(filt
):
100 class _DomainFFName(filters
.FilterField
):
103 def satisfies(self
, dom
):
104 for value
in self
._values
:
105 if str(dom
.getName()).lower().find((str(value
).strip().lower()))!=-1:
110 class _DomainFilterCriteria(filters
.FilterCriteria
):
111 _availableFields
={"name":_DomainFFName
}
113 def __init__(self
,criteria
={}):
114 filters
.FilterCriteria
.__init
__(self
,None,criteria
)
117 class DomainHolder(ObjectHolder
):
119 counterName
= "DOMAINS"
121 def match( self
, criteria
):
125 for f
,v
in criteria
.items():
127 f
=filters
.SimpleFilter(_DomainFilterCriteria(crit
),None)
128 return f
.apply(self
.getList())
130 def remove(self
, item
):
131 # METHOD HAS TO BE IMPLEMENTED...
132 ObjectHolder
.remove(self
, item
)
133 TrashCanManager().add(item
)
135 def getLength( self
):
136 return len(self
.getList())
138 def getBrowseIndex( self
):
140 for domain
in self
.getList():
141 name
= domain
.getName()
142 if name
and not name
[0].lower() in letters
:
143 letters
.append(name
[0].lower())
147 def matchFirstLetter( self
, letter
):
149 for domain
in self
.getList():
150 name
= domain
.getName()
151 if name
and name
[0].lower() == letter
.lower():