source: indico/indico/MaKaC/services/implementation/category.py @ 701dc2

burotelhello-world-walkthroughipv6new-webexv0.97-seriesv0.98-seriesv0.98.2v0.98.3v0.98b1v0.98b2v0.99v1.0v1.1
Last change on this file since 701dc2 was 701dc2, checked in by Jose Benito <jose.benito.gonzalez@…>, 3 years ago

[IMP] Protection Setting for new events and categs

  • fixes #95
  • Now the protection of a category or an event can be set when creating this categ/event.
  • Updated the user guide
  • reviewed by jbenito:
    • removed unnecessary protection checking.
    • i18n missing in some sentences
  • Property mode set to 100644
File size: 5.1 KB
Line 
1"""
2Asynchronous request handlers for category-related services.
3"""
4
5import datetime
6from MaKaC.services.implementation.base import ProtectedModificationService, ParameterManager
7from MaKaC.services.implementation.base import ProtectedDisplayService, ServiceBase
8import MaKaC.conference as conference
9from MaKaC.common.logger import Logger
10from MaKaC.services.interface.rpc.common import ServiceError
11import MaKaC.webinterface.locators as locators
12from MaKaC.webinterface.wcomponents import WConferenceList, WConferenceListEvents
13
14class CategoryBase(object):
15    """
16    Base class for category
17    """
18
19    def _checkParams( self ):
20        try:
21            l = locators.WebLocator()
22            l.setCategory( self._params )
23            self._target = self._categ = l.getObject()
24        except:
25            #raise ServiceError("ERR-E4", "Invalid category id.")
26            self._target = self._categ = conference.CategoryManager().getRoot()
27
28
29class CategoryModifBase(ProtectedModificationService, CategoryBase):
30    def _checkParams(self):
31        CategoryBase._checkParams(self)
32        ProtectedModificationService._checkParams(self)
33
34class CategoryDisplayBase(ProtectedDisplayService, CategoryBase):
35
36    def _checkParams(self):
37        CategoryBase._checkParams(self)
38        ProtectedDisplayService._checkParams(self)
39
40class GetCategoryList(CategoryDisplayBase):
41
42    def _checkProtection( self ):
43        self._accessAllowed = False
44        try:
45            CategoryDisplayBase._checkProtection(self)
46            self._accessAllowed = True
47        except Exception, e:
48            pass
49
50    def _getAnswer( self ):
51        # allowed is used to report to the user in case of forbidden access.
52        allowed = self._accessAllowed
53
54        # if the category access is forbidden we return the previous
55        # one which the user can access.
56        if  not self._accessAllowed:
57            while (not self._accessAllowed and not self._target.isRoot()):
58                self._target = self._target.getOwner()
59                self._checkProtection()
60        target = self._target
61
62        # if the category is final we return the previous one.
63        if not target.hasSubcategories():
64            target = target.getOwner()
65
66        # We get the parent category. If no parent (Home) we keep the same as target.
67        parent = target.getOwner()
68        if not parent:
69            parent = target
70
71        # Breadcrumbs
72        breadcrumbs = target.getCategoryPathTitles()
73
74        # Getting the list of subcategories
75        categList=[]
76        for cat in target.getSubCategoryList():
77            #if cat.hasAnyProtection():
78            #    protected = True
79            #elif cat.isConferenceCreationRestricted():
80            #    protected = not cat.canCreateConference( self._getUser() )
81            #else:
82            #    protected = False
83            categList.append({"id":cat.getId(), "title":cat.getTitle(), "subcatLength":len(cat.getSubCategoryList()), "final": not cat.hasSubcategories()})
84        return {"parentCateg":
85                    {"id":parent.getId(), "title":parent.getTitle()},
86                "currentCateg":
87                    {"id":target.getId(), "title":target.getTitle(), "breadcrumb": breadcrumbs},
88                "categList":categList,
89                "accessAllowed": allowed
90                }
91
92class CanCreateEvent(CategoryDisplayBase):
93    """
94    This service returns whether or not the user can create
95    an event in this category along with the protection of
96    the chosen category.
97    """
98    def _checkProtection( self ):
99        self._accessAllowed = False
100        try:
101            CategoryDisplayBase._checkProtection(self)
102            self._accessAllowed = True
103        except Exception, e:
104            pass
105
106    def _getAnswer( self ):
107        canCreate = False
108        protection = "public"
109
110        if (self._accessAllowed and self._categ.canCreateConference( self._getUser() )):
111            canCreate = True
112
113        if self._categ.isProtected() :
114            protection = "private"
115
116        return {"canCreate": canCreate,
117                "protection": protection}
118
119
120class GetPastEventsList(CategoryDisplayBase):
121
122    def _checkParams(self):
123        CategoryDisplayBase._checkParams(self)
124        pm = ParameterManager(self._params)
125        self._fromDate = pm.extract("fromDate", pType=datetime.datetime, allowEmpty=False).date()
126
127    def _getAnswer( self ):
128
129        allEvents,eventsByMonth = WConferenceList.sortEvents(self._target.getConferenceList())
130
131        ## CREATE future events dict and future/past counter
132        pastEvents = {}
133        for year in allEvents.keys():
134            if year < self._fromDate.year:
135                pastEvents[year] = allEvents[year]
136            elif year == self._fromDate.year:
137                for month in allEvents[year].keys():
138                    if month < self._fromDate.month:
139                        pastEvents.setdefault(year,{})[month] = allEvents[year][month]
140
141        return WConferenceListEvents(pastEvents, self._aw).getHTML()
142
143
144methodMap = {
145    "getCategoryList": GetCategoryList,
146    "getPastEventsList": GetPastEventsList,
147    "canCreateEvent": CanCreateEvent
148    }
Note: See TracBrowser for help on using the repository browser.