def create_case_add_attachments(request, bean_case): try: files = request.FILES.getlist('update-case-attachment') if files: case_update = Bean('AOP_Case_Updates') case_update['contact_id'] = request.user.userattr.contact_id case_update['case_id'] = bean_case['id'] case_update['name'] = bean_case['description'][:45] case_update['description'] = bean_case['description'].replace('\n', '<br>') case_update['internal'] = 0 SuiteCRM().save_bean(case_update) if case_update['id']: for f in files: note = Bean('Notes') note['name'] = f.name note['parent_type'] = 'AOP_Case_Updates' note['parent_id'] = case_update['id'] note['contact_id'] = request.user.userattr.contact_id SuiteCRM().save_bean(note) if note['id']: SuiteCRM().set_note_attachment( note['id'], f.name, base64.b64encode(f.read()) ) return True except Exception: pass return False
def module_remove_record(request, module): if request.method == 'POST' and 'id' in request.POST: id = request.POST['id'] if user_can_delete_module(request.user, module) \ and user_is_linked_to_record(request.user, module, id): bean = Bean(module) bean['id'] = id bean['deleted'] = 1 try: SuiteCRM().save_bean(bean) return JsonResponse({ "status" : "Success", "msg" : _("Record deleted successfully.") }) except Exception as e: return JsonResponse({ "status" : "Error", "error" : _("Error deleting record.") }, status = 400) else: return JsonResponse({ "status" : "Error", "error" : _("Insufficient permissions.") }, status = 400) return JsonResponse({ "status" : "Error", "error" : _("Invalid request.") }, status = 400)
def create_portal_user(contact): username = contact['email1'] password = User.objects.make_random_password() try: user = User.objects.get(username=username) return JsonResponse( { "status": "Error", "error": "An account with this email already exists" }, status=400) except: pass user = User.objects.create_user(username=username, email=username, password=password, first_name=contact['first_name'], last_name=contact['last_name']) UserAttr(user=user, contact_id=contact['id'], account_id=contact['account_id']).save() default_role = get_default_role() if default_role: RoleUser(user=user, role=default_role).save() contact2 = Bean('Contacts') contact2['id'] = contact['id'] contact2['joomla_account_id'] = user.id contact2['joomla_account_access'] = password SuiteCRM().save_bean(contact2) return JsonResponse({"success": True})
def reopen_case(request): if user_can_read_module(request.user, 'Cases') and request.method == 'POST' \ and 'case-id' in request.POST \ and user_is_linked_to_case(request.user, request.POST['case-id']): try: bean = Bean('Cases') bean['id'] = request.POST['case-id'] bean['state'] = 'Open' bean['status'] = 'Open_New' SuiteCRM().save_bean(bean) except Exception: pass url = reverse('module_detail', kwargs={ 'module': 'Cases', 'id': request.POST['case-id'] }) return HttpResponseRedirect(url) else: context = basepage_processor(request) template = loader.get_template('portal/insufficient_permissions.html') return HttpResponse(template.render(context, request))
def get_bean_from_post(module, view, data): module_fields = SuiteCRMCached().get_module_fields(module)['module_fields'] view_def = Layout.objects.get(module=module, view=view) fields = json.loads(view_def.fields) bean = Bean(module) default_values = {} try: module_def = ModuleDefinitionFactory.get_module_definition(module) default_values = module_def.default_values except Exception: pass for row in fields: for field in row: if field in module_fields: if field in data: value = data[field] field_def = module_fields[field] field_type = field_def['type'] if field_type == 'multienum': bean[field] = encode_multienum(data.getlist(field)) elif field_type == 'datetime' or field_type == 'datetimecombo': bean[field] = iso_to_datetime(value) elif field_type == 'relate': relate_id_field = field_def['id_name'] if relate_id_field in data: bean[relate_id_field] = data[relate_id_field] elif field_type == 'parent_type': if 'parent_id' in data: bean[field] = value bean['parent_id'] = data['parent_id'] else: bean[field] = value if view == 'create': for field, value in default_values.items(): if field not in data: bean[field] = value return bean
def add_case_update(request): if user_can_read_module(request.user, 'Cases') and request.method == 'POST': if request.method == 'POST' and 'case-id' in request.POST \ and 'update-case-text' in request.POST \ and user_is_linked_to_case(request.user, request.POST['case-id']): update_case_text = request.POST['update-case-text'].strip() if not update_case_text: return JsonResponse({ "status" : "Error", "error" : _("Empty case updates are not allowed.") }, status = 400) case_update = Bean('AOP_Case_Updates') case_update['contact_id'] = request.user.userattr.contact_id case_update['case_id'] = request.POST['case-id'] case_update['name'] = update_case_text[:45] case_update['description'] = update_case_text.replace('\n', '<br>') case_update['internal'] = 0 try: SuiteCRM().save_bean(case_update) if case_update['id']: for f in request.FILES.getlist('update-case-attachment'): note = Bean('Notes') note['name'] = f.name note['parent_type'] = 'AOP_Case_Updates' note['parent_id'] = case_update['id'] note['contact_id'] = request.user.userattr.contact_id SuiteCRM().save_bean(note) if note['id']: SuiteCRM().set_note_attachment( note['id'], f.name, base64.b64encode(f.read()) ) else: return JsonResponse({ "status" : "Error", "error" : _("An error occurred while uploading the attachment(s).") }, status = 400) else: return JsonResponse({ "status" : "Error", "error" : _("An error occurred while creating the case update.") }, status = 400) return JsonResponse({ "status" : "Success", "msg" : _("The case update has been added successfully."), "case_update" : render_to_string( 'portal/module_detail_case_update.html', { "update" : get_case_update(case_update['id']), "show" : True } ) }) except: return JsonResponse({ "status" : "Error", "error" : _("An error occurred while updating the case.") }, status = 400) return JsonResponse({ "status" : "Error", "error" : _("Invalid request.") }, status = 400)