Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion blt/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
ShowBughuntView,
SlackCallbackView,
accept_bug,
dashboard_view,
delete_manager,
delete_prize,
edit_prize,
Expand Down Expand Up @@ -811,7 +812,8 @@
RegisterOrganizationView.as_view(),
name="register_organization",
),
path("organization/dashboard/", Organization_view, name="organization_view"),
path("organization/view", Organization_view, name="organization_view"),
path("organization/dashboard/", dashboard_view, name="organization_dashboard"),
path(
"organization/<int:id>/dashboard/analytics/",
OrganizationDashboardAnalyticsView.as_view(),
Expand Down
8 changes: 7 additions & 1 deletion website/templates/includes/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,13 @@ <h3 class="font-semibold">Notifications</h3>
<li>
<a href="{% url 'organization_view' %}"
class="flex items-center gap-1.5 py-2 px-3 hover:bg-gray-100 rounded-md hover:text-red-600 transition-colors duration-200 font-medium">
<i class="fa fa-building fa-fw"></i> {% trans "Organization Dashboard" %}
<i class="fa fa-building fa-fw"></i> {% trans "View Organization" %}
</a>
</li>
<li>
<a href="{% url 'organization_dashboard' %}"
class="flex items-center gap-1.5 py-2 px-3 hover:bg-gray-100 rounded-md hover:text-red-600 transition-colors duration-200 font-medium">
<i class="fa fa-gauge fa-fw"></i> {% trans "Organization Dashboard" %}
</a>
</li>
<li class="border my-2 w-full"></li>
Expand Down
7 changes: 6 additions & 1 deletion website/templates/includes/navbar.html
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,12 @@
</li>
<li>
<a href="{% url 'organization_view' %}">
<i class="fa fa-building fa-fw"></i> {% trans "Organization Dashboard" %}
<i class="fa fa-building fa-fw"></i> {% trans "View Organization" %}
</a>
</li>
<li>
<a href="{% url 'organization_dashboard' %}">
<i class="fa fa-gauge fa-fw"></i> {% trans "Organization Dashboard" %}
</a>
</li>
<!-- divider -->
Expand Down
2 changes: 1 addition & 1 deletion website/templates/sitemap.html
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ <h2 class="text-5xl text-red-500 font-bold">Sitemap</h2>
</span>
</div>
<ul class="flex flex-col">
<a href="{% url 'organization_view' %}"
<a href="{% url 'organization_dashboard' %}"
class="flex items-center gap-1 text-black cursor-pointer hover:bg-gray-100 group transition duration-200 px-4 py-2 rounded-lg">
<i class="fas fa-tachometer-alt w-5 h-5 mr-1 align-middle text-red-500"></i>
<p class="font-medium text-black/80 group-hover:text-red-500 transition duration-200">Dashboard</p>
Expand Down
46 changes: 37 additions & 9 deletions website/views/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,13 @@ def wrapper(self, request, *args, **kwargs):
return wrapper


def Organization_view(request, *args, **kwargs):
user = request.user

def _get_user_organization(user):
"""Helper function to find and return a user's organization."""
if not user.is_active:
messages.info(request, "Email not verified.")
return redirect("/")
return None, "Email not verified."

if isinstance(user, AnonymousUser):
messages.error(request, "Please login to access your organization.")
return redirect("/accounts/login/")
return None, "Please login to access your organization."

user_organizations = Organization.objects.filter(Q(admin=user) | Q(managers=user))
if not user_organizations.exists():
Expand All @@ -93,15 +90,46 @@ def Organization_view(request, *args, **kwargs):
# Check if any of these domains belong to a organization
organizations_with_user_domains = Organization.objects.filter(domain__in=user_domains)
if not organizations_with_user_domains.exists():
messages.error(request, "You do not have a organization, create one.")
return redirect("register_organization")
return None, "You do not have a organization, create one."

# Get the organization to redirect to
organization = user_organizations.first() or organizations_with_user_domains.first()
return organization, None


def Organization_view(request, *args, **kwargs):
user = request.user

organization, error_message = _get_user_organization(user)
if error_message:
messages.error(request, error_message)
if error_message == "Email not verified.":
return redirect("/")
elif error_message == "Please login to access your organization.":
return redirect("/accounts/login/")
else:
return redirect("register_organization")

return redirect("organization_detail", slug=organization.slug)


def dashboard_view(request, *args, **kwargs):
user = request.user

organization, error_message = _get_user_organization(user)
if error_message:
messages.error(request, error_message)
if error_message == "Email not verified.":
return redirect("/")
elif error_message == "Please login to access your organization.":
return redirect("/accounts/login/")
else:
return redirect("register_organization")

# Redirect to organization dashboard
return redirect("organization_analytics", id=organization.id)


class RegisterOrganizationView(View):
def get(self, request, *args, **kwargs):
return render(request, "organization/register_organization.html")
Expand Down