Skip to content
Snippets Groups Projects
Verified Commit cec500f7 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Store currently activated calendars in user profile

parent abd13645
No related branches found
No related tags found
1 merge request!1148Calendar events and iCal feeds
......@@ -50,6 +50,7 @@
<calendar-select
v-model="selectedCalendarFeedNames"
:calendar-feeds="calendar.calendarFeeds"
@input="storeActivatedCalendars"
/>
</button-menu>
</v-col>
......@@ -92,6 +93,7 @@
class="mb-4"
v-model="selectedCalendarFeedNames"
:calendar-feeds="calendar.calendarFeeds"
@input="storeActivatedCalendars"
/>
<v-btn depressed block v-if="calendar" :href="calendar.allFeedsUrl">
<v-icon left>mdi-download-outline</v-icon>
......@@ -155,6 +157,7 @@ import {
} from "aleksisAppImporter";
import gqlCalendarOverview from "./calendarOverview.graphql";
import gqlSetCalendarStatus from "./setCalendarStatus.graphql";
export default {
name: "CalendarOverview",
......@@ -197,6 +200,11 @@ export default {
calendar: {
query: gqlCalendarOverview,
skip: true,
result({ data }) {
this.selectedCalendarFeedNames = data.calendar.calendarFeeds
.filter((c) => c.activated)
.map((c) => c.name);
},
},
},
computed: {
......@@ -268,6 +276,15 @@ export default {
getColorForEvent(event) {
return event.color;
},
storeActivatedCalendars() {
// Store currently activated calendars in the backend
this.$apollo.mutate({
mutation: gqlSetCalendarStatus,
variables: {
calendars: this.selectedCalendarFeedNames,
},
});
},
fetchMoreCalendarEvents({ start, end }) {
// Get the start and end dates of the current date range shown in the calendar
let extendedStart = this.$refs.calendar.getStartOfWeek(start).date;
......
......@@ -7,6 +7,7 @@ query ($start: Date, $end: Date) {
description
url
color
activated
feed {
events(start: $start, end: $end) {
name
......
mutation ($calendars: [String]!) {
setCalendarStatus(calendars: $calendars) {
ok
}
}
......@@ -718,7 +718,17 @@ class CalendarEventMixin(RegistryObject):
def value_color(cls, reference_object, request) -> str:
return cls.get_color(request)
@classproperty
def valid_feed(cls):
"""Return if the feed is valid."""
return cls.name != cls.__name__
@classproperty
def valid_feeds(cls):
"""Return a list of valid feeds."""
return [feed for feed in cls.registered_objects_list if feed.name != feed.__name__]
return [feed for feed in cls.registered_objects_list if feed.valid_feed]
@classproperty
def valid_feed_names(cls):
"""Return a list of valid feed names."""
return [feed.name for feed in cls.valid_feeds]
......@@ -16,7 +16,7 @@ from dynamic_preferences.types import (
)
from oauth2_provider.models import AbstractApplication
from .mixins import PublicFilePreferenceMixin
from .mixins import CalendarEventMixin, PublicFilePreferenceMixin
from .models import Group, Person
from .registries import person_preferences_registry, site_preferences_registry
from .util.notifications import get_notification_choices_lazy
......@@ -502,3 +502,18 @@ class HolidayFeedColor(StringPreference):
verbose_name = _("Holiday calendar feed color")
widget = ColorWidget
required = True
@person_preferences_registry.register
class ActivatedCalendars(MultipleChoicePreference):
"""Calendars that are activated for a person."""
section = calendar
name = "activated_calendars"
default = []
widget = SelectMultiple
verbose_name = _("Activated calendars")
required = False
field_attribute = {"initial": []}
choices = [(feed.name, feed.verbose_name) for feed in CalendarEventMixin.valid_feeds]
......@@ -20,7 +20,7 @@ from ..models import (
)
from ..util.apps import AppConfig
from ..util.core_helpers import get_allowed_object_ids, get_app_module, get_app_packages, has_person
from .calendar import CalendarBaseType
from .calendar import CalendarBaseType, SetCalendarStatusMutation
from .celery_progress import CeleryProgressFetchedMutation, CeleryProgressType
from .custom_menu import CustomMenuType
from .dynamic_routes import DynamicRouteType
......@@ -188,6 +188,8 @@ class Mutation(graphene.ObjectType):
revoke_oauth_token = OAuthRevokeTokenMutation.Field()
set_calendar_status = SetCalendarStatusMutation.Field()
def build_global_schema():
"""Build global GraphQL schema from all apps."""
......
from datetime import datetime
from django.core.exceptions import PermissionDenied
from django.urls import reverse
import graphene
from graphene import ObjectType
from aleksis.core.mixins import CalendarEventMixin
from aleksis.core.util.core_helpers import has_person
class CalendarEventType(ObjectType):
......@@ -71,6 +73,8 @@ class CalendarType(ObjectType):
url = graphene.String()
activated = graphene.Boolean()
def resolve_verbose_name(root, info, **kwargs):
return root.get_verbose_name(info.context)
......@@ -86,6 +90,25 @@ class CalendarType(ObjectType):
def resolve_color(root, info, **kwargs):
return root.get_color(info.context)
def resolve_activated(root, info, **kwargs):
return root.name in info.context.user.person.preferences["calendar__activated_calendars"]
class SetCalendarStatusMutation(graphene.Mutation):
"""Mutation to change the status of a calendar."""
class Arguments:
calendars = graphene.List(graphene.String)
ok = graphene.Boolean()
def mutate(root, info, calendars, **kwargs):
if not has_person(info.context):
raise PermissionDenied
calendar_feeds = [cal for cal in calendars if cal in CalendarEventMixin.valid_feed_names]
info.context.user.person.preferences["calendar__activated_calendars"] = calendar_feeds
return SetCalendarStatusMutation(ok=True)
class CalendarBaseType(ObjectType):
calendar_feeds = graphene.List(CalendarType)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment