| 1 | from MaKaC.services.implementation.base import ProtectedModificationService |
|---|
| 2 | from MaKaC.services.implementation.base import ProtectedDisplayService |
|---|
| 3 | from MaKaC.services.implementation.base import ParameterManager |
|---|
| 4 | from MaKaC.services.implementation.roomBooking import GetBookingBase |
|---|
| 5 | |
|---|
| 6 | from MaKaC.services.interface.rpc.common import ServiceError, ServiceAccessError |
|---|
| 7 | |
|---|
| 8 | from MaKaC.common.PickleJar import DictPickler |
|---|
| 9 | |
|---|
| 10 | import MaKaC.conference as conference |
|---|
| 11 | from MaKaC.services.implementation.base import TextModificationBase |
|---|
| 12 | from MaKaC.services.implementation.base import HTMLModificationBase |
|---|
| 13 | from MaKaC.services.implementation.base import DateTimeModificationBase |
|---|
| 14 | from MaKaC.common.fossilize import fossilize |
|---|
| 15 | from MaKaC.user import PrincipalHolder, Avatar, Group |
|---|
| 16 | |
|---|
| 17 | class ContributionBase(object): |
|---|
| 18 | |
|---|
| 19 | def _checkParams( self ): |
|---|
| 20 | try: |
|---|
| 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.") |
|---|
| 30 | |
|---|
| 31 | try: |
|---|
| 32 | self._target = self._contribution = self._conf.getContributionById(self._params["contribution"]) |
|---|
| 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.") |
|---|
| 41 | |
|---|
| 42 | # create a parameter manager that checks the consistency of passed parameters |
|---|
| 43 | self._pm = ParameterManager(self._params) |
|---|
| 44 | |
|---|
| 45 | class ContributionDisplayBase(ProtectedDisplayService, ContributionBase): |
|---|
| 46 | |
|---|
| 47 | def _checkParams(self): |
|---|
| 48 | ContributionBase._checkParams(self) |
|---|
| 49 | ProtectedDisplayService._checkParams(self) |
|---|
| 50 | |
|---|
| 51 | class ContributionModifBase(ProtectedModificationService, ContributionBase): |
|---|
| 52 | |
|---|
| 53 | def _checkParams(self): |
|---|
| 54 | ContributionBase._checkParams(self) |
|---|
| 55 | ProtectedModificationService._checkParams(self) |
|---|
| 56 | |
|---|
| 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) |
|---|
| 62 | |
|---|
| 63 | class ContributionTextModificationBase(TextModificationBase, ContributionBase): |
|---|
| 64 | pass |
|---|
| 65 | |
|---|
| 66 | class ContributionHTMLModificationBase(HTMLModificationBase, ContributionBase): |
|---|
| 67 | pass |
|---|
| 68 | |
|---|
| 69 | class ContributionDateTimeModificationBase (DateTimeModificationBase, ContributionBase): |
|---|
| 70 | pass |
|---|
| 71 | |
|---|
| 72 | class ContributionAddSubContribution(ContributionModifBase): |
|---|
| 73 | def _checkParams(self): |
|---|
| 74 | ContributionModifBase._checkParams(self) |
|---|
| 75 | |
|---|
| 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="") |
|---|
| 80 | |
|---|
| 81 | # these are required |
|---|
| 82 | self._duration = self._pm.extract("duration", pType=int) |
|---|
| 83 | self._title = self._pm.extract("title", pType=str) |
|---|
| 84 | |
|---|
| 85 | def __addPresenters(self, subcontrib): |
|---|
| 86 | |
|---|
| 87 | # add each presenter |
|---|
| 88 | for presenterValues in self._presenters: |
|---|
| 89 | |
|---|
| 90 | # magically update a new ContributionParticipation with JSON data, using the DictPickler |
|---|
| 91 | presenter = conference.SubContribParticipation() |
|---|
| 92 | DictPickler.update(presenter, presenterValues) |
|---|
| 93 | |
|---|
| 94 | subcontrib.newSpeaker(presenter) |
|---|
| 95 | |
|---|
| 96 | def _getAnswer(self): |
|---|
| 97 | # create the sub contribution |
|---|
| 98 | sc = self._target.newSubContribution() |
|---|
| 99 | |
|---|
| 100 | sc.setTitle( self._title ) |
|---|
| 101 | sc.setDescription( self._description ) |
|---|
| 102 | # separate the keywords using newlines |
|---|
| 103 | sc.setKeywords('\n'.join(self._keywords)) |
|---|
| 104 | sc.setDuration( self._duration / 60, \ |
|---|
| 105 | self._duration % 60 ) |
|---|
| 106 | |
|---|
| 107 | self.__addPresenters(sc) |
|---|
| 108 | |
|---|
| 109 | # log the event |
|---|
| 110 | logInfo = sc.getLogInfo() |
|---|
| 111 | logInfo["subject"] = "Create new subcontribution: %s"%sc.getTitle() |
|---|
| 112 | self._target.getConference().getLogHandler().logAction(logInfo, "Timetable/SubContribution", self._getUser()) |
|---|
| 113 | |
|---|
| 114 | class ContributionDeleteSubContribution(ContributionModifBase): |
|---|
| 115 | |
|---|
| 116 | # contribution.deleteSubContribution |
|---|
| 117 | |
|---|
| 118 | _asyndicoDoc = { |
|---|
| 119 | 'summary': 'Deletes a subcontribution, given the conference, contribution and subcontribution IDs.', |
|---|
| 120 | 'params': [{'name': 'conference', 'type': 'str'}, |
|---|
| 121 | {'name': 'contribution', 'type': 'str'}, |
|---|
| 122 | {'name': 'subcontribution', 'type': 'str'}], |
|---|
| 123 | 'return': None |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | def _checkParams(self): |
|---|
| 127 | ContributionModifBase._checkParams(self) |
|---|
| 128 | |
|---|
| 129 | subContId = self._pm.extract("subcontribution", pType=str, allowEmpty=False) |
|---|
| 130 | |
|---|
| 131 | self._subContribution = self._contribution.getSubContributionById(subContId) |
|---|
| 132 | |
|---|
| 133 | def _getAnswer(self): |
|---|
| 134 | self._subContribution.getOwner().removeSubContribution(self._subContribution) |
|---|
| 135 | |
|---|
| 136 | class ContributionGetBooking(ContributionDisplayBase, GetBookingBase): |
|---|
| 137 | pass |
|---|
| 138 | |
|---|
| 139 | class ContributionProtectionUserList(ContributionModifBase): |
|---|
| 140 | |
|---|
| 141 | def _getAnswer(self): |
|---|
| 142 | #will use IAvatarFossil or IGroupFossil |
|---|
| 143 | return fossilize(self._contribution.getAllowedToAccessList()) |
|---|
| 144 | |
|---|
| 145 | class ContributionProtectionAddUsers(ContributionModifBase): |
|---|
| 146 | |
|---|
| 147 | def _checkParams(self): |
|---|
| 148 | ContributionModifBase._checkParams(self) |
|---|
| 149 | |
|---|
| 150 | self._usersData = self._params['value'] |
|---|
| 151 | self._user = self.getAW().getUser() |
|---|
| 152 | |
|---|
| 153 | def _getAnswer(self): |
|---|
| 154 | |
|---|
| 155 | for user in self._usersData : |
|---|
| 156 | |
|---|
| 157 | userToAdd = PrincipalHolder().getById(user['id']) |
|---|
| 158 | |
|---|
| 159 | if not userToAdd : |
|---|
| 160 | raise ServiceError("ERR-U0","User does not exist!") |
|---|
| 161 | |
|---|
| 162 | self._contribution.grantAccess(userToAdd) |
|---|
| 163 | |
|---|
| 164 | class ContributionProtectionRemoveUser(ContributionModifBase): |
|---|
| 165 | |
|---|
| 166 | def _checkParams(self): |
|---|
| 167 | ContributionModifBase._checkParams(self) |
|---|
| 168 | |
|---|
| 169 | self._userData = self._params['value'] |
|---|
| 170 | |
|---|
| 171 | self._user = self.getAW().getUser() |
|---|
| 172 | |
|---|
| 173 | def _getAnswer(self): |
|---|
| 174 | |
|---|
| 175 | userToRemove = PrincipalHolder().getById(self._userData['id']) |
|---|
| 176 | |
|---|
| 177 | if not userToRemove : |
|---|
| 178 | raise ServiceError("ERR-U0","User does not exist!") |
|---|
| 179 | elif isinstance(userToRemove, Avatar) or isinstance(userToRemove, Group) : |
|---|
| 180 | self._contribution.revokeAccess(userToRemove) |
|---|
| 181 | |
|---|
| 182 | methodMap = { |
|---|
| 183 | "addSubContribution": ContributionAddSubContribution, |
|---|
| 184 | "deleteSubContribution": ContributionDeleteSubContribution, |
|---|
| 185 | "getBooking": ContributionGetBooking, |
|---|
| 186 | "protection.getAllowedUsersList": ContributionProtectionUserList, |
|---|
| 187 | "protection.addAllowedUsers": ContributionProtectionAddUsers, |
|---|
| 188 | "protection.removeAllowedUser": ContributionProtectionRemoveUser |
|---|
| 189 | } |
|---|