[WEB-5044] fix: ruff lint and format errors (#7868)
* fix: lint errors * fix: file formatting * fix: code refactor
This commit is contained in:
parent
1fb22bd252
commit
9237f568dd
261 changed files with 2199 additions and 6378 deletions
|
|
@ -11,6 +11,4 @@ class InstanceAdminPermission(BasePermission):
|
|||
return False
|
||||
|
||||
instance = Instance.objects.first()
|
||||
return InstanceAdmin.objects.filter(
|
||||
role__gte=15, instance=instance, user=request.user
|
||||
).exists()
|
||||
return InstanceAdmin.objects.filter(role__gte=15, instance=instance, user=request.user).exists()
|
||||
|
|
|
|||
|
|
@ -5,9 +5,7 @@ from plane.app.serializers import UserAdminLiteSerializer
|
|||
|
||||
|
||||
class InstanceSerializer(BaseSerializer):
|
||||
primary_owner_details = UserAdminLiteSerializer(
|
||||
source="primary_owner", read_only=True
|
||||
)
|
||||
primary_owner_details = UserAdminLiteSerializer(source="primary_owner", read_only=True)
|
||||
|
||||
class Meta:
|
||||
model = Instance
|
||||
|
|
|
|||
|
|
@ -47,9 +47,7 @@ class InstanceAdminEndpoint(BaseAPIView):
|
|||
role = request.data.get("role", 20)
|
||||
|
||||
if not email:
|
||||
return Response(
|
||||
{"error": "Email is required"}, status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
return Response({"error": "Email is required"}, status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
instance = Instance.objects.first()
|
||||
if instance is None:
|
||||
|
|
@ -61,9 +59,7 @@ class InstanceAdminEndpoint(BaseAPIView):
|
|||
# Fetch the user
|
||||
user = User.objects.get(email=email)
|
||||
|
||||
instance_admin = InstanceAdmin.objects.create(
|
||||
instance=instance, user=user, role=role
|
||||
)
|
||||
instance_admin = InstanceAdmin.objects.create(instance=instance, user=user, role=role)
|
||||
serializer = InstanceAdminSerializer(instance_admin)
|
||||
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
||||
|
||||
|
|
@ -127,9 +123,7 @@ class InstanceAdminSignUpEndpoint(View):
|
|||
# return error if the email and password is not present
|
||||
if not email or not password or not first_name:
|
||||
exc = AuthenticationException(
|
||||
error_code=AUTHENTICATION_ERROR_CODES[
|
||||
"REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME"
|
||||
],
|
||||
error_code=AUTHENTICATION_ERROR_CODES["REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME"],
|
||||
error_message="REQUIRED_ADMIN_EMAIL_PASSWORD_FIRST_NAME",
|
||||
payload={
|
||||
"email": email,
|
||||
|
|
@ -369,10 +363,7 @@ class InstanceAdminUserSessionEndpoint(BaseAPIView):
|
|||
permission_classes = [AllowAny]
|
||||
|
||||
def get(self, request):
|
||||
if (
|
||||
request.user.is_authenticated
|
||||
and InstanceAdmin.objects.filter(user=request.user).exists()
|
||||
):
|
||||
if request.user.is_authenticated and InstanceAdmin.objects.filter(user=request.user).exists():
|
||||
serializer = InstanceAdminMeSerializer(request.user)
|
||||
data = {"is_authenticated": True}
|
||||
data["user"] = serializer.data
|
||||
|
|
@ -393,14 +384,8 @@ class InstanceAdminSignOutEndpoint(View):
|
|||
user.save()
|
||||
# Log the user out
|
||||
logout(request)
|
||||
url = get_safe_redirect_url(
|
||||
base_url=base_host(request=request, is_admin=True),
|
||||
next_path=""
|
||||
)
|
||||
url = get_safe_redirect_url(base_url=base_host(request=request, is_admin=True), next_path="")
|
||||
return HttpResponseRedirect(url)
|
||||
except Exception:
|
||||
url = get_safe_redirect_url(
|
||||
base_url=base_host(request=request, is_admin=True),
|
||||
next_path=""
|
||||
)
|
||||
url = get_safe_redirect_url(base_url=base_host(request=request, is_admin=True), next_path="")
|
||||
return HttpResponseRedirect(url)
|
||||
|
|
|
|||
|
|
@ -97,9 +97,7 @@ class BaseAPIView(TimezoneMixin, APIView, BasePaginator):
|
|||
if settings.DEBUG:
|
||||
from django.db import connection
|
||||
|
||||
print(
|
||||
f"{request.method} - {request.get_full_path()} of Queries: {len(connection.queries)}"
|
||||
)
|
||||
print(f"{request.method} - {request.get_full_path()} of Queries: {len(connection.queries)}")
|
||||
return response
|
||||
|
||||
except Exception as exc:
|
||||
|
|
@ -108,14 +106,10 @@ class BaseAPIView(TimezoneMixin, APIView, BasePaginator):
|
|||
|
||||
@property
|
||||
def fields(self):
|
||||
fields = [
|
||||
field for field in self.request.GET.get("fields", "").split(",") if field
|
||||
]
|
||||
fields = [field for field in self.request.GET.get("fields", "").split(",") if field]
|
||||
return fields if fields else None
|
||||
|
||||
@property
|
||||
def expand(self):
|
||||
expand = [
|
||||
expand for expand in self.request.GET.get("expand", "").split(",") if expand
|
||||
]
|
||||
expand = [expand for expand in self.request.GET.get("expand", "").split(",") if expand]
|
||||
return expand if expand else None
|
||||
|
|
|
|||
|
|
@ -37,9 +37,7 @@ class InstanceConfigurationEndpoint(BaseAPIView):
|
|||
@invalidate_cache(path="/api/instances/configurations/", user=False)
|
||||
@invalidate_cache(path="/api/instances/", user=False)
|
||||
def patch(self, request):
|
||||
configurations = InstanceConfiguration.objects.filter(
|
||||
key__in=request.data.keys()
|
||||
)
|
||||
configurations = InstanceConfiguration.objects.filter(key__in=request.data.keys())
|
||||
|
||||
bulk_configurations = []
|
||||
for configuration in configurations:
|
||||
|
|
@ -50,9 +48,7 @@ class InstanceConfigurationEndpoint(BaseAPIView):
|
|||
configuration.value = value
|
||||
bulk_configurations.append(configuration)
|
||||
|
||||
InstanceConfiguration.objects.bulk_update(
|
||||
bulk_configurations, ["value"], batch_size=100
|
||||
)
|
||||
InstanceConfiguration.objects.bulk_update(bulk_configurations, ["value"], batch_size=100)
|
||||
|
||||
serializer = InstanceConfigurationSerializer(configurations, many=True)
|
||||
return Response(serializer.data, status=status.HTTP_200_OK)
|
||||
|
|
@ -75,9 +71,7 @@ class DisableEmailFeatureEndpoint(BaseAPIView):
|
|||
"EMAIL_FROM",
|
||||
]
|
||||
)
|
||||
).update(
|
||||
value=Case(When(key="ENABLE_SMTP", then=Value("0")), default=Value(""))
|
||||
)
|
||||
).update(value=Case(When(key="ENABLE_SMTP", then=Value("0")), default=Value("")))
|
||||
return Response(status=status.HTTP_200_OK)
|
||||
except Exception:
|
||||
return Response(
|
||||
|
|
@ -127,13 +121,9 @@ class EmailCredentialCheckEndpoint(BaseAPIView):
|
|||
connection=connection,
|
||||
)
|
||||
msg.send(fail_silently=False)
|
||||
return Response(
|
||||
{"message": "Email successfully sent."}, status=status.HTTP_200_OK
|
||||
)
|
||||
return Response({"message": "Email successfully sent."}, status=status.HTTP_200_OK)
|
||||
except BadHeaderError:
|
||||
return Response(
|
||||
{"error": "Invalid email header."}, status=status.HTTP_400_BAD_REQUEST
|
||||
)
|
||||
return Response({"error": "Invalid email header."}, status=status.HTTP_400_BAD_REQUEST)
|
||||
except SMTPAuthenticationError:
|
||||
return Response(
|
||||
{"error": "Invalid credentials provided"},
|
||||
|
|
@ -166,9 +156,7 @@ class EmailCredentialCheckEndpoint(BaseAPIView):
|
|||
)
|
||||
except ConnectionError:
|
||||
return Response(
|
||||
{
|
||||
"error": "Network connection error. Please check your internet connection."
|
||||
},
|
||||
{"error": "Network connection error. Please check your internet connection."},
|
||||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
except Exception:
|
||||
|
|
|
|||
|
|
@ -24,10 +24,7 @@ class InstanceWorkSpaceAvailabilityCheckEndpoint(BaseAPIView):
|
|||
status=status.HTTP_400_BAD_REQUEST,
|
||||
)
|
||||
|
||||
workspace = (
|
||||
Workspace.objects.filter(slug__iexact=slug).exists()
|
||||
or slug in RESTRICTED_WORKSPACE_SLUGS
|
||||
)
|
||||
workspace = Workspace.objects.filter(slug__iexact=slug).exists() or slug in RESTRICTED_WORKSPACE_SLUGS
|
||||
return Response({"status": not workspace}, status=status.HTTP_200_OK)
|
||||
|
||||
|
||||
|
|
@ -45,18 +42,14 @@ class InstanceWorkSpaceEndpoint(BaseAPIView):
|
|||
)
|
||||
|
||||
member_count = (
|
||||
WorkspaceMember.objects.filter(
|
||||
workspace=OuterRef("id"), member__is_bot=False, is_active=True
|
||||
)
|
||||
WorkspaceMember.objects.filter(workspace=OuterRef("id"), member__is_bot=False, is_active=True)
|
||||
.select_related("owner")
|
||||
.order_by()
|
||||
.annotate(count=Func(F("id"), function="Count"))
|
||||
.values("count")
|
||||
)
|
||||
|
||||
workspaces = Workspace.objects.annotate(
|
||||
total_projects=project_count, total_members=member_count
|
||||
)
|
||||
workspaces = Workspace.objects.annotate(total_projects=project_count, total_members=member_count)
|
||||
|
||||
# Add search functionality
|
||||
search = request.query_params.get("search", None)
|
||||
|
|
|
|||
|
|
@ -51,14 +51,10 @@ def instance_traces():
|
|||
span.set_attribute("instance_name", instance.instance_name)
|
||||
span.set_attribute("current_version", instance.current_version)
|
||||
span.set_attribute("latest_version", instance.latest_version)
|
||||
span.set_attribute(
|
||||
"is_telemetry_enabled", instance.is_telemetry_enabled
|
||||
)
|
||||
span.set_attribute("is_telemetry_enabled", instance.is_telemetry_enabled)
|
||||
span.set_attribute("is_support_required", instance.is_support_required)
|
||||
span.set_attribute("is_setup_done", instance.is_setup_done)
|
||||
span.set_attribute(
|
||||
"is_signup_screen_visited", instance.is_signup_screen_visited
|
||||
)
|
||||
span.set_attribute("is_signup_screen_visited", instance.is_signup_screen_visited)
|
||||
span.set_attribute("is_verified", instance.is_verified)
|
||||
span.set_attribute("edition", instance.edition)
|
||||
span.set_attribute("domain", instance.domain)
|
||||
|
|
@ -80,16 +76,10 @@ def instance_traces():
|
|||
issue_count = Issue.objects.filter(workspace=workspace).count()
|
||||
module_count = Module.objects.filter(workspace=workspace).count()
|
||||
cycle_count = Cycle.objects.filter(workspace=workspace).count()
|
||||
cycle_issue_count = CycleIssue.objects.filter(
|
||||
workspace=workspace
|
||||
).count()
|
||||
module_issue_count = ModuleIssue.objects.filter(
|
||||
workspace=workspace
|
||||
).count()
|
||||
cycle_issue_count = CycleIssue.objects.filter(workspace=workspace).count()
|
||||
module_issue_count = ModuleIssue.objects.filter(workspace=workspace).count()
|
||||
page_count = Page.objects.filter(workspace=workspace).count()
|
||||
member_count = WorkspaceMember.objects.filter(
|
||||
workspace=workspace
|
||||
).count()
|
||||
member_count = WorkspaceMember.objects.filter(workspace=workspace).count()
|
||||
|
||||
# Set span attributes
|
||||
with tracer.start_as_current_span("workspace_details") as span:
|
||||
|
|
|
|||
|
|
@ -190,9 +190,7 @@ class Command(BaseCommand):
|
|||
]
|
||||
|
||||
for item in config_keys:
|
||||
obj, created = InstanceConfiguration.objects.get_or_create(
|
||||
key=item.get("key")
|
||||
)
|
||||
obj, created = InstanceConfiguration.objects.get_or_create(key=item.get("key"))
|
||||
if created:
|
||||
obj.category = item.get("category")
|
||||
obj.is_encrypted = item.get("is_encrypted", False)
|
||||
|
|
@ -201,15 +199,9 @@ class Command(BaseCommand):
|
|||
else:
|
||||
obj.value = item.get("value")
|
||||
obj.save()
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"{obj.key} loaded with value from environment variable."
|
||||
)
|
||||
)
|
||||
self.stdout.write(self.style.SUCCESS(f"{obj.key} loaded with value from environment variable."))
|
||||
else:
|
||||
self.stdout.write(
|
||||
self.style.WARNING(f"{obj.key} configuration already exists")
|
||||
)
|
||||
self.stdout.write(self.style.WARNING(f"{obj.key} configuration already exists"))
|
||||
|
||||
keys = ["IS_GOOGLE_ENABLED", "IS_GITHUB_ENABLED", "IS_GITLAB_ENABLED"]
|
||||
if not InstanceConfiguration.objects.filter(key__in=keys).exists():
|
||||
|
|
@ -237,11 +229,7 @@ class Command(BaseCommand):
|
|||
category="AUTHENTICATION",
|
||||
is_encrypted=False,
|
||||
)
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"{key} loaded with value from environment variable."
|
||||
)
|
||||
)
|
||||
self.stdout.write(self.style.SUCCESS(f"{key} loaded with value from environment variable."))
|
||||
if key == "IS_GITHUB_ENABLED":
|
||||
GITHUB_CLIENT_ID, GITHUB_CLIENT_SECRET = get_configuration_value(
|
||||
[
|
||||
|
|
@ -265,39 +253,25 @@ class Command(BaseCommand):
|
|||
category="AUTHENTICATION",
|
||||
is_encrypted=False,
|
||||
)
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"{key} loaded with value from environment variable."
|
||||
)
|
||||
)
|
||||
self.stdout.write(self.style.SUCCESS(f"{key} loaded with value from environment variable."))
|
||||
if key == "IS_GITLAB_ENABLED":
|
||||
GITLAB_HOST, GITLAB_CLIENT_ID, GITLAB_CLIENT_SECRET = (
|
||||
get_configuration_value(
|
||||
[
|
||||
{
|
||||
"key": "GITLAB_HOST",
|
||||
"default": os.environ.get(
|
||||
"GITLAB_HOST", "https://gitlab.com"
|
||||
),
|
||||
},
|
||||
{
|
||||
"key": "GITLAB_CLIENT_ID",
|
||||
"default": os.environ.get("GITLAB_CLIENT_ID", ""),
|
||||
},
|
||||
{
|
||||
"key": "GITLAB_CLIENT_SECRET",
|
||||
"default": os.environ.get(
|
||||
"GITLAB_CLIENT_SECRET", ""
|
||||
),
|
||||
},
|
||||
]
|
||||
)
|
||||
GITLAB_HOST, GITLAB_CLIENT_ID, GITLAB_CLIENT_SECRET = get_configuration_value(
|
||||
[
|
||||
{
|
||||
"key": "GITLAB_HOST",
|
||||
"default": os.environ.get("GITLAB_HOST", "https://gitlab.com"),
|
||||
},
|
||||
{
|
||||
"key": "GITLAB_CLIENT_ID",
|
||||
"default": os.environ.get("GITLAB_CLIENT_ID", ""),
|
||||
},
|
||||
{
|
||||
"key": "GITLAB_CLIENT_SECRET",
|
||||
"default": os.environ.get("GITLAB_CLIENT_SECRET", ""),
|
||||
},
|
||||
]
|
||||
)
|
||||
if (
|
||||
bool(GITLAB_HOST)
|
||||
and bool(GITLAB_CLIENT_ID)
|
||||
and bool(GITLAB_CLIENT_SECRET)
|
||||
):
|
||||
if bool(GITLAB_HOST) and bool(GITLAB_CLIENT_ID) and bool(GITLAB_CLIENT_SECRET):
|
||||
value = "1"
|
||||
else:
|
||||
value = "0"
|
||||
|
|
@ -307,13 +281,7 @@ class Command(BaseCommand):
|
|||
category="AUTHENTICATION",
|
||||
is_encrypted=False,
|
||||
)
|
||||
self.stdout.write(
|
||||
self.style.SUCCESS(
|
||||
f"{key} loaded with value from environment variable."
|
||||
)
|
||||
)
|
||||
self.stdout.write(self.style.SUCCESS(f"{key} loaded with value from environment variable."))
|
||||
else:
|
||||
for key in keys:
|
||||
self.stdout.write(
|
||||
self.style.WARNING(f"{key} configuration already exists")
|
||||
)
|
||||
self.stdout.write(self.style.WARNING(f"{key} configuration already exists"))
|
||||
|
|
|
|||
|
|
@ -22,9 +22,7 @@ class Instance(BaseModel):
|
|||
instance_id = models.CharField(max_length=255, unique=True)
|
||||
current_version = models.CharField(max_length=255)
|
||||
latest_version = models.CharField(max_length=255, null=True, blank=True)
|
||||
edition = models.CharField(
|
||||
max_length=255, default=InstanceEdition.PLANE_COMMUNITY.value
|
||||
)
|
||||
edition = models.CharField(max_length=255, default=InstanceEdition.PLANE_COMMUNITY.value)
|
||||
domain = models.TextField(blank=True)
|
||||
# Instance specifics
|
||||
last_checked_at = models.DateTimeField()
|
||||
|
|
@ -55,9 +53,7 @@ class InstanceAdmin(BaseModel):
|
|||
null=True,
|
||||
related_name="instance_owner",
|
||||
)
|
||||
instance = models.ForeignKey(
|
||||
Instance, on_delete=models.CASCADE, related_name="admins"
|
||||
)
|
||||
instance = models.ForeignKey(Instance, on_delete=models.CASCADE, related_name="admins")
|
||||
role = models.PositiveIntegerField(choices=ROLE_CHOICES, default=20)
|
||||
is_verified = models.BooleanField(default=False)
|
||||
|
||||
|
|
|
|||
|
|
@ -31,9 +31,7 @@ def decrypt_data(encrypted_data):
|
|||
try:
|
||||
if encrypted_data:
|
||||
cipher_suite = Fernet(derive_key(settings.SECRET_KEY))
|
||||
decrypted_data = cipher_suite.decrypt(
|
||||
encrypted_data.encode()
|
||||
) # Convert string back to bytes
|
||||
decrypted_data = cipher_suite.decrypt(encrypted_data.encode()) # Convert string back to bytes
|
||||
return decrypted_data.decode()
|
||||
else:
|
||||
return ""
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ def get_configuration_value(keys):
|
|||
environment_list = []
|
||||
if settings.SKIP_ENV_VAR:
|
||||
# Get the configurations
|
||||
instance_configuration = InstanceConfiguration.objects.values(
|
||||
"key", "value", "is_encrypted"
|
||||
)
|
||||
instance_configuration = InstanceConfiguration.objects.values("key", "value", "is_encrypted")
|
||||
|
||||
for key in keys:
|
||||
for item in instance_configuration:
|
||||
|
|
@ -51,9 +49,7 @@ def get_email_configuration():
|
|||
{"key": "EMAIL_USE_SSL", "default": os.environ.get("EMAIL_USE_SSL", "0")},
|
||||
{
|
||||
"key": "EMAIL_FROM",
|
||||
"default": os.environ.get(
|
||||
"EMAIL_FROM", "Team Plane <team@mailer.plane.so>"
|
||||
),
|
||||
"default": os.environ.get("EMAIL_FROM", "Team Plane <team@mailer.plane.so>"),
|
||||
},
|
||||
]
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue