def email_participants(request, share, subdir=None): try: subject = request.POST.get('subject') emails = request.POST.getlist('emails', []) users = [ u for u in get_users_with_perms(share, attach_perms=False, with_superusers=False, with_group_users=True) ] if len(emails) > 0: users = [ u for u in User.objects.filter( id__in=[u.id for u in users]).filter(email__in=emails) ] body = request.POST.get('body') users.append(share.owner) email_users(users, ctx_dict={}, subject=subject, body=body, from_email=request.user.email, content_subtype='plain') response = {'status': 'success', 'sent_to': [u.email for u in users]} return json_response(response) except Exception, e: return JsonResponse({'errors': [str(e)]}, status=400)
def email_participants(request,share,subdir=None): try: subject = request.POST.get('subject') body = request.POST.get('body') users = [u for u in get_users_with_perms(share, attach_perms=False, with_superusers=False, with_group_users=True)] users.append(share.owner) email_users(users, ctx_dict={}, subject=subject, body=body,from_email=request.user.email) response = {'status':'success','sent_to':[u.email for u in users]} return json_response(response) except Exception, e: return JsonResponse({'errors':[str(e)]},status=400)
def set_permissions(request,share,json=None): from smtplib import SMTPException emailed=[] created=[] failed=[] # if not request.user.has_perm('admin',share): # return json_response({'status':'error','error':'You do not have permission to write to this share.'}) if json.has_key('groups'): for group, permissions in json['groups'].iteritems(): g = Group.objects.get(id__iexact=group) current_perms = get_perms(g,share) removed_perms = list(set(current_perms) - set(permissions)) added_perms = list(set(permissions) - set(current_perms)) for u in g.user_set.all(): if len(share.get_user_permissions(u,user_specific=True)) == 0 and len(added_perms) > 0 and json['email']: email_users([u],'share/share_subject.txt','share/share_email_body.txt',{'user':u,'share':share,'sharer':request.user,'site_url':SITE_URL}) emailed.append(u.username) for perm in removed_perms: remove_perm(perm,g,share) for perm in added_perms: assign_perm(perm,g,share) if json.has_key('users'): for username, permissions in json['users'].iteritems(): username = username.lower() try: u = User.objects.get(username__iexact=username) if len(share.get_user_permissions(u,user_specific=True)) == 0 and json['email']: try: email_users([u],'share/share_subject.txt','share/share_email_body.txt',{'user':u,'share':share,'sharer':request.user,'site_url':SITE_URL}) emailed.append(username) except: failed.append(username) except: if len(permissions) > 0: password = User.objects.make_random_password() u = User(username=username,email=username) u.set_password(password) u.save() try: email_users([u],'share/share_subject.txt','share/share_new_email_body.txt',{'user':u,'password':password,'share':share,'sharer':request.user,'site_url':SITE_URL}) created.append(username) except: failed.append(username) u.delete() current_perms = share.get_user_permissions(u,user_specific=True) print 'CURRENT' print current_perms print 'PERMISSIONS' print permissions removed_perms = list(set(current_perms) - set(permissions)) added_perms = list(set(permissions) - set(current_perms)) print 'ADDING: ' print added_perms print 'REMOVING: ' print removed_perms for perm in removed_perms: if u.username not in failed: remove_perm(perm,u,share) for perm in added_perms: if u.username not in failed: assign_perm(perm,u,share) data = share.get_permissions(user_specific=True) data['messages']=[] if len(emailed) > 0: data['messages'].append({'type':'info','content':'%s has/have been emailed'%', '.join(emailed)}) if len(created) > 0: data['messages'].append({'type':'info','content':'Accounts has/have been created and emails have been sent to the following email addresses: %s'%', '.join(created)}) if len(failed) > 0: data['messages'].append({'type':'info','content':'Delivery has failed to the following addresses: %s'%', '.join(failed)}) data['json']=json return json_response(data)
def set_permissions(request,share,json=None): from smtplib import SMTPException emailed=[] created=[] failed=[] # if not request.user.has_perm('admin',share): # return json_response({'status':'error','error':'You do not have permission to write to this share.'}) if json.has_key('groups'): for group, permissions in json['groups'].iteritems(): g = Group.objects.get(id=group) current_perms = get_perms(g,share) removed_perms = list(set(current_perms) - set(permissions)) added_perms = list(set(permissions) - set(current_perms)) for u in g.user_set.all(): if len(share.get_user_permissions(u,user_specific=True)) == 0 and len(added_perms) > 0 and json['email']: email_users([u],'share/share_subject.txt','share/share_email_body.txt',{'user':u,'share':share,'sharer':request.user,'site_url':SITE_URL}) emailed.append(u.username) for perm in removed_perms: remove_perm(perm,g,share) for perm in added_perms: assign_perm(perm,g,share) if json.has_key('users'): for username, permissions in json['users'].iteritems(): try: u = User.objects.get(username=username) if len(share.get_user_permissions(u,user_specific=True)) == 0 and json['email']: try: email_users([u],'share/share_subject.txt','share/share_email_body.txt',{'user':u,'share':share,'sharer':request.user,'site_url':SITE_URL}) emailed.append(username) except: failed.append(username) except: if len(permissions) > 0: password = User.objects.make_random_password() u = User(username=username,email=username) u.set_password(password) u.save() try: email_users([u],'share/share_subject.txt','share/share_new_email_body.txt',{'user':u,'password':password,'share':share,'sharer':request.user,'site_url':SITE_URL}) created.append(username) except: failed.append(username) u.delete() current_perms = share.get_user_permissions(u,user_specific=True) print 'CURRENT' print current_perms print 'PERMISSIONS' print permissions removed_perms = list(set(current_perms) - set(permissions)) added_perms = list(set(permissions) - set(current_perms)) print 'ADDING: ' print added_perms print 'REMOVING: ' print removed_perms for perm in removed_perms: if u.username not in failed: remove_perm(perm,u,share) for perm in added_perms: if u.username not in failed: assign_perm(perm,u,share) data = share.get_permissions(user_specific=True) data['messages']=[] if len(emailed) > 0: data['messages'].append({'type':'info','content':'%s has/have been emailed'%', '.join(emailed)}) if len(created) > 0: data['messages'].append({'type':'info','content':'Accounts has/have been created and emails have been sent to the following email addresses: %s'%', '.join(created)}) if len(failed) > 0: data['messages'].append({'type':'info','content':'Delivery has failed to the following addresses: %s'%', '.join(failed)}) data['json']=json ShareFTPUser.update_share_ftp_users(share) return json_response(data)