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