forked from potsda.mn/mobilizon
Some fixes
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
d58ca5743d
commit
62af1e72d6
|
@ -18,7 +18,14 @@
|
|||
"paths": {
|
||||
"@/*": ["src/*"]
|
||||
},
|
||||
"lib": ["esnext", "dom", "es2017.intl", "dom.iterable", "scripthost", "webworker"]
|
||||
"lib": [
|
||||
"esnext",
|
||||
"dom",
|
||||
"es2017.intl",
|
||||
"dom.iterable",
|
||||
"scripthost",
|
||||
"webworker"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"src/**/*.ts",
|
||||
|
|
|
@ -266,15 +266,9 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
|||
%{organizer_actor_id: organizer_actor_id} = args,
|
||||
%{context: %{current_user: %User{} = user}} = _resolution
|
||||
) do
|
||||
if Config.only_groups_can_create_events?() and Map.get(args, :attributed_to_id) == nil do
|
||||
{:error,
|
||||
dgettext(
|
||||
"errors",
|
||||
"Only groups can create events"
|
||||
)}
|
||||
else
|
||||
case User.owns_actor(user, organizer_actor_id) do
|
||||
{:is_owned, %Actor{} = organizer_actor} ->
|
||||
if can_create_event?(args) do
|
||||
if is_organizer_group_member?(args) do
|
||||
args_with_organizer =
|
||||
args |> Map.put(:organizer_actor, organizer_actor) |> extract_timezone(user.id)
|
||||
|
@ -302,17 +296,32 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
|
|||
"Organizer profile doesn't have permission to create an event on behalf of this group"
|
||||
)}
|
||||
end
|
||||
else
|
||||
{:error,
|
||||
dgettext(
|
||||
"errors",
|
||||
"Only groups can create events"
|
||||
)}
|
||||
end
|
||||
|
||||
{:is_owned, nil} ->
|
||||
{:error, dgettext("errors", "Organizer profile is not owned by the user")}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def create_event(_parent, _args, _resolution) do
|
||||
{:error, dgettext("errors", "You need to be logged-in to create events")}
|
||||
end
|
||||
|
||||
@spec can_create_event?(map()) :: boolean()
|
||||
defp can_create_event?(args) do
|
||||
if Config.only_groups_can_create_events?() do
|
||||
Map.get(args, :attributed_to_id) != nil
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Update an event
|
||||
"""
|
||||
|
|
|
@ -10,7 +10,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
|
|||
alias Mobilizon.Federation.ActivityPub.Actions
|
||||
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
|
||||
alias Mobilizon.GraphQL.API
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Users.{User, UserRole}
|
||||
alias Mobilizon.Web.Upload
|
||||
import Mobilizon.Web.Gettext
|
||||
|
||||
|
@ -143,14 +143,14 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
|
|||
}
|
||||
}
|
||||
) do
|
||||
if Config.only_admin_can_create_groups?() and not is_admin(role) do
|
||||
{:error, "only admins can create groups"}
|
||||
else
|
||||
with args when is_map(args) <-
|
||||
Map.update(args, :preferred_username, "", &String.downcase/1),
|
||||
args when is_map(args) <- Map.put(args, :creator_actor, creator_actor),
|
||||
args when is_map(args) <- Map.put(args, :creator_actor_id, creator_actor_id),
|
||||
{:picture, args} when is_map(args) <- {:picture, save_attached_pictures(args)},
|
||||
if can_create_group?(role) do
|
||||
args =
|
||||
args
|
||||
|> Map.update(:preferred_username, "", &String.downcase/1)
|
||||
|> Map.put(:creator_actor, creator_actor)
|
||||
|> Map.put(:creator_actor_id, creator_actor_id)
|
||||
|
||||
with {:picture, args} when is_map(args) <- {:picture, save_attached_pictures(args)},
|
||||
{:ok, _activity, %Actor{type: :Group} = group} <-
|
||||
API.Groups.create_group(args) do
|
||||
{:ok, group}
|
||||
|
@ -161,6 +161,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
|
|||
{:error, err} when is_binary(err) ->
|
||||
{:error, err}
|
||||
end
|
||||
else
|
||||
{:error, dgettext("errors", "Only admins can create groups")}
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -168,6 +170,15 @@ defmodule Mobilizon.GraphQL.Resolvers.Group do
|
|||
{:error, "You need to be logged-in to create a group"}
|
||||
end
|
||||
|
||||
@spec can_create_group?(UserRole.t()) :: boolean()
|
||||
defp can_create_group?(role) do
|
||||
if Config.only_admin_can_create_groups?() do
|
||||
is_admin(role)
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
@doc """
|
||||
Update a group. The creator is automatically added as admin
|
||||
"""
|
||||
|
|
|
@ -60,7 +60,7 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
|||
locale
|
||||
) do
|
||||
language = build_language(language, locale)
|
||||
begins_on = build_begins_on(begins_on, timezone, language)
|
||||
begins_on = build_begins_on(begins_on, timezone)
|
||||
|
||||
begins_on
|
||||
|> datetime_to_string(language)
|
||||
|
@ -74,8 +74,8 @@ defimpl Mobilizon.Service.Metadata, for: Mobilizon.Events.Event do
|
|||
@spec build_language(String.t() | nil, String.t()) :: String.t()
|
||||
defp build_language(language, locale), do: language || locale
|
||||
|
||||
@spec build_begins_on(DateTime.t(), String.t() | nil, String.t()) :: DateTime.t()
|
||||
defp build_begins_on(begins_on, timezone, language) do
|
||||
@spec build_begins_on(DateTime.t(), String.t() | nil) :: DateTime.t()
|
||||
defp build_begins_on(begins_on, timezone) do
|
||||
if timezone do
|
||||
case DateTime.shift_zone(begins_on, timezone) do
|
||||
{:ok, begins_on} -> begins_on
|
||||
|
|
Loading…
Reference in a new issue