Merge branch 'split-event-visibility-and-join' into 'master'

Split event visibility and join options

Closes #56

See merge request framasoft/mobilizon!54
This commit is contained in:
Thomas Citharel 2019-02-07 14:07:16 +01:00
commit 7b83682b26
5 changed files with 75 additions and 22 deletions

View File

@ -1,11 +1,22 @@
import { IActor } from "./actor.model";
export enum EventStatus {
TENTATIVE, CONFIRMED, CANCELLED
TENTATIVE,
CONFIRMED,
CANCELLED
}
export enum EventVisibility {
PUBLIC, PRIVATE
PUBLIC,
UNLISTED,
RESTRICTED,
PRIVATE
}
export enum EventJoinOptions {
FREE,
RESTRICTED,
INVITE
}
export enum ParticipantRole {
@ -34,6 +45,7 @@ export interface IEvent {
ends_on: Date;
status: EventStatus;
visibility: EventVisibility;
join_options: EventJoinOptions;
thumbnail: string;
large_image: string;
publish_at: Date;

View File

@ -1,3 +1,4 @@
import {EventJoinOptions} from "../../types/event.model";
<template>
<section>
<h1 class="title">
@ -31,22 +32,16 @@
</template>
<script lang="ts">
// import Location from '@/components/Location';
import VueMarkdown from "vue-markdown";
import { CREATE_EVENT, EDIT_EVENT } from "@/graphql/event";
import { FETCH_CATEGORIES } from "@/graphql/category";
import { AUTH_USER_ACTOR } from "@/constants";
import { Component, Prop, Vue } from "vue-property-decorator";
import {
IEvent,
ICategory,
EventVisibility,
EventStatus
} from "../../types/event.model";
import { LOGGED_PERSON } from "../../graphql/actor";
import { IPerson } from "../../types/actor.model";
// import Location from '@/components/Location';
import VueMarkdown from "vue-markdown";
import {CREATE_EVENT, EDIT_EVENT} from "@/graphql/event";
import {FETCH_CATEGORIES} from "@/graphql/category";
import {Component, Prop, Vue} from "vue-property-decorator";
import {EventJoinOptions, EventStatus, EventVisibility, ICategory, IEvent} from "@/types/event.model";
import {LOGGED_PERSON} from "@/graphql/actor";
import {IPerson} from "@/types/actor.model";
@Component({
@Component({
components: {
VueMarkdown
},
@ -70,7 +65,7 @@ export default class CreateEvent extends Vue {
// }
async created() {
// We put initialization here because we need loggedPerson to be ready before initalizing event
// We put initialization here because we need loggedPerson to be ready before initializing event
const { data } = await this.$apollo.query({ query: LOGGED_PERSON });
this.loggedPerson = data.loggedPerson;
@ -89,6 +84,7 @@ export default class CreateEvent extends Vue {
local: true,
status: EventStatus.CONFIRMED,
visibility: EventVisibility.PUBLIC,
join_options: EventJoinOptions.FREE,
thumbnail: "",
large_image: "",
publish_at: new Date()

View File

@ -3,8 +3,13 @@ import EctoEnum
defenum(Mobilizon.Events.EventVisibilityEnum, :event_visibility_type, [
:public,
:unlisted,
:private,
:moderated,
:restricted,
:private
])
defenum(Mobilizon.Events.JoinOptionsEnum, :event_join_options_type, [
:free,
:restricted,
:invite
])
@ -33,6 +38,7 @@ defmodule Mobilizon.Events.Event do
field(:title, :string)
field(:status, Mobilizon.Events.EventStatusEnum, default: :confirmed)
field(:visibility, Mobilizon.Events.EventVisibilityEnum, default: :public)
field(:join_options, Mobilizon.Events.JoinOptionsEnum, default: :free)
field(:thumbnail, :string)
field(:large_image, :string)
field(:publish_at, Timex.Ecto.DateTimeWithTimezone)

View File

@ -0,0 +1,40 @@
defmodule Mobilizon.Repo.Migrations.SplitEventVisibilityAndJoinOptions do
use Ecto.Migration
alias Mobilizon.Events.EventVisibilityEnum
alias Mobilizon.Events.JoinOptionsEnum
@doc """
EventVisibilityEnum has dropped some possible values, so we need to recreate it
Visibility allowed nullable values previously
"""
def up do
execute "ALTER TABLE events ALTER COLUMN visibility TYPE VARCHAR USING visibility::text"
EventVisibilityEnum.drop_type
EventVisibilityEnum.create_type
execute "ALTER TABLE events ALTER COLUMN visibility TYPE event_visibility_type USING visibility::event_visibility_type"
JoinOptionsEnum.create_type
alter table(:events) do
add(:join_options, JoinOptionsEnum.type(), null: false, default: "free")
end
execute "UPDATE events SET visibility = 'public' WHERE visibility IS NULL"
alter table(:events) do
modify(:visibility, EventVisibilityEnum.type(), null: false, default: "public")
end
end
def down do
alter table(:events) do
remove(:join_options)
end
JoinOptionsEnum.drop_type
execute "ALTER TABLE events ALTER COLUMN visibility TYPE VARCHAR USING visibility::text"
EventVisibilityEnum.drop_type
EventVisibilityEnum.create_type
execute "ALTER TABLE events ALTER COLUMN visibility TYPE event_visibility_type USING visibility::event_visibility_type"
end
end

View File

@ -249,8 +249,7 @@ defmodule MobilizonWeb.Resolvers.EventResolverTest do
test "list_events/3 doesn't list private events", context do
insert(:event, visibility: :private)
insert(:event, visibility: :unlisted)
insert(:event, visibility: :moderated)
insert(:event, visibility: :invite)
insert(:event, visibility: :restricted)
query = """
{