From 65db196826751686d5482dc52053d160d52199fb Mon Sep 17 00:00:00 2001 From: nikhila05 Date: Wed, 20 Feb 2019 13:20:42 +0530 Subject: [PATCH] fixed issue of Normal user shouldn't get edit & delete options under actions in document list page, displaying contacts in account detail page, APISettings modal updated with website field and also CRUD opearations views respective to website field (#209) * added django storages, loading local or aws storages based on env variable, removed reset password option for loggedin user, fixed issue of account edit in account list, removed address text in leads create page, properly aligining attachments, fixed issue of unable to see assigned contacts in edit account page * added source column in leads list page, fixed issue converting leads to accounts in leads view page, displaying billing address details in accounts view page, added more colors for tags * fixed issue of Normal user shouldn't get edit & delete options under actions in document list page, displaying contacts in account detail page, APISettings modal updated with website field and also CRUD opearations views respective to website field --- accounts/templates/create_account.html | 17 +-- common/forms.py | 25 +++- common/migrations/0012_apisettings_website.py | 18 +++ common/models.py | 1 + common/templates/doc_create.html | 8 +- common/templates/doc_list.html | 19 ++- common/templates/settings/create.html | 38 +++++- common/templates/settings/list.html | 104 ++++++++++---- common/templates/settings/update.html | 36 ++++- common/templates/settings/view.html | 127 +++++++++++++++++- common/utils.py | 9 ++ common/views.py | 23 ++-- contacts/views.py | 6 + crm/settings.py | 2 +- leads/urls.py | 4 +- leads/views.py | 69 ++++++---- static/css/403.css | 43 ++++++ static/css/main.scss | 13 +- templates/403.html | 22 +++ templates/404.html | 2 +- templates/500.html | 2 +- 21 files changed, 485 insertions(+), 103 deletions(-) create mode 100644 common/migrations/0012_apisettings_website.py create mode 100644 static/css/403.css create mode 100644 templates/403.html diff --git a/accounts/templates/create_account.html b/accounts/templates/create_account.html index 8adf75ee..d06d0f55 100644 --- a/accounts/templates/create_account.html +++ b/accounts/templates/create_account.html @@ -129,17 +129,6 @@ {{ account_form.assigned_to.errors }} --> -
-
- - - {{ account_form.assigned_to.errors }} -
-
@@ -196,12 +185,13 @@ {% endblock js_block %} + diff --git a/common/forms.py b/common/forms.py index 776129a1..59fb48d5 100644 --- a/common/forms.py +++ b/common/forms.py @@ -1,3 +1,4 @@ +import re from django import forms from django.contrib.auth import authenticate from django.contrib.auth.forms import PasswordResetForm @@ -198,6 +199,19 @@ class UserCommentForm(forms.ModelForm): fields = ('comment', 'user', 'commented_by') +def find_urls(string): + # website_regex = "^((http|https)://)?([A-Za-z0-9.-]+\.[A-Za-z]{2,63})?$" # (http(s)://)google.com or google.com + # website_regex = "^https?://([A-Za-z0-9.-]+\.[A-Za-z]{2,63})?$" # (http(s)://)google.com + website_regex = "^https?://[A-Za-z0-9.-]+\.[A-Za-z]{2,63}$" # http(s)://google.com + website_regex_port = "^https?://[A-Za-z0-9.-]+\.[A-Za-z]{2,63}:[0-9]{2,4}$" # http(s)://google.com:8000 + url = re.findall(website_regex, string) + url_port = re.findall(website_regex_port, string) + if len(url) > 0 and url[0] != '': + return url + else: + return url_port + + class APISettingsForm(forms.ModelForm): def __init__(self, *args, **kwargs): @@ -215,4 +229,13 @@ class APISettingsForm(forms.ModelForm): class Meta: model = APISettings - fields = ('title', 'lead_assigned_to') + fields = ('title', 'lead_assigned_to', 'website') + + def clean_website(self): + website = self.data.get('website') + if website and not (website.startswith('http://') or website.startswith('https://')): + raise forms.ValidationError("Please provide valid schema") + if not len(find_urls(website)) > 0: + raise forms.ValidationError( + "Please provide a valid URL with schema and without trailing slash - Example: http://google.com") + return website diff --git a/common/migrations/0012_apisettings_website.py b/common/migrations/0012_apisettings_website.py new file mode 100644 index 00000000..ca8fa0a3 --- /dev/null +++ b/common/migrations/0012_apisettings_website.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1.7 on 2019-02-19 10:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('common', '0011_auto_20190218_1230'), + ] + + operations = [ + migrations.AddField( + model_name='apisettings', + name='website', + field=models.URLField(default='', max_length=255), + ), + ] diff --git a/common/models.py b/common/models.py index 7f05eae3..1b5f73b8 100644 --- a/common/models.py +++ b/common/models.py @@ -243,6 +243,7 @@ def generate_key(): class APISettings(models.Model): title = models.CharField(max_length=1000) apikey = models.CharField(max_length=16, blank=True) + website = models.URLField(max_length=255, default='') lead_assigned_to = models.ManyToManyField(User, related_name='lead_assignee_users') tags = models.ManyToManyField('accounts.Tags', blank=True) created_by = models.ForeignKey(User, related_name='settings_created_by', on_delete=models.SET_NULL, null=True) diff --git a/common/templates/doc_create.html b/common/templates/doc_create.html index 346913ce..bdeee5c8 100644 --- a/common/templates/doc_create.html +++ b/common/templates/doc_create.html @@ -25,14 +25,14 @@
- +
{{ errors.title }}
- +
{% if doc_obj %}{{doc_file_name}}{% endif %} @@ -43,7 +43,9 @@ {{ errors.shared_to.errors }} diff --git a/common/templates/doc_list.html b/common/templates/doc_list.html index 44be3629..0cd076a8 100644 --- a/common/templates/doc_list.html +++ b/common/templates/doc_list.html @@ -80,9 +80,11 @@ S.No Title - Created By + Created By + Created On Status Shared To + Download Actions {% endif %} @@ -106,6 +108,7 @@ {% endif %} + {{document.created_on}} {{document.status}} {% with shared_users=document.shared_to.all %} {% if shared_users %} @@ -113,13 +116,20 @@ {{ user.email }}
{% endfor %} {% else %} - Not Shared to any + Not shared with anyone {% endif %} {% endwith %} + + {% if request.user in document.shared_to.all or request.user == document.created_by or request.user.role == 'ADMIN' %} + Download + {% endif %} + - - + {% if request.user == document.created_by or request.user.role == 'ADMIN' %} + + + {% endif %} {% endfor %} @@ -177,3 +187,4 @@ }); {% endblock js_block %} + diff --git a/common/templates/settings/create.html b/common/templates/settings/create.html index d1d3881b..346a002b 100644 --- a/common/templates/settings/create.html +++ b/common/templates/settings/create.html @@ -10,7 +10,7 @@ {% endblock %} @@ -21,20 +21,26 @@
- {% if setting %}EDIT{% else %}CREATE{% endif %} SETTINGS + CREATE SETTINGS
- + {{ settings_form.title.errors }}
- {{ settings_form }} +
+
+ + + {{ settings_form.website.errors }} +
+
@@ -42,7 +48,7 @@ {{ settings_form.lead_assigned_to.errors }} @@ -59,6 +65,7 @@
+
{% if not setting %} @@ -80,6 +87,27 @@ + {% endblock js_block %} + diff --git a/common/templates/settings/update.html b/common/templates/settings/update.html index 73fa9dfe..ab1e6253 100644 --- a/common/templates/settings/update.html +++ b/common/templates/settings/update.html @@ -10,7 +10,8 @@ {% endblock %} @@ -21,7 +22,7 @@
- {% if setting %}EDIT{% else %}CREATE{% endif %} SETTINGS + EDIT SETTINGS
@@ -34,7 +35,13 @@
- {{ settings_form }} +
+
+ + + {{ settings_form.website.errors }} +
+
@@ -42,7 +49,7 @@ {{ settings_form.lead_assigned_to.errors }} @@ -80,6 +87,27 @@ +{% endblock js_block %} diff --git a/common/utils.py b/common/utils.py index 64c23fb0..7eb33001 100644 --- a/common/utils.py +++ b/common/utils.py @@ -570,3 +570,12 @@ def return_complete_address(self): else: address += self.get_country_display() return address + + +def get_client_ip(request): + x_forwarded_for = request.META.get('HTTP_X_FORWARDED_FOR') + if x_forwarded_for: + ip = x_forwarded_for.split(',')[0] + else: + ip = request.META.get('REMOTE_ADDR') + return ip diff --git a/common/views.py b/common/views.py index a1d74a8c..691b7f1f 100644 --- a/common/views.py +++ b/common/views.py @@ -601,13 +601,14 @@ def add_api_settings(request): settings_obj.tags.add(tag) if assign_to_list: settings_obj.lead_assigned_to.add(*assign_to_list) + success_url = reverse_lazy("common:api_settings") if request.POST.get("savenewform"): - return redirect('common:add_api_settings') - return redirect("common:api_settings") + success_url = reverse_lazy("common:add_api_settings") + data = {'success_url': success_url, 'error': False} + return JsonResponse(data) + else: - print (form.errors) - data = {'form': form, "setting": api_settings, - 'users': users, 'assign_to_list': assign_to_list} + return JsonResponse({'error': True, 'errors': form.errors}) else: data = {'form': form, "setting": api_settings, 'users': users, 'assign_to_list': assign_to_list} @@ -647,14 +648,14 @@ def update_api_settings(request, pk): if assign_to_list: settings_obj.lead_assigned_to.clear() settings_obj.lead_assigned_to.add(*assign_to_list) + success_url = reverse_lazy("common:api_settings") if request.POST.get("savenewform"): - return redirect('common:add_api_settings') - return redirect("common:api_settings") + success_url = reverse_lazy("common:add_api_settings") + data = {'success_url': success_url, 'error': False} + return JsonResponse(data) + else: - data = { - 'form': form, "setting": api_settings, 'users': users, 'assign_to_list': assign_to_list, - 'assigned_to_list': json.dumps([i.id for i in api_settings.lead_assigned_to.all() if i]) - } + return JsonResponse({'error': True, 'errors': form.errors}) else: data = { 'form': form, "setting": api_settings, 'users': users, 'assign_to_list': assign_to_list, diff --git a/contacts/views.py b/contacts/views.py index 33862ee9..5a36165d 100644 --- a/contacts/views.py +++ b/contacts/views.py @@ -13,6 +13,7 @@ from common.forms import BillingAddressForm from common.utils import COUNTRIES from contacts.models import Contact from contacts.forms import ContactForm, ContactCommentForm, ContactAttachmentForm +from accounts.models import Account class ContactsListView(LoginRequiredMixin, TemplateView): @@ -77,6 +78,11 @@ class CreateContactView(LoginRequiredMixin, CreateView): contact_obj.address = address_obj contact_obj.created_by = self.request.user contact_obj.save() + if self.request.GET.get('view_account', None): + if Account.objects.filter(id= + int(self.request.GET.get('view_account'))).exists(): + Account.objects.get(id= + int(self.request.GET.get('view_account'))).contacts.add(contact_obj) return self.form_valid(form) return self.form_invalid(form) diff --git a/crm/settings.py b/crm/settings.py index 55542847..bb270449 100644 --- a/crm/settings.py +++ b/crm/settings.py @@ -7,7 +7,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = 'mwx@&97%!$fx_*zgj(2ygi^(s=oh5j(cqb$=+-mkd9scbt!0v0' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = True +DEBUG = False ALLOWED_HOSTS = ['*'] diff --git a/leads/urls.py b/leads/urls.py index c9fa1e52..4d23c0c5 100644 --- a/leads/urls.py +++ b/leads/urls.py @@ -2,7 +2,7 @@ from django.urls import path from leads.views import ( LeadListView, CreateLeadView, LeadDetailView, UpdateLeadView, DeleteLeadView, ConvertLeadView, GetLeadsView, AddCommentView, UpdateCommentView, DeleteCommentView, - AddAttachmentsView, DeleteAttachmentsView + AddAttachmentsView, DeleteAttachmentsView, create_lead_from_site ) @@ -12,6 +12,8 @@ app_name = 'leads' urlpatterns = [ path('list/', LeadListView.as_view(), name='list'), path('create/', CreateLeadView.as_view(), name='add_lead'), + # create_lead_from_site + path('create/from-site/', create_lead_from_site, name="create_lead_from_site"), path('/view/', LeadDetailView.as_view(), name="view_lead"), path('/edit/', UpdateLeadView.as_view(), name="edit_lead"), path('/delete/', DeleteLeadView.as_view(), name="remove_lead"), diff --git a/leads/views.py b/leads/views.py index f1d951b9..23db0336 100644 --- a/leads/views.py +++ b/leads/views.py @@ -12,8 +12,8 @@ from django.views.generic import ( CreateView, UpdateView, DetailView, ListView, TemplateView, View) from accounts.models import Account, Tags -from common.models import User, Comment, Attachments -from common.utils import LEAD_STATUS, LEAD_SOURCE, COUNTRIES +from common.models import User, Comment, Attachments, APISettings +from common.utils import LEAD_STATUS, LEAD_SOURCE, COUNTRIES, get_client_ip from common import status from contacts.models import Contact from leads.models import Lead @@ -581,7 +581,7 @@ class DeleteAttachmentsView(LoginRequiredMixin, View): def post(self, request, *args, **kwargs): self.object = get_object_or_404(Attachments, id=request.POST.get("attachment_id")) if ( - request.user == self.object.created_by or request.user.is_superuser or + request.user == self.object.created_by or request.user.is_superuser or request.user.role == 'ADMIN' ): self.object.delete() @@ -593,30 +593,45 @@ class DeleteAttachmentsView(LoginRequiredMixin, View): def create_lead_from_site(request): + if request.method == "POST": + # ip_addres = get_client_ip(request) + # website_address = request.scheme + '://' + ip_addres + api_key = request.POST.get('apikey') + # api_setting = APISettings.objects.filter(website=website_address, apikey=api_key).first() + api_setting = APISettings.objects.filter(apikey=api_key).first() + if not api_setting: + return JsonResponse({ + 'error': True, 'message': "You don't have permission, please contact the admin!."}, + status=status.HTTP_400_BAD_REQUEST) - if request.POST.get("email") and request.POST.get("full_name"): - user = User.objects.filter(is_admin=True, is_active=True).first() - lead = Lead.objects.create( - title=request.POST.get("full_name"), - status="assigned", source="micropyramid.com", - description=request.POST.get("message"), - email=request.POST.get("email"), phone=request.POST.get("phone"), - is_active=True, created_by=user) - lead.assigned_to.add(user) - # Send Email to Assigned Users - site_address = request.scheme + '://' + request.META['HTTP_HOST'] - send_lead_assigned_emails.delay(lead.id, [user.id], site_address) - # Create Contact - contact = Contact.objects.create( - first_name=request.POST.get("full_name"), - email=request.POST.get("email"), phone=request.POST.get("phone"), - description=request.POST.get("message"), created_by=user, - is_active=True) - contact.assigned_to.add(user) + if api_setting and request.POST.get("email") and request.POST.get("full_name"): + # user = User.objects.filter(is_admin=True, is_active=True).first() + user = api_setting.created_by + lead = Lead.objects.create( + title=request.POST.get("full_name"), + status="assigned", source=api_setting.website, + description=request.POST.get("message"), + email=request.POST.get("email"), phone=request.POST.get("phone"), + is_active=True, created_by=user) + lead.assigned_to.add(user) + # Send Email to Assigned Users + site_address = request.scheme + '://' + request.META['HTTP_HOST'] + send_lead_assigned_emails.delay(lead.id, [user.id], site_address) + # Create Contact + contact = Contact.objects.create( + first_name=request.POST.get("full_name"), + email=request.POST.get("email"), phone=request.POST.get("phone"), + description=request.POST.get("message"), created_by=user, + is_active=True) + contact.assigned_to.add(user) - lead.contacts.add(contact) + lead.contacts.add(contact) - return JsonResponse({'error': False, 'message': "Lead Created sucessfully."}, - status=status.HTTP_201_CREATED) - return JsonResponse({'error': True, 'message': "In-valid data."}, - status=status.HTTP_400_BAD_REQUEST) + return JsonResponse({'error': False, 'message': "Lead Created sucessfully."}, + status=status.HTTP_201_CREATED) + return JsonResponse({'error': True, 'message': "In-valid data."}, + status=status.HTTP_400_BAD_REQUEST) + else: + return JsonResponse({ + 'error': True, 'message': "In-valid request method."}, + status=status.HTTP_400_BAD_REQUEST) diff --git a/static/css/403.css b/static/css/403.css new file mode 100644 index 00000000..4c46ea5b --- /dev/null +++ b/static/css/403.css @@ -0,0 +1,43 @@ +body { + color: #666; + text-align: center; + font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; + margin: auto; + font-size: 14px; +} + +h1 { + font-size: 56px; + line-height: 100px; + font-weight: normal; + color: #456; +} + +h2 { + font-size: 24px; + color: #666; + line-height: 1.5em; +} + +h3 { + color: #456; + font-size: 20px; + font-weight: normal; + line-height: 28px; +} + +hr { + max-width: 800px; + margin: 18px auto; + border: 0; + border-top: 1px solid #eee; + border-bottom: 1px solid white; +} + +img { + max-width: 40vw; +} + +.container { + margin: auto 20px; +} diff --git a/static/css/main.scss b/static/css/main.scss index 052cb074..c137e2fa 100644 --- a/static/css/main.scss +++ b/static/css/main.scss @@ -1476,4 +1476,15 @@ pre{ font-size: 1.3rem; font-weight: 600; } -} \ No newline at end of file +} + +.copy-text { + border: 2px solid #dadada; + border-style: dashed; + padding: 10px; +} + +.help-text{ + font-size: 12px; + color: #a7a7a7a7; +} diff --git a/templates/403.html b/templates/403.html new file mode 100644 index 00000000..412dc01a --- /dev/null +++ b/templates/403.html @@ -0,0 +1,22 @@ +{% load staticfiles %} + + + + + The page you're looking for could not be found (404) + + + + +

+ 404 +

+
+

The page you're looking for could not be found.

+
+

Make sure the address is correct and that the page hasn't moved.

+

Please contact your administrator if you think this is a mistake.

+ GO back Home CRM Home +
+ + diff --git a/templates/404.html b/templates/404.html index af236bd0..ad03c50f 100644 --- a/templates/404.html +++ b/templates/404.html @@ -58,7 +58,7 @@

The page you're looking for could not be found.


Make sure the address is correct and that the page hasn't moved.

-

Please contact your GitLab administrator if you think this is a mistake.

+

Please contact your administrator if you think this is a mistake.

GO back Home CRM Home
diff --git a/templates/500.html b/templates/500.html index db216ae1..1a5f81c4 100644 --- a/templates/500.html +++ b/templates/500.html @@ -58,7 +58,7 @@

The page you're looking for could not be found.


Make sure the address is correct and that the page hasn't moved.

-

Please contact your GitLab administrator if you think this is a mistake.

+

Please contact your administrator if you think this is a mistake.

GO back Home CRM Home