-
-
Notifications
You must be signed in to change notification settings - Fork 19
Add task support for calendar #3139
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
base: main
Are you sure you want to change the base?
Changes from all commits
79102b5
64536a2
ffd4e18
7dd16d9
a33c045
7f2948d
d0e849b
16867b6
36cae75
8bad6cb
e442cde
212dd3e
5ae2a5f
051dd1d
f2a9187
55c5415
6f9726e
d24aead
540a5b9
b921e0b
19bfa98
e902936
0fa7534
0160404
8981c08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,98 @@ | ||||||||||||||||||||||||||||||||||||||||
create type "public"."calendar_task_time" as enum ('working_time', 'personal_time'); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
create type "public"."priority_status" as enum ('low', 'medium', 'high', 'critical'); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
create table "public"."workspace_calendar_tasks" ( | ||||||||||||||||||||||||||||||||||||||||
"id" uuid not null default gen_random_uuid(), | ||||||||||||||||||||||||||||||||||||||||
"created_at" timestamp with time zone not null default now(), | ||||||||||||||||||||||||||||||||||||||||
"ws_id" uuid, | ||||||||||||||||||||||||||||||||||||||||
"creator_id" uuid, | ||||||||||||||||||||||||||||||||||||||||
"updated_at" timestamp with time zone, | ||||||||||||||||||||||||||||||||||||||||
"is_splittable" boolean, | ||||||||||||||||||||||||||||||||||||||||
"name" text, | ||||||||||||||||||||||||||||||||||||||||
"min_split_duration_minutes" smallint, | ||||||||||||||||||||||||||||||||||||||||
"max_split_duration_minutes" smallint, | ||||||||||||||||||||||||||||||||||||||||
phatgg221 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||
"schedule_after" timestamp with time zone, | ||||||||||||||||||||||||||||||||||||||||
"due_date" timestamp with time zone, | ||||||||||||||||||||||||||||||||||||||||
"time_reference" calendar_task_time default 'working_time'::calendar_task_time, | ||||||||||||||||||||||||||||||||||||||||
"user_defined_priority" priority_status default 'medium'::priority_status, | ||||||||||||||||||||||||||||||||||||||||
"evaluated_priority" priority_status default 'medium'::priority_status | ||||||||||||||||||||||||||||||||||||||||
); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" enable row level security; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
CREATE UNIQUE INDEX workspace_calendar_tasks_pkey ON public.workspace_calendar_tasks USING btree (id); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" add constraint "workspace_calendar_tasks_pkey" PRIMARY KEY using index "workspace_calendar_tasks_pkey"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" add constraint "workspace_calendar_tasks_creator_id_fkey" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE CASCADE not valid; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" validate constraint "workspace_calendar_tasks_creator_id_fkey"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" add constraint "workspace_calendar_tasks_ws_id_fkey" FOREIGN KEY (ws_id) REFERENCES workspaces(id) ON DELETE CASCADE not valid; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" validate constraint "workspace_calendar_tasks_ws_id_fkey"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant delete on table "public"."workspace_calendar_tasks" to "anon"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant insert on table "public"."workspace_calendar_tasks" to "anon"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant references on table "public"."workspace_calendar_tasks" to "anon"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant select on table "public"."workspace_calendar_tasks" to "anon"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant trigger on table "public"."workspace_calendar_tasks" to "anon"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant truncate on table "public"."workspace_calendar_tasks" to "anon"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant update on table "public"."workspace_calendar_tasks" to "anon"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant delete on table "public"."workspace_calendar_tasks" to "authenticated"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant insert on table "public"."workspace_calendar_tasks" to "authenticated"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant references on table "public"."workspace_calendar_tasks" to "authenticated"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant select on table "public"."workspace_calendar_tasks" to "authenticated"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant trigger on table "public"."workspace_calendar_tasks" to "authenticated"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant truncate on table "public"."workspace_calendar_tasks" to "authenticated"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant update on table "public"."workspace_calendar_tasks" to "authenticated"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant delete on table "public"."workspace_calendar_tasks" to "service_role"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant insert on table "public"."workspace_calendar_tasks" to "service_role"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant references on table "public"."workspace_calendar_tasks" to "service_role"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant select on table "public"."workspace_calendar_tasks" to "service_role"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant trigger on table "public"."workspace_calendar_tasks" to "service_role"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant truncate on table "public"."workspace_calendar_tasks" to "service_role"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
grant update on table "public"."workspace_calendar_tasks" to "service_role"; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" add column "description" text; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" add column "total_duration" text not null; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" alter column "max_split_duration_minutes" set data type real using "max_split_duration_minutes"::real; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" alter column "min_split_duration_minutes" set data type real using "min_split_duration_minutes"::real; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" enable row level security; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
create policy "allow only user in the workspace to insert" | ||||||||||||||||||||||||||||||||||||||||
on "public"."workspace_calendar_tasks" | ||||||||||||||||||||||||||||||||||||||||
as permissive | ||||||||||||||||||||||||||||||||||||||||
for insert | ||||||||||||||||||||||||||||||||||||||||
to authenticated | ||||||||||||||||||||||||||||||||||||||||
with check (true); | ||||||||||||||||||||||||||||||||||||||||
Comment on lines
+89
to
+94
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. RLS policy too permissive for workspace isolation. The current policy allows any authenticated user to insert tasks with This could allow users to create tasks in workspaces they don't belong to. Update the policy to check workspace membership: create policy "allow only user in the workspace to insert"
on "public"."workspace_calendar_tasks"
as permissive
for insert
to authenticated
-with check (true);
+with check (
+ exists (
+ select 1 from workspace_users
+ where workspace_users.ws_id = workspace_calendar_tasks.ws_id
+ and workspace_users.user_id = auth.uid()
+ )
+); 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" alter column "total_duration" set data type real using "total_duration"::real; | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
alter table "public"."workspace_calendar_tasks" alter column "updated_at" set default now(); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,209 @@ | ||
drop policy "Users can view sync logs for their workspaces" on "public"."workspace_calendar_sync_log"; | ||
|
||
drop policy "Workspace members can read and write whiteboards" on "public"."workspace_whiteboards"; | ||
|
||
revoke delete on table "public"."workspace_calendar_sync_log" from "anon"; | ||
|
||
revoke insert on table "public"."workspace_calendar_sync_log" from "anon"; | ||
|
||
revoke references on table "public"."workspace_calendar_sync_log" from "anon"; | ||
|
||
revoke select on table "public"."workspace_calendar_sync_log" from "anon"; | ||
|
||
revoke trigger on table "public"."workspace_calendar_sync_log" from "anon"; | ||
|
||
revoke truncate on table "public"."workspace_calendar_sync_log" from "anon"; | ||
|
||
revoke update on table "public"."workspace_calendar_sync_log" from "anon"; | ||
|
||
revoke delete on table "public"."workspace_calendar_sync_log" from "authenticated"; | ||
|
||
revoke insert on table "public"."workspace_calendar_sync_log" from "authenticated"; | ||
|
||
revoke references on table "public"."workspace_calendar_sync_log" from "authenticated"; | ||
|
||
revoke select on table "public"."workspace_calendar_sync_log" from "authenticated"; | ||
|
||
revoke trigger on table "public"."workspace_calendar_sync_log" from "authenticated"; | ||
|
||
revoke truncate on table "public"."workspace_calendar_sync_log" from "authenticated"; | ||
|
||
revoke update on table "public"."workspace_calendar_sync_log" from "authenticated"; | ||
|
||
revoke delete on table "public"."workspace_calendar_sync_log" from "service_role"; | ||
|
||
revoke insert on table "public"."workspace_calendar_sync_log" from "service_role"; | ||
|
||
revoke references on table "public"."workspace_calendar_sync_log" from "service_role"; | ||
|
||
revoke select on table "public"."workspace_calendar_sync_log" from "service_role"; | ||
|
||
revoke trigger on table "public"."workspace_calendar_sync_log" from "service_role"; | ||
|
||
revoke truncate on table "public"."workspace_calendar_sync_log" from "service_role"; | ||
|
||
revoke update on table "public"."workspace_calendar_sync_log" from "service_role"; | ||
|
||
revoke delete on table "public"."workspace_whiteboards" from "anon"; | ||
|
||
revoke insert on table "public"."workspace_whiteboards" from "anon"; | ||
|
||
revoke references on table "public"."workspace_whiteboards" from "anon"; | ||
|
||
revoke select on table "public"."workspace_whiteboards" from "anon"; | ||
|
||
revoke trigger on table "public"."workspace_whiteboards" from "anon"; | ||
|
||
revoke truncate on table "public"."workspace_whiteboards" from "anon"; | ||
|
||
revoke update on table "public"."workspace_whiteboards" from "anon"; | ||
|
||
revoke delete on table "public"."workspace_whiteboards" from "authenticated"; | ||
|
||
revoke insert on table "public"."workspace_whiteboards" from "authenticated"; | ||
|
||
revoke references on table "public"."workspace_whiteboards" from "authenticated"; | ||
|
||
revoke select on table "public"."workspace_whiteboards" from "authenticated"; | ||
|
||
revoke trigger on table "public"."workspace_whiteboards" from "authenticated"; | ||
|
||
revoke truncate on table "public"."workspace_whiteboards" from "authenticated"; | ||
|
||
revoke update on table "public"."workspace_whiteboards" from "authenticated"; | ||
|
||
revoke delete on table "public"."workspace_whiteboards" from "service_role"; | ||
|
||
revoke insert on table "public"."workspace_whiteboards" from "service_role"; | ||
|
||
revoke references on table "public"."workspace_whiteboards" from "service_role"; | ||
|
||
revoke select on table "public"."workspace_whiteboards" from "service_role"; | ||
|
||
revoke trigger on table "public"."workspace_whiteboards" from "service_role"; | ||
|
||
revoke truncate on table "public"."workspace_whiteboards" from "service_role"; | ||
|
||
revoke update on table "public"."workspace_whiteboards" from "service_role"; | ||
|
||
alter table "public"."workspace_calendar_sync_log" drop constraint "workspace_calendar_sync_log_status_check"; | ||
|
||
alter table "public"."workspace_calendar_sync_log" drop constraint "workspace_calendar_sync_log_timestamps_check"; | ||
|
||
alter table "public"."workspace_calendar_sync_log" drop constraint "workspace_calendar_sync_log_triggered_by_check"; | ||
|
||
alter table "public"."workspace_calendar_sync_log" drop constraint "workspace_calendar_sync_log_ws_id_fkey"; | ||
|
||
alter table "public"."workspace_calendar_tasks" drop constraint "workspace_calendar_tasks_creator_id_fkey"; | ||
|
||
alter table "public"."workspace_calendar_tasks" drop constraint "workspace_calendar_tasks_ws_id_fkey"; | ||
|
||
alter table "public"."workspace_whiteboards" drop constraint "workspace_whiteboards_creator_id_fkey"; | ||
|
||
alter table "public"."workspace_whiteboards" drop constraint "workspace_whiteboards_ws_id_fkey"; | ||
|
||
drop view if exists "public"."time_tracking_session_analytics"; | ||
|
||
alter table "public"."workspace_calendar_sync_log" drop constraint "workspace_calendar_sync_log_pkey"; | ||
|
||
alter table "public"."workspace_calendar_tasks" drop constraint "workspace_calendar_tasks_pkey"; | ||
|
||
alter table "public"."workspace_whiteboards" drop constraint "workspace_whiteboards_pkey"; | ||
|
||
drop index if exists "public"."idx_whiteboards_creator_id"; | ||
|
||
drop index if exists "public"."idx_whiteboards_snapshot_gin"; | ||
|
||
drop index if exists "public"."idx_whiteboards_ws_id"; | ||
|
||
drop index if exists "public"."workspace_calendar_sync_log_pkey"; | ||
|
||
drop index if exists "public"."workspace_calendar_sync_log_status_idx"; | ||
|
||
drop index if exists "public"."workspace_calendar_sync_log_sync_started_at_idx"; | ||
|
||
drop index if exists "public"."workspace_calendar_sync_log_workspace_id_idx"; | ||
|
||
drop index if exists "public"."workspace_calendar_tasks_pkey"; | ||
|
||
drop index if exists "public"."workspace_whiteboards_pkey"; | ||
|
||
drop table "public"."workspace_calendar_sync_log"; | ||
|
||
drop table "public"."workspace_whiteboards"; | ||
|
||
alter table "public"."tasks" add column "is_splittable" boolean not null default true; | ||
|
||
alter table "public"."tasks" add column "max_split_duration_minutes" real default '240'::real; | ||
|
||
alter table "public"."tasks" add column "min_split_duration_minutes" real default '30'::real; | ||
|
||
alter table "public"."tasks" add column "time_reference" calendar_task_time not null default 'working_time'::calendar_task_time; | ||
|
||
alter table "public"."tasks" add column "total_duration" real; | ||
|
||
alter table "public"."tasks" add column "user_defined_priority" priority_status default 'medium'::priority_status; | ||
|
||
|
||
|
||
|
||
CREATE UNIQUE INDEX workspace_calendar_taskss_pkey ON public.workspace_calendar_tasks USING btree (id); | ||
|
||
alter table "public"."workspace_calendar_tasks" add constraint "workspace_calendar_taskss_pkey" PRIMARY KEY using index "workspace_calendar_taskss_pkey"; | ||
|
||
Comment on lines
+150
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typo in index/constraint name: extra “s” in You dropped and then recreated the PK index as 🤖 Prompt for AI Agents
|
||
alter table "public"."workspace_calendar_tasks" add constraint "workspace_calendar_taskss_creator_id_fkey" FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE CASCADE not valid; | ||
|
||
alter table "public"."workspace_calendar_tasks" validate constraint "workspace_calendar_taskss_creator_id_fkey"; | ||
|
||
alter table "public"."workspace_calendar_tasks" add constraint "workspace_calendar_taskss_ws_id_fkey" FOREIGN KEY (ws_id) REFERENCES workspaces(id) ON DELETE CASCADE not valid; | ||
|
||
alter table "public"."workspace_calendar_tasks" validate constraint "workspace_calendar_taskss_ws_id_fkey"; | ||
Comment on lines
+154
to
+160
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Constraint names for FKs carry the same typo (“taskss”). The foreign-key constraints are added as
Rename to use 🤖 Prompt for AI Agents
|
||
|
||
create or replace view "public"."time_tracking_session_analytics" as SELECT tts.id, | ||
tts.ws_id, | ||
tts.user_id, | ||
tts.task_id, | ||
tts.category_id, | ||
tts.title, | ||
tts.description, | ||
tts.start_time, | ||
tts.end_time, | ||
tts.duration_seconds, | ||
tts.is_running, | ||
tts.tags, | ||
tts.created_at, | ||
tts.updated_at, | ||
tts.productivity_score, | ||
tts.was_resumed, | ||
ttc.name AS category_name, | ||
ttc.color AS category_color, | ||
t.name AS task_name, | ||
EXTRACT(hour FROM tts.start_time) AS start_hour, | ||
EXTRACT(dow FROM tts.start_time) AS day_of_week, | ||
date_trunc('day'::text, tts.start_time) AS session_date, | ||
date_trunc('week'::text, tts.start_time) AS session_week, | ||
date_trunc('month'::text, tts.start_time) AS session_month, | ||
CASE | ||
WHEN (tts.duration_seconds >= 7200) THEN 'long'::text | ||
WHEN (tts.duration_seconds >= 1800) THEN 'medium'::text | ||
WHEN (tts.duration_seconds >= 300) THEN 'short'::text | ||
ELSE 'micro'::text | ||
END AS session_length_category | ||
FROM ((time_tracking_sessions tts | ||
LEFT JOIN time_tracking_categories ttc ON ((tts.category_id = ttc.id))) | ||
LEFT JOIN tasks t ON ((tts.task_id = t.id))); | ||
|
||
|
||
|
||
alter table "public"."tasks" alter column "is_splittable" drop default; | ||
|
||
alter table "public"."tasks" alter column "is_splittable" drop not null; | ||
|
||
alter table "public"."tasks" alter column "max_split_duration_minutes" drop default; | ||
|
||
alter table "public"."tasks" alter column "min_split_duration_minutes" drop default; | ||
|
||
alter table "public"."tasks" alter column "time_reference" drop default; | ||
|
||
alter table "public"."tasks" alter column "time_reference" drop not null; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
alter table "public"."tasks" alter column "list_id" drop not null; | ||
|
||
|
||
|
||
|
||
|
||
create or replace view "public"."time_tracking_session_analytics" as SELECT tts.id, | ||
tts.ws_id, | ||
tts.user_id, | ||
tts.task_id, | ||
tts.category_id, | ||
tts.title, | ||
tts.description, | ||
tts.start_time, | ||
tts.end_time, | ||
tts.duration_seconds, | ||
tts.is_running, | ||
tts.tags, | ||
tts.created_at, | ||
tts.updated_at, | ||
tts.productivity_score, | ||
tts.was_resumed, | ||
ttc.name AS category_name, | ||
ttc.color AS category_color, | ||
t.name AS task_name, | ||
EXTRACT(hour FROM tts.start_time) AS start_hour, | ||
EXTRACT(dow FROM tts.start_time) AS day_of_week, | ||
date_trunc('day'::text, tts.start_time) AS session_date, | ||
date_trunc('week'::text, tts.start_time) AS session_week, | ||
date_trunc('month'::text, tts.start_time) AS session_month, | ||
CASE | ||
WHEN (tts.duration_seconds >= 7200) THEN 'long'::text | ||
WHEN (tts.duration_seconds >= 1800) THEN 'medium'::text | ||
WHEN (tts.duration_seconds >= 300) THEN 'short'::text | ||
ELSE 'micro'::text | ||
END AS session_length_category | ||
FROM ((time_tracking_sessions tts | ||
LEFT JOIN time_tracking_categories ttc ON ((tts.category_id = ttc.id))) | ||
LEFT JOIN tasks t ON ((tts.task_id = t.id))); | ||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Foreign key columns should be NOT NULL.
The
ws_id
andcreator_id
columns allow NULL values, but they have foreign key constraints and are essential for the application logic.This prevents orphaned records and ensures data integrity.
📝 Committable suggestion
🤖 Prompt for AI Agents