From a1726fc12e44c35b871e017c08729de5d1a522bf Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 2 Nov 2022 11:36:32 +0100 Subject: [PATCH 1/2] Add sha-256 hash for toggling dark theme code and remove inlined phoenix digest Follow-up to !1300 Signed-off-by: Thomas Citharel --- lib/web/plugs/http_security_plug.ex | 3 ++- lib/web/templates/page/index.html.heex | 1 - test/web/plugs/http_security_plug_test.exs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/web/plugs/http_security_plug.ex b/lib/web/plugs/http_security_plug.ex index b18c85d14..082507a2d 100644 --- a/lib/web/plugs/http_security_plug.ex +++ b/lib/web/plugs/http_security_plug.ex @@ -85,7 +85,8 @@ defmodule Mobilizon.Web.Plugs.HTTPSecurityPlug do else [ @script_src, - "'sha256-4RS22DYeB7U14dra4KcQYxmwt5HkOInieXK1NUMBmQI=' " + "'sha256-4RS22DYeB7U14dra4KcQYxmwt5HkOInieXK1NUMBmQI=' ", + "'sha256-zJdRXhLWm9NGI6BFr+sNmHBBrjAdJdFr7MpUq0EwK58=' " ] end diff --git a/lib/web/templates/page/index.html.heex b/lib/web/templates/page/index.html.heex index d24ba8cf8..7047727cb 100644 --- a/lib/web/templates/page/index.html.heex +++ b/lib/web/templates/page/index.html.heex @@ -20,7 +20,6 @@ <% end %> <%= tags(assigns) || assigns.tags %> - <%= Vite.inlined_phx_manifest() %> <%= Vite.vite_client() %> <%= Vite.vite_snippet("src/main.ts") %> diff --git a/test/web/plugs/http_security_plug_test.exs b/test/web/plugs/http_security_plug_test.exs index 6abd6a6cb..43be1dec4 100644 --- a/test/web/plugs/http_security_plug_test.exs +++ b/test/web/plugs/http_security_plug_test.exs @@ -73,7 +73,7 @@ defmodule Mobilizon.Web.Plugs.HTTPSecurityPlugTest do [csp] = Conn.get_resp_header(conn, "content-security-policy") assert csp =~ - ~r/script-src 'self' 'unsafe-eval' 'sha256-[\w+\/=]*' example.com matomo.example.com ;/ + ~r/script-src 'self' 'unsafe-eval' 'sha256-[\w+\/=]*' 'sha256-[\w+\/=]*' example.com matomo.example.com ;/ end end From dcfe87116e65152436539decdad0ba7b6609e1ef Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Wed, 2 Nov 2022 11:38:14 +0100 Subject: [PATCH 2/2] Allow to view more than 10 drafts events on my events view Closes #993 Signed-off-by: Thomas Citharel --- js/src/graphql/actor.ts | 51 +++++----- js/src/types/current-user.model.ts | 2 +- js/src/views/Event/MyEventsView.vue | 146 +++++++++------------------- lib/graphql/schema/user.ex | 4 +- lib/mobilizon/events/events.ex | 6 +- 5 files changed, 78 insertions(+), 131 deletions(-) diff --git a/js/src/graphql/actor.ts b/js/src/graphql/actor.ts index de899ef21..3a1ec38d9 100644 --- a/js/src/graphql/actor.ts +++ b/js/src/graphql/actor.ts @@ -205,31 +205,34 @@ export const LOGGED_USER_DRAFTS = gql` loggedUser { id drafts(page: $page, limit: $limit) { - id - uuid - title - draft - picture { + total + elements { id - url - alt - } - beginsOn - status - visibility - attributedTo { - ...ActorFragment - } - organizerActor { - ...ActorFragment - } - participantStats { - going - notApproved - } - options { - maximumAttendeeCapacity - remainingAttendeeCapacity + uuid + title + draft + picture { + id + url + alt + } + beginsOn + status + visibility + attributedTo { + ...ActorFragment + } + organizerActor { + ...ActorFragment + } + participantStats { + going + notApproved + } + options { + maximumAttendeeCapacity + remainingAttendeeCapacity + } } } } diff --git a/js/src/types/current-user.model.ts b/js/src/types/current-user.model.ts index f2dda9ad2..4c4e57cd9 100644 --- a/js/src/types/current-user.model.ts +++ b/js/src/types/current-user.model.ts @@ -54,7 +54,7 @@ export interface IUser extends ICurrentUser { disabled: boolean; participations: Paginate; mediaSize: number; - drafts: IEvent[]; + drafts: Paginate; settings: IUserSettings; activitySettings: IActivitySetting[]; followedGroupEvents: Paginate; diff --git a/js/src/views/Event/MyEventsView.vue b/js/src/views/Event/MyEventsView.vue index ef1ab3295..286e73090 100644 --- a/js/src/views/Event/MyEventsView.vue +++ b/js/src/views/Event/MyEventsView.vue @@ -19,9 +19,9 @@ > -
+
{{ @@ -73,15 +73,31 @@ />
-
+
- +

{{ t("Drafts") }}

+ + +
- {{ month[0] }} +

{{ month[0] }}

@@ -209,10 +225,15 @@ import { import { useQuery } from "@vue/apollo-composable"; import { computed, inject, ref, defineAsyncComponent } from "vue"; import { IUser } from "@/types/current-user.model"; -import { booleanTransformer, useRouteQuery } from "vue-use-route-query"; +import { + booleanTransformer, + integerTransformer, + useRouteQuery, +} from "vue-use-route-query"; import { Locale } from "date-fns"; import { useI18n } from "vue-i18n"; import { useRestrictions } from "@/composition/apollo/config"; +import { useHead } from "@vueuse/head"; const EventParticipationCard = defineAsyncComponent( () => import("@/components/Event/EventParticipationCard.vue") @@ -253,8 +274,6 @@ const dateFilter = useRouteQuery("dateFilter", new Date(), { const hasMoreFutureParticipations = ref(true); const hasMorePastParticipations = ref(true); -// config: CONFIG - const { result: loggedUserUpcomingEventsResult, fetchMore: fetchMoreUpcomingEvents, @@ -277,10 +296,17 @@ const groupEvents = computed( .elements ?? [] ); +const LOGGED_USER_DRAFTS_LIMIT = 10; +const draftsPage = useRouteQuery("draftsPage", 1, integerTransformer); + const { result: draftsResult } = useQuery<{ loggedUser: Pick; -}>(LOGGED_USER_DRAFTS, () => ({ page: 1, limit: 10 })); -const drafts = computed(() => draftsResult.value?.loggedUser.drafts ?? []); +}>( + LOGGED_USER_DRAFTS, + () => ({ page: draftsPage.value, limit: LOGGED_USER_DRAFTS_LIMIT }), + () => ({ fetchPolicy: "cache-and-network" }) +); +const drafts = computed(() => draftsResult.value?.loggedUser.drafts); const { result: participationsResult, fetchMore: fetchMoreParticipations } = useQuery<{ @@ -294,12 +320,6 @@ const pastParticipations = computed( } ); -// metaInfo() { -// return { -// title: this.t("My events") as string, -// }; -// }, - const monthlyEvents = ( elements: Eventable[], revertSort = false @@ -413,86 +433,8 @@ const dateFnsLocale = inject("dateFnsLocale"); const firstDayOfWeek = computed((): number => { return dateFnsLocale?.options?.weekStartsOn ?? 0; }); + +useHead({ + title: computed(() => t("My events")), +}); - - diff --git a/lib/graphql/schema/user.ex b/lib/graphql/schema/user.ex index 5a3aff7bd..ce139cf97 100644 --- a/lib/graphql/schema/user.ex +++ b/lib/graphql/schema/user.ex @@ -96,7 +96,9 @@ defmodule Mobilizon.GraphQL.Schema.UserType do resolve(&User.user_memberships/3) end - field(:drafts, list_of(:event), description: "The list of draft events this user has created") do + field(:drafts, :paginated_event_list, + description: "The list of draft events this user has created" + ) do arg(:page, :integer, default_value: 1, description: "The page in the paginated drafts events list" diff --git a/lib/mobilizon/events/events.ex b/lib/mobilizon/events/events.ex index 95234053b..aedc9d394 100644 --- a/lib/mobilizon/events/events.ex +++ b/lib/mobilizon/events/events.ex @@ -465,13 +465,13 @@ defmodule Mobilizon.Events do |> Page.build_page(page, limit) end - @spec list_drafts_for_user(integer, integer | nil, integer | nil) :: [Event.t()] + @spec list_drafts_for_user(integer, integer | nil, integer | nil) :: Page.t(Event.t()) def list_drafts_for_user(user_id, page \\ nil, limit \\ nil) do Event |> user_events_query(user_id) |> filter_draft(true) - |> Page.paginate(page, limit) - |> Repo.all() + |> order_by(desc: :updated_at) + |> Page.build_page(page, limit) end @spec is_user_moderator_for_event?(integer | String.t(), integer | String.t()) :: boolean