* dev: remove default user * dev: initiate licensing * dev: remove migration file 0046 * feat: self hosted licensing initialize * dev: instance licenses * dev: change license response structure * dev: add default properties and issue mention migration * dev: reset migrations * dev: instance configuration * dev: instance configuration migration * dev: update instance configuration model to take null and empty values * dev: instance configuration variables * dev: set default values * dev: update instance configuration load * dev: email configuration settings moved to database * dev: instance configuration on instance bootup * dev: auto instance registration script * dev: instance admin * dev: enable instance configuration and instance admin roles * dev: instance owner fix * dev: instance configuration values * dev: fix instance permissions and serializer * dev: fix email senders * dev: remove deprecated variables * dev: fix current site domain registration * dev: update cors setup and local settings * dev: migrate instance registration and configuration to manage commands * dev: check email validity * dev: update script to use manage command * dev: default bucket creation script * dev: instance admin routes and initial set of screens * dev: admin api to check if the current user is admin * dev: instance admin unique constraints * dev: check magic link login * dev: fix email sending for ssl * dev: create instance activation route if the instance is not activated during startup * dev: removed DJANGO_SETTINGS_MODULE from environment files and deleted auto bucket create script * dev: environment configuration for backend * dev: fix access token variable error * feat: Instance Admin Panel: General Settings (#2792) --------- Co-authored-by: pablohashescobar <nikhilschacko@gmail.com> Co-authored-by: Prateek Shourya <prateekshourya29@gmail.com>
166 lines
4.5 KiB
Python
166 lines
4.5 KiB
Python
# Third party imports
|
|
from rest_framework import serializers
|
|
|
|
# Module import
|
|
from .base import BaseSerializer
|
|
from plane.db.models import User, Workspace, WorkspaceMemberInvite
|
|
from plane.license.models import InstanceAdmin, Instance
|
|
|
|
|
|
class UserSerializer(BaseSerializer):
|
|
class Meta:
|
|
model = User
|
|
fields = "__all__"
|
|
read_only_fields = [
|
|
"id",
|
|
"created_at",
|
|
"updated_at",
|
|
"is_superuser",
|
|
"is_staff",
|
|
"last_active",
|
|
"last_login_time",
|
|
"last_logout_time",
|
|
"last_login_ip",
|
|
"last_logout_ip",
|
|
"last_login_uagent",
|
|
"token_updated_at",
|
|
"is_onboarded",
|
|
"is_bot",
|
|
]
|
|
extra_kwargs = {"password": {"write_only": True}}
|
|
|
|
# If the user has already filled first name or last name then he is onboarded
|
|
def get_is_onboarded(self, obj):
|
|
return bool(obj.first_name) or bool(obj.last_name)
|
|
|
|
|
|
class UserMeSerializer(BaseSerializer):
|
|
class Meta:
|
|
model = User
|
|
fields = [
|
|
"id",
|
|
"avatar",
|
|
"cover_image",
|
|
"date_joined",
|
|
"display_name",
|
|
"email",
|
|
"first_name",
|
|
"last_name",
|
|
"is_active",
|
|
"is_bot",
|
|
"is_email_verified",
|
|
"is_managed",
|
|
"is_onboarded",
|
|
"is_tour_completed",
|
|
"mobile_number",
|
|
"role",
|
|
"onboarding_step",
|
|
"user_timezone",
|
|
"username",
|
|
"theme",
|
|
"last_workspace_id",
|
|
]
|
|
read_only_fields = fields
|
|
|
|
|
|
class UserMeSettingsSerializer(BaseSerializer):
|
|
workspace = serializers.SerializerMethodField()
|
|
|
|
class Meta:
|
|
model = User
|
|
fields = [
|
|
"id",
|
|
"email",
|
|
"workspace",
|
|
]
|
|
read_only_fields = fields
|
|
|
|
def get_workspace(self, obj):
|
|
workspace_invites = WorkspaceMemberInvite.objects.filter(
|
|
email=obj.email
|
|
).count()
|
|
if obj.last_workspace_id is not None:
|
|
workspace = Workspace.objects.filter(
|
|
pk=obj.last_workspace_id, workspace_member__member=obj.id
|
|
).first()
|
|
return {
|
|
"last_workspace_id": obj.last_workspace_id,
|
|
"last_workspace_slug": workspace.slug if workspace is not None else "",
|
|
"fallback_workspace_id": obj.last_workspace_id,
|
|
"fallback_workspace_slug": workspace.slug
|
|
if workspace is not None
|
|
else "",
|
|
"invites": workspace_invites,
|
|
}
|
|
else:
|
|
fallback_workspace = (
|
|
Workspace.objects.filter(workspace_member__member_id=obj.id)
|
|
.order_by("created_at")
|
|
.first()
|
|
)
|
|
return {
|
|
"last_workspace_id": None,
|
|
"last_workspace_slug": None,
|
|
"fallback_workspace_id": fallback_workspace.id
|
|
if fallback_workspace is not None
|
|
else None,
|
|
"fallback_workspace_slug": fallback_workspace.slug
|
|
if fallback_workspace is not None
|
|
else None,
|
|
"invites": workspace_invites,
|
|
}
|
|
|
|
|
|
class UserLiteSerializer(BaseSerializer):
|
|
class Meta:
|
|
model = User
|
|
fields = [
|
|
"id",
|
|
"first_name",
|
|
"last_name",
|
|
"avatar",
|
|
"is_bot",
|
|
"display_name",
|
|
]
|
|
read_only_fields = [
|
|
"id",
|
|
"is_bot",
|
|
]
|
|
|
|
|
|
class UserAdminLiteSerializer(BaseSerializer):
|
|
class Meta:
|
|
model = User
|
|
fields = [
|
|
"id",
|
|
"first_name",
|
|
"last_name",
|
|
"avatar",
|
|
"is_bot",
|
|
"display_name",
|
|
"email",
|
|
]
|
|
read_only_fields = [
|
|
"id",
|
|
"is_bot",
|
|
]
|
|
|
|
|
|
class ChangePasswordSerializer(serializers.Serializer):
|
|
model = User
|
|
|
|
"""
|
|
Serializer for password change endpoint.
|
|
"""
|
|
old_password = serializers.CharField(required=True)
|
|
new_password = serializers.CharField(required=True)
|
|
|
|
|
|
class ResetPasswordSerializer(serializers.Serializer):
|
|
model = User
|
|
|
|
"""
|
|
Serializer for password change endpoint.
|
|
"""
|
|
new_password = serializers.CharField(required=True)
|
|
confirm_password = serializers.CharField(required=True)
|