Skip to content

Commit

Permalink
fix: cover image update fix for project and user profile (#6075)
Browse files Browse the repository at this point in the history
* fix: cover image update payload

* fix: cover image assets

* chore: add gif support

---------

Co-authored-by: pablohashescobar <[email protected]>
  • Loading branch information
aaryan610 and pablohashescobar authored Nov 19, 2024
1 parent 6f497b0 commit d5a55de
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 11 deletions.
31 changes: 27 additions & 4 deletions apiserver/plane/app/views/asset/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,12 @@ 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",
]
if type not in allowed_types:
return Response(
{
Expand Down Expand Up @@ -317,7 +322,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 @@ -387,7 +392,13 @@ def post(self, request, slug):
)

# 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 @@ -620,7 +631,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 +755,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 +795,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]

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);
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;
}

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

0 comments on commit d5a55de

Please sign in to comment.