Skip to content

Commit

Permalink
fix: cover image assets
Browse files Browse the repository at this point in the history
  • Loading branch information
pablohashescobar committed Nov 19, 2024
1 parent f9e252f commit 77790b3
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
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 @@ def post(self, request):
)

# 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 @@ -317,7 +323,7 @@ def entity_asset_save(self, asset_id, entity_type, asset, request):

# 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 @@ def post(self, request, slug, project_id):
)

# 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 @@ def get(self, request, slug, project_id, pk):

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()

@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 @@ def post(self, request, slug, project_id, entity_id):
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
1 change: 1 addition & 0 deletions packages/types/src/project/projects.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IProject {
created_at: Date;
created_by: 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;
Expand Down
14 changes: 10 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 @@ -15,7 +14,8 @@ export interface IUserLite {
}
export interface IUser extends IUserLite {
// only for uploading the cover image
cover_image: string | null;
cover_image_asset?: string | null;
cover_image?: string | null;
// only for rendering the cover image
cover_image_url: readonly (string | null);
date_joined: string;
Expand Down Expand Up @@ -93,7 +93,6 @@ export interface IUserTheme {
sidebarBackground: string | undefined;
}


export interface IUserMemberLite extends IUserLite {
email?: string;
}
Expand Down Expand Up @@ -156,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: 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;
}

const updateCurrentUserDetail = updateCurrentUser(payload).finally(() => setIsLoading(false));
setPromiseToast(updateCurrentUserDetail, {
Expand Down
6 changes: 5 additions & 1 deletion web/ce/components/projects/create/root.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,12 @@ export const CreateProjectForm: FC<TCreateProjectFormProps> = observer((props) =
const onSubmit = async (formData: Partial<TProject>) => {
// Upper case identifier
formData.identifier = formData.identifier?.toUpperCase();
formData.cover_image = formData.cover_image_url;
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: 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

0 comments on commit 77790b3

Please sign in to comment.