-
Notifications
You must be signed in to change notification settings - Fork 161
Add roles and departments #582
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GDay
wants to merge
22
commits into
add-permissions-based-on-department
Choose a base branch
from
add-departments-with-people
base: add-permissions-based-on-department
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
2f9670e
add roles and departments
GDay 7c10070
updates
GDay 9261ddd
fix adding users
GDay e5e5500
format
GDay 698f282
add tests
GDay 67408c8
address copilot issues
GDay 6a6ed9d
copilot updates
GDay 9b3c709
remove pagination
GDay 92fd998
remove unused classes/ids
GDay 23cf7ab
updates based on comments
GDay 35ffb41
move inline css to class
GDay 8bbed2b
bug fix
GDay 7d6d7a8
Add sequences to departments (#585)
GDay 5925896
Add sequences to departments (#590)
GDay e91d958
fix broken merge
GDay d17551d
Popup when sequences are being added (#591)
GDay 7ac9e50
add popup when user is added to role (#592)
GDay ecf30c6
Remove user (#593)
GDay 2e416d0
Allow setting new start date for existing users (roles) (#599)
GDay aa300ca
Show feedback when integration failed (#600)
GDay 718d2f9
reset migrations
GDay 054dc57
format, move import
GDay File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| from django.contrib.messages.views import SuccessMessageMixin | ||
| from django.shortcuts import get_object_or_404, render | ||
| from django.urls import reverse_lazy | ||
| from django.utils.translation import gettext as _ | ||
| from django.views.generic.base import View | ||
| from django.views.generic.edit import CreateView, UpdateView | ||
| from django.views.generic.list import ListView | ||
|
|
||
| from users.mixins import AdminOrManagerPermMixin | ||
| from users.models import Department, Role | ||
| from users.selectors import ( | ||
| get_all_users_for_departments_of_user, | ||
| get_available_departments_for_user, | ||
| get_available_roles_for_user, | ||
| ) | ||
|
|
||
|
|
||
| class DepartmentListView(AdminOrManagerPermMixin, ListView): | ||
| template_name = "departments.html" | ||
| paginate_by = 20 | ||
| context_object_name = "departments" | ||
|
|
||
| def get_queryset(self): | ||
| return get_available_departments_for_user( | ||
| user=self.request.user | ||
| ).prefetch_related("roles__users") | ||
|
|
||
| def get_context_data(self, **kwargs): | ||
| context = super().get_context_data(**kwargs) | ||
| context["title"] = _("Roles and departments") | ||
| context["subtitle"] = _("people") | ||
| context["users"] = get_all_users_for_departments_of_user(user=self.request.user) | ||
| return context | ||
|
|
||
|
|
||
| class DepartmentCreateView(AdminOrManagerPermMixin, SuccessMessageMixin, CreateView): | ||
| template_name = "department_create.html" | ||
| model = Department | ||
| fields = [ | ||
| "name", | ||
| ] | ||
| success_message = _("Department has been created") | ||
| success_url = reverse_lazy("people:departments") | ||
|
|
||
| def form_valid(self, form): | ||
| response = super().form_valid(form) | ||
| if self.request.user.is_manager: | ||
| self.request.user.departments.add(self.object) | ||
| return response | ||
|
|
||
| def get_context_data(self, **kwargs): | ||
| context = super().get_context_data(**kwargs) | ||
| context["title"] = _("Roles and departments") | ||
| context["subtitle"] = _("people") | ||
| return context | ||
|
|
||
|
|
||
| class DepartmentRoleCreateView( | ||
| AdminOrManagerPermMixin, SuccessMessageMixin, CreateView | ||
| ): | ||
| template_name = "role_create.html" | ||
| model = Role | ||
| fields = [ | ||
| "name", | ||
| ] | ||
| success_message = _("Role has been created") | ||
| success_url = reverse_lazy("people:departments") | ||
|
|
||
| def dispatch(self, *args, **kwargs): | ||
| self.department = get_object_or_404( | ||
| get_available_departments_for_user(user=self.request.user), | ||
| id=self.kwargs.get("pk"), | ||
| ) | ||
| return super().dispatch(*args, **kwargs) | ||
|
|
||
| def form_valid(self, form): | ||
| form.instance.department = self.department | ||
| return super().form_valid(form) | ||
|
|
||
| def get_context_data(self, **kwargs): | ||
| context = super().get_context_data(**kwargs) | ||
| context["title"] = _("Roles") | ||
| context["subtitle"] = _("people") | ||
| return context | ||
|
|
||
|
|
||
| class AddUserToRoleView(AdminOrManagerPermMixin, SuccessMessageMixin, View): | ||
| def post(self, request, role_pk, user_pk, **kwargs): | ||
| role = get_object_or_404( | ||
| get_available_roles_for_user(user=request.user), id=role_pk | ||
| ) | ||
| user = get_object_or_404( | ||
| get_all_users_for_departments_of_user(user=request.user), id=user_pk | ||
| ) | ||
|
|
||
| role.users.add(user) | ||
| return render( | ||
| request, | ||
| "_departments_list.html", | ||
| {"departments": get_available_departments_for_user(user=self.request.user)}, | ||
|
GDay marked this conversation as resolved.
Outdated
|
||
| ) | ||
|
|
||
|
|
||
| class DepartmentUpdateView(AdminOrManagerPermMixin, SuccessMessageMixin, UpdateView): | ||
| template_name = "department_update.html" | ||
| fields = [ | ||
| "name", | ||
| ] | ||
| success_message = _("Department has been updated") | ||
| success_url = reverse_lazy("people:departments") | ||
|
|
||
| def get_queryset(self): | ||
| return get_available_departments_for_user(user=self.request.user) | ||
|
|
||
| def get_context_data(self, **kwargs): | ||
| context = super().get_context_data(**kwargs) | ||
| context["title"] = _("Department") | ||
| context["subtitle"] = _("people") | ||
| return context | ||
|
|
||
|
|
||
| class DepartmentRoleUpdateView( | ||
| AdminOrManagerPermMixin, SuccessMessageMixin, UpdateView | ||
| ): | ||
| template_name = "role_update.html" | ||
| fields = [ | ||
| "name", | ||
| ] | ||
| success_message = _("Role has been updated") | ||
| success_url = reverse_lazy("people:departments") | ||
|
|
||
| def get_queryset(self): | ||
| return get_available_roles_for_user(user=self.request.user) | ||
|
|
||
| def get_context_data(self, **kwargs): | ||
| context = super().get_context_data(**kwargs) | ||
| context["title"] = _("Role") | ||
| context["subtitle"] = _("people") | ||
| return context | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| {% load static crispy_forms_tags %} | ||
|
GDay marked this conversation as resolved.
Outdated
|
||
| {% load i18n %} | ||
|
|
||
| {% for department in departments %} | ||
| <div class="card mb-4"> | ||
| <div class="card-header"> | ||
| <div class="col-11"> | ||
| <h3 class="card-title">{{ department }}</h3> | ||
| </div> | ||
| <div class="col-1 text-end"> | ||
| <a class="btn btn-azure btn-sm" href="{% url "people:department_update" department.pk %}"> | ||
| {% include "_edit_icon.html" %} | ||
| </a> | ||
| </div> | ||
| </div> | ||
| <div class="card-body"> | ||
| {% for role in department.roles.all %} | ||
| <div class="drop mb-2" data-role-id="{{role.id}}"> | ||
| <h3 class="card-title mb-2">{{ role }}</h3> | ||
| {% if role.users.all|length %} | ||
|
GDay marked this conversation as resolved.
Outdated
|
||
| <ul class="list-group list-group-flush"> | ||
|
|
||
| {% for user in role.users.all %} | ||
| <li class="list-group-item" style="padding: 4px;"> | ||
|
GDay marked this conversation as resolved.
Outdated
|
||
| {% if user.profile_image is not None %} | ||
|
GDay marked this conversation as resolved.
Outdated
|
||
| <span class="avatar me-2 avatar-xs" style="background-image: url({{ user.profile_image.get_url }})"></span> | ||
| {% else %} | ||
| <span class="avatar me-2 avatar-xs">{{ user.initials }}</span> | ||
| {% endif %} | ||
| {{ user.name }} | ||
| </li> | ||
| {% endfor %} | ||
| </ul> | ||
| {% else %} | ||
| {% trans "No users have been added to this role yet." %} | ||
| {% endif %} | ||
| </div> | ||
| {% endfor %} | ||
| {% if department.roles.all|length == 0 %} | ||
|
GDay marked this conversation as resolved.
Outdated
|
||
| {% trans "No roles have been added to this department yet." %} | ||
| <br/> | ||
| <a type="submit" class="btn btn-primary btn-sm mt-2" href="{% url "people:department_role_create" department.id %}">{% trans "Add role" %}</a> | ||
|
GDay marked this conversation as resolved.
Outdated
|
||
| {% endif %} | ||
| </div> | ||
| </div> | ||
| {% empty %} | ||
| <div class="card mb-4"> | ||
| <div class="card-header"> | ||
| {% trans "There are no departments yet." %} | ||
| </div> | ||
| </div> | ||
| {% endfor %} | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| {% extends 'admin_base.html' %} | ||
| {% load i18n %} | ||
| {% load crispy_forms_tags %} | ||
|
|
||
| {% block content %} | ||
| <div class="row justify-content-md-center"> | ||
| <div class="col-md-8 col-12"> | ||
| <div class="card mt-3"> | ||
| <div class="card-header"> | ||
| <h3 class="card-title">{{ object.name }}</h3> | ||
| </div> | ||
| <div class="card-body"> | ||
| <form action="." method="post"> | ||
| {% csrf_token %} | ||
| {{ form|crispy }} | ||
| <button type="submit" class="btn btn-primary">{% trans "Update" %}</button> | ||
| </form> | ||
| </div> | ||
| </div> | ||
| <div class="card mt-3"> | ||
| <div class="card-header"> | ||
| <h3 class="card-title">{% trans "Roles" %}</h3> | ||
| </div> | ||
| <div class="card-body"> | ||
| <div class="divide-y"> | ||
| {% for role in department.roles.all %} | ||
| <div class="row"> | ||
| <div class="col"> | ||
| <p style="margin-bottom:0px">{{ role }}</p> | ||
|
GDay marked this conversation as resolved.
Outdated
|
||
| </div> | ||
| <div class="col"> | ||
| <div class="text-end"> | ||
| <a class="btn btn-azure btn-sm" href="{% url "people:department_role_update" department.pk role.pk %}"> | ||
| {% include "_edit_icon.html" %} | ||
| </a> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {% empty %} | ||
| <p class="mb-0">{% trans "No roles added yet" %}</p> | ||
| {% endfor %} | ||
| </div> | ||
| <a class="btn btn-primary mt-4" href="{% url "people:department_role_create" department.pk %}"> | ||
| {% trans "Add" %} | ||
| </a> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| {% endblock %} | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.