-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
052517f
commit 505d66f
Showing
24 changed files
with
1,124 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
import 'package:studyu_core/core.dart'; | ||
|
||
part 'study_tag.g.dart'; | ||
|
||
@JsonSerializable() | ||
class StudyTag extends SupabaseObjectFunctions<StudyTag> { | ||
static const String tableName = 'study_tag'; | ||
|
||
@override | ||
Map<String, dynamic> get primaryKeys => {'tag_id': tagId, 'study_id': studyId}; | ||
|
||
@JsonKey(name: 'study_id') | ||
final String studyId; | ||
@JsonKey(name: 'tag_id') | ||
final String tagId; | ||
|
||
@JsonKey(includeToJson: false, includeFromJson: false) | ||
late Tag tag; | ||
|
||
/*@JsonKey(includeToJson: false, includeFromJson: false) | ||
late Study study;*/ | ||
|
||
StudyTag({ | ||
required this.studyId, | ||
required this.tagId, | ||
}); | ||
|
||
StudyTag.fromTag({ | ||
required this.tag, | ||
required this.studyId, | ||
}) : tagId = tag.id; | ||
|
||
factory StudyTag.fromJson(Map<String, dynamic> json) { | ||
final studyTag = _$StudyTagFromJson(json); | ||
|
||
/*final Map<String, dynamic>? study = json['study'] as Map<String, dynamic>?; | ||
if (study != null) { | ||
studyTag.study = Study.fromJson(study); | ||
}*/ | ||
|
||
final Map<String, dynamic>? tag = json['tag'] as Map<String, dynamic>?; | ||
if (tag != null) { | ||
studyTag.tag = Tag.fromJson(tag); | ||
} | ||
|
||
return studyTag; | ||
} | ||
|
||
String get name => tag.name; | ||
|
||
String get id => tag.id; | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$StudyTagToJson(this); | ||
|
||
@override | ||
String toString() => toJson().toString(); | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || other is StudyTag && studyId == other.studyId && tag == other.tag; | ||
|
||
@override | ||
int get hashCode => id.hashCode ^ name.hashCode ^ studyId.hashCode ^ tag.hashCode; | ||
} | ||
|
||
extension StudyTagListToTagList on List<StudyTag> { | ||
List<Tag> toTagList() => map((studyTag) => studyTag.tag).toList(); | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import 'package:json_annotation/json_annotation.dart'; | ||
|
||
import 'package:studyu_core/core.dart'; | ||
import 'package:studyu_core/src/util/supabase_object.dart'; | ||
|
||
part 'tag.g.dart'; | ||
|
||
@JsonSerializable() | ||
class Tag extends SupabaseObjectFunctions<Tag> { | ||
static const String tableName = 'tag'; | ||
|
||
@override | ||
Map<String, dynamic> get primaryKeys => {'id': id}; | ||
|
||
@JsonKey(name: 'id') | ||
String id; | ||
@JsonKey(name: 'name') | ||
String name; | ||
|
||
Tag({required this.id, required this.name}); | ||
|
||
factory Tag.fromJson(Map<String, dynamic> json) => _$TagFromJson(json); | ||
|
||
@override | ||
Map<String, dynamic> toJson() => _$TagToJson(this); | ||
|
||
@override | ||
bool operator ==(Object other) => | ||
identical(this, other) || other is Tag && id == other.id && name == other.name; | ||
|
||
@override | ||
int get hashCode => id.hashCode ^ name.hashCode; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
-- | ||
-- Name: tag; Type: TABLE; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
CREATE TABLE public.tag ( | ||
id uuid DEFAULT gen_random_uuid() NOT NULL, | ||
name text NOT NULL, | ||
color text, | ||
parent_id uuid | ||
-- rename result_sharing to visibility | ||
--visibility public.result_sharing NOT NULL DEFAULT 'private'::public.result_sharing, | ||
); | ||
|
||
ALTER TABLE public.tag OWNER TO supabase_admin; | ||
|
||
|
||
-- | ||
-- Name: tag tag_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
ALTER TABLE ONLY public.tag | ||
ADD CONSTRAINT tag_pkey PRIMARY KEY (id); | ||
|
||
|
||
-- | ||
-- Name: study_tag; Type: TABLE; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
CREATE TABLE public.study_tag ( | ||
study_id uuid NOT NULL, | ||
tag_id uuid NOT NULL | ||
); | ||
|
||
ALTER TABLE public.study_tag OWNER TO supabase_admin; | ||
|
||
|
||
-- | ||
-- Name: study_tag study_tag_pkey; Type: CONSTRAINT; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
ALTER TABLE ONLY public.study_tag | ||
ADD CONSTRAINT "study_tag_pkey" PRIMARY KEY (study_id, tag_id); | ||
|
||
|
||
-- | ||
-- Name: tag tag_parentId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
ALTER TABLE ONLY public.tag | ||
ADD CONSTRAINT "tag_parentId_fkey" FOREIGN KEY (parent_id) REFERENCES public.tag(id) ON DELETE CASCADE; | ||
|
||
|
||
-- | ||
-- Name: tag study_tag_studyId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
ALTER TABLE ONLY public.study_tag | ||
ADD CONSTRAINT "study_tag_studyId_fkey" FOREIGN KEY (study_id) REFERENCES public.study(id) ON DELETE CASCADE; | ||
|
||
|
||
-- | ||
-- Name: tag study_tag_tagId_fkey; Type: FK CONSTRAINT; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
ALTER TABLE ONLY public.study_tag | ||
ADD CONSTRAINT "study_tag_tagId_fkey" FOREIGN KEY (tag_id) REFERENCES public.tag(id) ON DELETE CASCADE; | ||
|
||
|
||
-- TODO VERIFY all policies regarding anonymous select, update, insert, delete and authenticated behavior regarding auth.uid() | ||
|
||
-- | ||
-- Name: study_tag Allow read access but deny write access for tags; Type: POLICY; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
CREATE POLICY "Allow read access, deny write access" | ||
ON public.tag | ||
FOR SELECT | ||
USING (true); | ||
|
||
|
||
-- | ||
-- Name: Allow study creators to manage tags; Type: POLICY; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
CREATE POLICY "Allow study creators to manage tags" | ||
ON public.study_tag | ||
FOR ALL | ||
USING ( | ||
EXISTS ( | ||
SELECT 1 | ||
FROM study | ||
WHERE study.id = study_tag.study_id | ||
AND study.user_id = auth.uid() | ||
) | ||
); | ||
|
||
|
||
-- | ||
-- Name: Allow subscribed users to select study tags; Type: POLICY; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
CREATE POLICY "Allow subscribed users to select study tags" | ||
ON public.study_tag | ||
FOR SELECT | ||
USING ( | ||
EXISTS ( | ||
SELECT 1 | ||
FROM public.study_subject | ||
WHERE study_subject.study_id = study_tag.study_id | ||
AND study_subject.user_id = auth.uid() | ||
) | ||
); | ||
|
||
|
||
-- todo deny insert, delete, update for everyone else | ||
-- todo deny select for everyone except study creators and users subscribed to the study | ||
|
||
|
||
-- | ||
-- Name: tag; Type: ROW SECURITY; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
ALTER TABLE public.tag ENABLE ROW LEVEL SECURITY; | ||
|
||
-- | ||
-- Name: study_tag; Type: ROW SECURITY; Schema: public; Owner: supabase_admin | ||
-- | ||
|
||
ALTER TABLE public.study_tag ENABLE ROW LEVEL SECURITY; |
Oops, something went wrong.