-
Notifications
You must be signed in to change notification settings - Fork 1
Organisation member management #248
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
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1c0c39f
Add a basic org members view
Joe-Heffer-Shef 3725bc5
Add a basic org members view
Joe-Heffer-Shef dd490c7
Merge remote-tracking branch 'refs/remotes/origin/dev' into feat/21-m…
Joe-Heffer-Shef 6d6ba66
Add user invite form. Refactor forms.
Joe-Heffer-Shef 2584d03
Add django-invitations plugin
Joe-Heffer-Shef d9cc87e
Register new user based on invitation key
Joe-Heffer-Shef 295c06b
Add the new user to an organisation
Joe-Heffer-Shef 51e6898
chore: Format code
Joe-Heffer-Shef cea8628
Fix adding a new user to an org
Joe-Heffer-Shef a231b28
Remove unused import
Joe-Heffer-Shef 04115c7
Added remove user feature
Joe-Heffer-Shef b232c9d
Remove members top-level nav link
Joe-Heffer-Shef 5ff1b90
Use the organisation service to remove users
Joe-Heffer-Shef dcfb4cd
Merge branch 'dev' into feat/21-manage-org-members
Joe-Heffer-Shef 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
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
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,14 @@ | ||
# Invitations | ||
|
||
https://django-invitations.readthedocs.io/ | ||
|
||
# Usage | ||
|
||
## Clear invitations | ||
|
||
[Invitations management command](https://django-invitations.readthedocs.io/en/latest/usage.html#management-commands) | ||
|
||
```bash | ||
python manage.py clear_expired_invitations | ||
``` | ||
|
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,8 @@ | ||
# Icons | ||
|
||
The [Boxicons](https://boxicons.com/) website has a gallery of available icons that can be implemented using the following HTML code: | ||
|
||
```html | ||
<i class='bx bxs-envelope'></i> | ||
``` | ||
|
This file was deleted.
Oops, something went wrong.
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,6 @@ | ||
from .manager_signup import ManagerSignupForm | ||
from .manager_login import ManagerLoginForm | ||
from .search_bar import SearchBarForm | ||
from .user_profile import UserProfileForm | ||
|
||
__all__ = ["ManagerSignupForm", "ManagerLoginForm", "SearchBarForm", "UserProfileForm"] |
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,8 @@ | ||
import django.forms as forms | ||
from django.contrib.auth.forms import AuthenticationForm | ||
|
||
|
||
class ManagerLoginForm(AuthenticationForm): | ||
username = forms.EmailField( | ||
label="Email", max_length=60, widget=forms.EmailInput(attrs={"autofocus": True}) | ||
) |
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,76 @@ | ||
""" | ||
New manager registration form | ||
""" | ||
|
||
import django.contrib.auth.models | ||
import django.forms as forms | ||
from django.contrib.auth.forms import UserCreationForm | ||
from invitations.models import Invitation | ||
|
||
from home.services import organisation_service | ||
from home.models import Organisation | ||
from home.constants import ROLE_PROJECT_MANAGER | ||
|
||
User = django.contrib.auth.get_user_model() | ||
|
||
|
||
class ManagerSignupForm(UserCreationForm): | ||
""" | ||
A form to register a new user (a new manager) who was invited by | ||
an existing manager of an organisation. | ||
""" | ||
|
||
class Meta: | ||
model = User | ||
fields = ("password1", "password2") | ||
|
||
# Secret key for the invitation (hidden form field) | ||
key = forms.CharField(required=False, disabled=True, widget=forms.HiddenInput, label="") | ||
|
||
@property | ||
def invitation(self) -> Invitation: | ||
""" | ||
The invitation that the existing manager send to the new user. | ||
""" | ||
return Invitation.objects.get(key=self.data["key"]) | ||
|
||
@property | ||
def inviter(self) -> User: | ||
""" | ||
The user (manager) who invited this new manager. | ||
""" | ||
return User.objects.get(pk=self.invitation.inviter_id) | ||
|
||
@property | ||
def organisation(self) -> Organisation: | ||
""" | ||
The organisation that the new user was invited to join. | ||
""" | ||
organisation = organisation_service.get_user_organisation(user=self.inviter) | ||
if organisation is None: | ||
raise forms.ValidationError("This user is not a manager of an organisation") | ||
return organisation | ||
|
||
@property | ||
def email(self) -> str: | ||
""" | ||
The email address of the new user that received the invitation email. | ||
""" | ||
return self.invitation.email | ||
|
||
def save(self, commit=True): | ||
user = super().save(commit=False) | ||
user.email = self.email | ||
user.username = user.email | ||
if commit: | ||
user.save() | ||
|
||
# Add user to organisation | ||
organisation_service.add_user_to_organisation( | ||
user_to_add=user, | ||
organisation=self.organisation, | ||
user=self.inviter, | ||
role=ROLE_PROJECT_MANAGER, | ||
) | ||
|
||
return user |
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,15 @@ | ||
import django.forms as forms | ||
|
||
|
||
class SearchBarForm(forms.Form): | ||
q = forms.CharField( | ||
required=False, | ||
widget=forms.TextInput( | ||
attrs={ | ||
"class": "form-control", | ||
"placeholder": "Search...", | ||
"aria-label": "Search", | ||
"name": "q", | ||
} | ||
), | ||
) |
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,28 @@ | ||
import django.contrib.auth | ||
import django.forms as forms | ||
|
||
User = django.contrib.auth.get_user_model() | ||
|
||
|
||
class UserProfileForm(forms.ModelForm): | ||
class Meta: | ||
model = User | ||
fields = ["email", "first_name", "last_name"] | ||
|
||
def clean_email(self): | ||
email = self.cleaned_data.get("email") | ||
|
||
if email == self.instance.email: | ||
return email | ||
|
||
if User.objects.exclude(pk=self.instance.pk).filter(email=email).exists(): | ||
raise forms.ValidationError("This email is already in use.") | ||
return email | ||
|
||
def save(self, commit=True): | ||
user = super().save(commit=False) | ||
if self.cleaned_data.get("password"): | ||
user.set_password(self.cleaned_data["password"]) | ||
if commit: | ||
user.save() | ||
return user |
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
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
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This permission check wasn't here before.