Get config and display/hide register button
This commit is contained in:
parent
e864b38ec6
commit
4fa78d7cd2
@ -12,7 +12,7 @@ config :mobilizon,
|
||||
config :mobilizon, :instance,
|
||||
name: System.get_env("MOBILIZON_INSTANCE_NAME") || "Localhost",
|
||||
version: "1.0.0-dev",
|
||||
registrations_open: System.get_env("MOBILIZON_INSTANCE_REGISTRATIONS_OPEN") || true
|
||||
registrations_open: System.get_env("MOBILIZON_INSTANCE_REGISTRATIONS_OPEN") || false
|
||||
|
||||
config :mime, :types, %{
|
||||
"application/activity+json" => ["activity-json"],
|
||||
|
@ -1,5 +1,9 @@
|
||||
use Mix.Config
|
||||
|
||||
config :mobilizon, :instance,
|
||||
name: "Test instance",
|
||||
registrations_open: true
|
||||
|
||||
# We don't run a server during test. If one is required,
|
||||
# you can enable the server option below.
|
||||
config :mobilizon, MobilizonWeb.Endpoint,
|
||||
|
@ -18,7 +18,7 @@
|
||||
<div class="navbar-end">
|
||||
<div class="navbar-item">
|
||||
<div class="buttons">
|
||||
<router-link class="button is-primary" v-if="!currentUser.id" :to="{ name: 'Register' }">
|
||||
<router-link class="button is-primary" v-if="!currentUser.id && config && config.registrationsOpen" :to="{ name: 'Register' }">
|
||||
<strong>
|
||||
<translate>Sign up</translate>
|
||||
</strong>
|
||||
@ -51,6 +51,8 @@ import { deleteUserData } from '@/utils/auth';
|
||||
import { LOGGED_PERSON } from '@/graphql/actor';
|
||||
import { IActor, IPerson } from '@/types/actor.model';
|
||||
import { RouteName } from '@/router';
|
||||
import { CONFIG } from '@/graphql/config';
|
||||
import { IConfig } from '@/types/config.model';
|
||||
|
||||
@Component({
|
||||
apollo: {
|
||||
@ -71,7 +73,10 @@ import { RouteName } from '@/router';
|
||||
loggedPerson: {
|
||||
query: LOGGED_PERSON,
|
||||
},
|
||||
},
|
||||
config: {
|
||||
query: CONFIG,
|
||||
}
|
||||
}
|
||||
})
|
||||
export default class NavBar extends Vue {
|
||||
notifications = [
|
||||
@ -83,6 +88,7 @@ export default class NavBar extends Vue {
|
||||
searchText: string | null = null;
|
||||
searchSelect = null;
|
||||
loggedPerson!: IPerson;
|
||||
config!: IConfig;
|
||||
|
||||
get items() {
|
||||
return this.search.map(searchEntry => {
|
||||
|
@ -1,40 +1,10 @@
|
||||
import gql from 'graphql-tag';
|
||||
|
||||
export const CREATE_USER = gql`
|
||||
mutation CreateUser($email: String!, $password: String!) {
|
||||
createUser(email: $email, password: $password) {
|
||||
email,
|
||||
confirmationSentAt
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const VALIDATE_USER = gql`
|
||||
mutation ValidateUser($token: String!) {
|
||||
validateUser(token: $token) {
|
||||
token,
|
||||
user {
|
||||
id,
|
||||
email,
|
||||
defaultActor {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const CURRENT_USER_CLIENT = gql`
|
||||
export const CONFIG = gql`
|
||||
query {
|
||||
currentUser @client {
|
||||
id,
|
||||
email
|
||||
config {
|
||||
name,
|
||||
registrationsOpen
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export const UPDATE_CURRENT_USER_CLIENT = gql`
|
||||
mutation UpdateCurrentUser($id: Int!, $email: String!) {
|
||||
updateCurrentUser(id: $id, email: $email) @client
|
||||
}
|
||||
`;
|
||||
|
@ -1,7 +1,5 @@
|
||||
import { ICurrentUser } from '@/types/current-user.model';
|
||||
export interface IConfig {
|
||||
name: string,
|
||||
|
||||
export interface ILogin {
|
||||
user: ICurrentUser,
|
||||
|
||||
token: string,
|
||||
registrationsOpen: boolean,
|
||||
}
|
||||
|
@ -37,7 +37,7 @@
|
||||
<translate>Forgot your password ?</translate>
|
||||
</router-link>
|
||||
</div>
|
||||
<div class="control">
|
||||
<div class="control" v-if="config && config.registrationsOpen">
|
||||
<router-link
|
||||
class="button is-text"
|
||||
:to="{ name: 'Register', params: { default_email: credentials.email, default_password: credentials.password }}"
|
||||
@ -61,12 +61,21 @@ import { ILogin } from '@/types/login.model';
|
||||
import { UPDATE_CURRENT_USER_CLIENT } from '@/graphql/user';
|
||||
import { onLogin } from '@/vue-apollo';
|
||||
import { RouteName } from '@/router';
|
||||
import { IConfig } from '@/types/config.model';
|
||||
import { CONFIG } from '@/graphql/config';
|
||||
|
||||
@Component
|
||||
@Component({
|
||||
apollo: {
|
||||
config: {
|
||||
query: CONFIG
|
||||
}
|
||||
}
|
||||
})
|
||||
export default class Login extends Vue {
|
||||
@Prop({ type: String, required: false, default: '' }) email!: string;
|
||||
@Prop({ type: String, required: false, default: '' }) password!: string;
|
||||
|
||||
config!: IConfig;
|
||||
credentials = {
|
||||
email: '',
|
||||
password: '',
|
||||
|
@ -1,7 +1,20 @@
|
||||
defmodule Mobilizon.CommonConfig do
|
||||
def registrations_open?(), do: instance_config() |> get_in([:registrations_open])
|
||||
@moduledoc """
|
||||
Instance configuration wrapper
|
||||
"""
|
||||
|
||||
def instance_name(), do: instance_config() |> get_in([:name])
|
||||
def registrations_open?() do
|
||||
instance_config()
|
||||
|> get_in([:registrations_open])
|
||||
|> to_bool
|
||||
end
|
||||
|
||||
def instance_name() do
|
||||
instance_config()
|
||||
|> get_in([:name])
|
||||
end
|
||||
|
||||
defp instance_config(), do: Application.get_env(:mobilizon, :instance)
|
||||
|
||||
defp to_bool(v), do: v == true or v == "true" or v == "True"
|
||||
end
|
||||
|
@ -2,7 +2,7 @@ defmodule MobilizonWeb.Resolvers.Config do
|
||||
@moduledoc """
|
||||
Handles the config-related GraphQL calls
|
||||
"""
|
||||
require Logger
|
||||
|
||||
import Mobilizon.CommonConfig
|
||||
|
||||
@doc """
|
||||
|
@ -18,7 +18,7 @@ defmodule MobilizonWeb.Resolvers.ConfigResolverTest do
|
||||
context.conn
|
||||
|> get("/api", AbsintheHelpers.query_skeleton(query, "config"))
|
||||
|
||||
assert json_response(res, 200)["data"]["config"]["name"] == "Localhost"
|
||||
assert json_response(res, 200)["data"]["config"]["name"] == "Test instance"
|
||||
assert json_response(res, 200)["data"]["config"]["registrationsOpen"] == true
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user