Skip to content
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

fix: cover image update fix for project and user profile #6075

Merged
merged 3 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 21 additions & 3 deletions apiserver/plane/app/views/asset/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@
)

# Check if the file type is allowed
allowed_types = ["image/jpeg", "image/png", "image/webp", "image/jpg"]
allowed_types = [
"image/jpeg",
"image/png",
"image/webp",
"image/jpg",
"image/gif",
]
sriramveeraghanta marked this conversation as resolved.
Show resolved Hide resolved
if type not in allowed_types:
return Response(
{
Expand Down Expand Up @@ -317,7 +323,7 @@

# Project Cover
elif entity_type == FileAsset.EntityTypeContext.PROJECT_COVER:
project = Project.objects.filter(id=asset.workspace_id).first()
project = Project.objects.filter(id=asset.project_id).first()
if project is None:
return
# Delete the previous cover image
Expand Down Expand Up @@ -620,7 +626,13 @@
)

# Check if the file type is allowed
allowed_types = ["image/jpeg", "image/png", "image/webp", "image/jpg"]
allowed_types = [
"image/jpeg",
"image/png",
"image/webp",
"image/jpg",
"image/gif",
]
if type not in allowed_types:
return Response(
{
Expand Down Expand Up @@ -738,6 +750,11 @@

class ProjectBulkAssetEndpoint(BaseAPIView):

def save_project_cover(self, asset, project_id):
project = Project.objects.get(id=project_id)
project.cover_image_asset_id = asset.id
project.save()

sriramveeraghanta marked this conversation as resolved.
Show resolved Hide resolved
@allow_permission([ROLE.ADMIN, ROLE.MEMBER, ROLE.GUEST])
def post(self, request, slug, project_id, entity_id):
asset_ids = request.data.get("asset_ids", [])
Expand Down Expand Up @@ -773,6 +790,7 @@
assets.update(
project_id=project_id,
)
[self.save_project_cover(asset, project_id) for asset in assets]

Check warning on line 793 in apiserver/plane/app/views/asset/v2.py

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

apiserver/plane/app/views/asset/v2.py#L793

Expression "[self.save_project_cover(asset, project_id) for asset in assets]" is assigned to nothing

if asset.entity_type == FileAsset.EntityTypeContext.ISSUE_DESCRIPTION:
assets.update(
Expand Down
6 changes: 5 additions & 1 deletion packages/types/src/project/projects.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ export interface IProject {
close_in: number;
created_at: Date;
created_by: string;
cover_image_url: string;
// only for uploading the cover image
cover_image_asset?: null;
cover_image?: string;
// only for rendering the cover image
cover_image_url: readonly string;
cycle_view: boolean;
issue_views_view: boolean;
module_view: boolean;
Expand Down
17 changes: 13 additions & 4 deletions packages/types/src/users.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { TUserPermissions } from "./enums";

type TLoginMediums = "email" | "magic-code" | "github" | "gitlab" | "google";


export interface IUserLite {
avatar_url: string;
display_name: string;
Expand All @@ -14,7 +13,11 @@ export interface IUserLite {
last_name: string;
}
export interface IUser extends IUserLite {
cover_image_url: string | null;
// only for uploading the cover image
cover_image_asset?: string | null;
cover_image?: string | null;
// only for rendering the cover image
cover_image_url: readonly (string | null);
sriramveeraghanta marked this conversation as resolved.
Show resolved Hide resolved
date_joined: string;
email: string;
is_active: boolean;
Expand Down Expand Up @@ -90,7 +93,6 @@ export interface IUserTheme {
sidebarBackground: string | undefined;
}


export interface IUserMemberLite extends IUserLite {
email?: string;
}
Expand Down Expand Up @@ -153,7 +155,14 @@ export interface IUserProfileProjectSegregation {
id: string;
pending_issues: number;
}[];
user_data: Pick<IUser, "avatar_url" | "cover_image_url" | "display_name" | "first_name" | "last_name"> & {
user_data: Pick<
IUser,
| "avatar_url"
| "cover_image_url"
| "display_name"
| "first_name"
| "last_name"
> & {
date_joined: Date;
user_timezone: string;
};
Expand Down
6 changes: 5 additions & 1 deletion web/app/profile/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,15 @@ const ProfileSettingsPage = observer(() => {
first_name: formData.first_name,
last_name: formData.last_name,
avatar_url: formData.avatar_url,
cover_image_url: formData.cover_image_url,
role: formData.role,
display_name: formData?.display_name,
user_timezone: formData.user_timezone,
};
// if unsplash or a pre-defined image is uploaded, delete the old uploaded asset
if (formData.cover_image_url?.startsWith("http")) {
payload.cover_image = formData.cover_image_url;
payload.cover_image_asset = null;
}
sriramveeraghanta marked this conversation as resolved.
Show resolved Hide resolved

const updateCurrentUserDetail = updateCurrentUser(payload).finally(() => setIsLoading(false));
setPromiseToast(updateCurrentUserDetail, {
Expand Down
5 changes: 5 additions & 0 deletions web/ce/components/projects/create/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ export const CreateProjectForm: FC<TCreateProjectFormProps> = observer((props) =
// Upper case identifier
formData.identifier = formData.identifier?.toUpperCase();
const coverImage = formData.cover_image_url;
// if unsplash or a pre-defined image is uploaded, delete the old uploaded asset
if (coverImage?.startsWith("http")) {
formData.cover_image = coverImage;
formData.cover_image_asset = null;
}

return createProject(workspaceSlug.toString(), formData)
.then(async (res) => {
Expand Down
7 changes: 6 additions & 1 deletion web/core/components/project/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,15 @@ export const ProjectDetailsForm: FC<IProjectDetailsForm> = (props) => {
network: formData.network,
identifier: formData.identifier,
description: formData.description,
cover_image_url: formData.cover_image_url,

logo_props: formData.logo_props,
// timezone: formData.timezone,
};
// if unsplash or a pre-defined image is uploaded, delete the old uploaded asset
if (formData.cover_image_url?.startsWith("http")) {
payload.cover_image = formData.cover_image_url;
payload.cover_image_asset = null;
}

if (project.identifier !== formData.identifier)
await projectService
Expand Down
Loading