| 207 | return False |
| 208 | |
| 209 | def new(self): |
| 210 | |
| 211 | # NEW is untested after refactor |
| 212 | spec_list = [ |
| 213 | {'email': str}, |
| 214 | {'permission_type': str}, |
| 215 | {'note': None} |
| 216 | ] |
| 217 | |
| 218 | self.log, input = regular_input.input_check_many( |
| 219 | spec_list = spec_list, |
| 220 | log = self.log, |
| 221 | untrusted_input = self.user_dict) |
| 222 | |
| 223 | self.check_free_tier_member_limits() |
| 224 | |
| 225 | if log_has_error(self.log): |
| 226 | return |
| 227 | |
| 228 | # TODO review if we should use the validate() function for email |
| 229 | # currently in user/account/account_new |
| 230 | # and if that validate function is also striping whitespace as expected. |
| 231 | # wonder if that applies to login / other areas too... |
| 232 | |
| 233 | input['email'] = input['email'].strip() # remove whitespace which |
| 234 | # is especially relevent here because we are checking if the user |
| 235 | # exists |
| 236 | |
| 237 | self.user_to_modify = User.get_by_email(self.session, input['email']) |
| 238 | |
| 239 | if self.user_to_modify == self.user_who_made_request: |
| 240 | self.log['error']['user_who_made_request'] = "You are already on the project." |
| 241 | return |
| 242 | # Assumes if user exists to add permissions directly |
| 243 | if self.user_to_modify: |
| 244 | |
| 245 | permission_result, self.log = Project_permissions.add( |
| 246 | session = self.session, |
| 247 | permission = input['permission_type'], |
| 248 | user = self.user_to_modify, |
| 249 | sub_type = self.project_string_id, |
| 250 | log = self.log) |
| 251 | if permission_result is False or regular_log.log_has_error(self.log): |
| 252 | return |
| 253 | |
| 254 | RoleMemberObject.new( |
| 255 | session = self.session, |
| 256 | default_role_name = ProjectDefaultRoles[input['permission_type'].lower()], |
| 257 | member_id = self.user_to_modify.member_id, |
| 258 | object_id = self.project.id, |
| 259 | object_type = ValidObjectTypes.project |
| 260 | ) |
| 261 | if self.project not in self.user_to_modify.projects: |
| 262 | self.user_to_modify.projects.append(self.project) |
| 263 | |
| 264 | if permission_result is False or regular_log.log_has_error(self.log): |
| 265 | return |
| 266 | |