source: indico/indico/MaKaC/services/implementation/contribution.py @ 35c7ed

hello-world-walkthroughipv6v0.98-seriesv0.98.2v0.98.3v0.98b2v0.99v1.0v1.1
Last change on this file since 35c7ed was 35c7ed, checked in by Pedro Ferreira <jose.pedro.ferreira@…>, 22 months ago

[FIX] Moved HTML to TPLs

  • Several other fixes, include i18n true lazy strings;
  • Also replaced most old JS code with jQuery;
  • Property mode set to 100644
File size: 8.0 KB
RevLine 
[9033fd]1from MaKaC.services.implementation.base import ProtectedModificationService
2from MaKaC.services.implementation.base import ProtectedDisplayService
3from MaKaC.services.implementation.base import ParameterManager
4from MaKaC.services.implementation.roomBooking import GetBookingBase
5
[a89f94]6from MaKaC.services.interface.rpc.common import ServiceError, ServiceAccessError
[9033fd]7
8from MaKaC.common.PickleJar import DictPickler
9
10import MaKaC.conference as conference
11from MaKaC.services.implementation.base import TextModificationBase
12from MaKaC.services.implementation.base import HTMLModificationBase
13from MaKaC.services.implementation.base import DateTimeModificationBase
[a89f94]14from MaKaC.common.fossilize import fossilize
15from MaKaC.user import PrincipalHolder, Avatar, Group
[9033fd]16
17class ContributionBase(object):
18
[a89f94]19    def _checkParams( self ):
[9033fd]20        try:
[a89f94]21            self._target = self._conf = conference.ConferenceHolder().getById(self._params["conference"]);
22        except:
23            try:
24                self._target = self._conf = conference.ConferenceHolder().getById(self._params["confId"]);
25            except:
26                raise ServiceError("ERR-E4", "Invalid conference id.")
27
28        if self._conf == None:
29            raise Exception("Conference id not specified.")
[9033fd]30
31        try:
32            self._target = self._contribution = self._conf.getContributionById(self._params["contribution"])
[a89f94]33        except:
34            try:
35                self._target = self._contribution = self._conf.getContributionById(self._params["contribId"])
36            except:
37                raise ServiceError("ERR-C0", "Invalid contribution id.")
38
39        if self._target == None:
40            raise Exception("Contribution id not specified.")
[9033fd]41
42        # create a parameter manager that checks the consistency of passed parameters
43        self._pm = ParameterManager(self._params)
44
45class ContributionDisplayBase(ProtectedDisplayService, ContributionBase):
[a89f94]46
[9033fd]47    def _checkParams(self):
48        ContributionBase._checkParams(self)
49        ProtectedDisplayService._checkParams(self)
50
[408dc5e]51class ContributionModifBase(ProtectedModificationService, ContributionBase):
[a31107b]52
53    def _checkParams(self):
54        ContributionBase._checkParams(self)
55        ProtectedModificationService._checkParams(self)
[a89f94]56
[9033fd]57    def _checkProtection(self):
58        if self._target.getSession() != None:
59            if self._target.getSession().canCoordinate(self.getAW(), "modifContribs"):
60                return
61        ProtectedModificationService._checkProtection(self)
[a89f94]62
[9033fd]63class ContributionTextModificationBase(TextModificationBase, ContributionBase):
64    pass
65
66class ContributionHTMLModificationBase(HTMLModificationBase, ContributionBase):
67    pass
68
69class ContributionDateTimeModificationBase (DateTimeModificationBase, ContributionBase):
70    pass
71
72class ContributionAddSubContribution(ContributionModifBase):
73    def _checkParams(self):
74        ContributionModifBase._checkParams(self)
[a89f94]75
[9033fd]76        # "presenters" and "keywords" are not required. they can be empty
77        self._presenters = self._pm.extract("presenters", pType=list, allowEmpty=True)
78        self._keywords = self._pm.extract("keywords", pType=list, allowEmpty=True)
79        self._description = self._pm.extract("description", pType=str, allowEmpty=True, defaultValue="")
[543f32]80        self._reportNumbers = self._pm.extract("reportNumbers", pType=list, allowEmpty=True, defaultValue=[])
81        self._materials = self._pm.extract("materials", pType=dict, allowEmpty=True)
[a89f94]82
83        # these are required
[9033fd]84        self._duration = self._pm.extract("duration", pType=int)
85        self._title = self._pm.extract("title", pType=str)
[a89f94]86
[9033fd]87    def __addPresenters(self, subcontrib):
[a89f94]88
[9033fd]89        # add each presenter
90        for presenterValues in self._presenters:
[a89f94]91
92            # magically update a new ContributionParticipation with JSON data, using the DictPickler
[9033fd]93            presenter = conference.SubContribParticipation()
94            DictPickler.update(presenter, presenterValues)
95
96            subcontrib.newSpeaker(presenter)
[a89f94]97
[543f32]98    def __addMaterials(self, subcontrib):
99        if self._materials:
100            for material in self._materials.keys():
101                newMaterial = conference.Material()
102                newMaterial.setTitle(material)
103                for resource in self._materials[material]:
104                    newLink = conference.Link()
105                    newLink.setURL(resource)
106                    newLink.setName(resource)
107                    newMaterial.addResource(newLink)
108                subcontrib.addMaterial(newMaterial)
109
110    def __addReportNumbers(self, subcontrib):
111        if self._reportNumbers:
112            for reportTuple in self._reportNumbers:
113                for recordNumber in reportTuple[1]:
114                    subcontrib.getReportNumberHolder().addReportNumber(reportTuple[0], recordNumber)
115
[9033fd]116    def _getAnswer(self):
117        # create the sub contribution
118        sc = self._target.newSubContribution()
[a89f94]119
[9033fd]120        sc.setTitle( self._title )
121        sc.setDescription( self._description )
122        # separate the keywords using newlines
123        sc.setKeywords('\n'.join(self._keywords))
124        sc.setDuration( self._duration / 60, \
[a89f94]125                         self._duration % 60 )
126
[543f32]127        self.__addMaterials(sc)
128        self.__addReportNumbers(sc)
[9033fd]129        self.__addPresenters(sc)
[a89f94]130
[9033fd]131        # log the event
132        logInfo = sc.getLogInfo()
133        logInfo["subject"] = "Create new subcontribution: %s"%sc.getTitle()
134        self._target.getConference().getLogHandler().logAction(logInfo, "Timetable/SubContribution", self._getUser())
135
136class ContributionDeleteSubContribution(ContributionModifBase):
137
138    # contribution.deleteSubContribution
139
140    _asyndicoDoc = {
141        'summary':  'Deletes a subcontribution, given the conference, contribution and subcontribution IDs.',
142        'params': [{'name': 'conference', 'type': 'str'},
143                   {'name': 'contribution', 'type': 'str'},
144                   {'name': 'subcontribution', 'type': 'str'}],
145        'return': None
146        }
[a89f94]147
[9033fd]148    def _checkParams(self):
149        ContributionModifBase._checkParams(self)
[a89f94]150
[9033fd]151        subContId = self._pm.extract("subcontribution", pType=str, allowEmpty=False)
152
153        self._subContribution = self._contribution.getSubContributionById(subContId)
[a89f94]154
[9033fd]155    def _getAnswer(self):
156        self._subContribution.getOwner().removeSubContribution(self._subContribution)
157
158class ContributionGetBooking(ContributionDisplayBase, GetBookingBase):
159    pass
160
[a89f94]161class ContributionProtectionUserList(ContributionModifBase):
162
163    def _getAnswer(self):
164        #will use IAvatarFossil or IGroupFossil
165        return fossilize(self._contribution.getAllowedToAccessList())
166
167class ContributionProtectionAddUsers(ContributionModifBase):
168
169    def _checkParams(self):
170        ContributionModifBase._checkParams(self)
171
172        self._usersData = self._params['value']
173        self._user = self.getAW().getUser()
174
175    def _getAnswer(self):
176
177        for user in self._usersData :
178
179            userToAdd = PrincipalHolder().getById(user['id'])
180
181            if not userToAdd :
182                raise ServiceError("ERR-U0","User does not exist!")
183
184            self._contribution.grantAccess(userToAdd)
185
186class ContributionProtectionRemoveUser(ContributionModifBase):
187
188    def _checkParams(self):
189        ContributionModifBase._checkParams(self)
190
191        self._userData = self._params['value']
192
193        self._user = self.getAW().getUser()
194
195    def _getAnswer(self):
196
197        userToRemove = PrincipalHolder().getById(self._userData['id'])
198
199        if not userToRemove :
200            raise ServiceError("ERR-U0","User does not exist!")
201        elif isinstance(userToRemove, Avatar) or isinstance(userToRemove, Group) :
202            self._contribution.revokeAccess(userToRemove)
203
[9033fd]204methodMap = {
205    "addSubContribution": ContributionAddSubContribution,
206    "deleteSubContribution": ContributionDeleteSubContribution,
[a89f94]207    "getBooking": ContributionGetBooking,
208    "protection.getAllowedUsersList": ContributionProtectionUserList,
209    "protection.addAllowedUsers": ContributionProtectionAddUsers,
[35c7ed]210    "protection.removeAllowedUser": ContributionProtectionRemoveUser
[9033fd]211}
Note: See TracBrowser for help on using the repository browser.