Skip to content

armgit / fider

Public Imported from GitHub
0

Open platform to collect and prioritize feedback

Allow admins to change Title, Invitation and Welcome Message (#80)

Guilherme Oenning394afcc4fe64
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 8ef09184e..8a1f45edb 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -30,5 +30,6 @@
"vsicons.presets.angular": true,
"go.coverOnSave": true,
"go.coverageOptions": "showBothCoveredAndUncoveredCode",
+ "go.coverageDecorator": "gutter",
"go.testEnvFile": "${workspaceRoot}/.test.env"
}
\ No newline at end of file
diff --git a/app/handlers/admin.go b/app/handlers/admin.go
new file mode 100644
index 000000000..8554ee90a
--- /dev/null
+++ b/app/handlers/admin.go
@@ -0,0 +1,22 @@
+package handlers
+
+import (
+ "github.com/getfider/fider/app/models/im"
+ "github.com/getfider/fider/app/pkg/web"
+)
+
+// UpdateSettings update current tenant' settings
+func UpdateSettings() web.HandlerFunc {
+ return func(c web.Context) error {
+ input := new(im.UpdateTenantSettings)
+ if result := c.BindTo(input); !result.Ok {
+ return c.HandleValidation(result)
+ }
+ err := c.Services().Tenants.UpdateSettings(c.Tenant().ID, input.Title, input.Invitation, input.WelcomeMessage)
+ if err != nil {
+ return c.Failure(err)
+ }
+
+ return c.Ok(web.Map{})
+ }
+}
diff --git a/app/handlers/admin_test.go b/app/handlers/admin_test.go
new file mode 100644
index 000000000..1aefff7a1
--- /dev/null
+++ b/app/handlers/admin_test.go
@@ -0,0 +1,31 @@
+package handlers_test
+
+import (
+ "testing"
+
+ "github.com/getfider/fider/app"
+ "github.com/getfider/fider/app/handlers"
+ "github.com/getfider/fider/app/models"
+ "github.com/getfider/fider/app/pkg/mock"
+ "github.com/getfider/fider/app/storage/inmemory"
+ . "github.com/onsi/gomega"
+)
+
+func TestUpdateSettingsHandler(t *testing.T) {
+ RegisterTestingT(t)
+
+ tenants := &inmemory.TenantStorage{}
+ tenants.Add("Demonstration", "demo")
+ server := mock.NewServer()
+ server.Context.SetServices(&app.Services{Tenants: tenants})
+ server.Context.SetTenant(&models.Tenant{ID: 1, Name: "Any Tenant"})
+ server.Context.SetUser(&models.User{ID: 1, Name: "Jon", Role: models.RoleAdministrator})
+
+ code, _ := server.ExecutePost(handlers.UpdateSettings(), `{ "title": "GoT", "invitation": "Join us!", "welcomeMessage": "Welcome to GoT Feedback Forum" }`)
+
+ tenant, _ := tenants.GetByDomain("demo")
+ Expect(code).To(Equal(200))
+ Expect(tenant.Name).To(Equal("GoT"))
+ Expect(tenant.Invitation).To(Equal("Join us!"))
+ Expect(tenant.WelcomeMessage).To(Equal("Welcome to GoT Feedback Forum"))
+}
diff --git a/app/models/identity.go b/app/models/identity.go
index aec4d4303..7dbbbb315 100644
--- a/app/models/identity.go
+++ b/app/models/identity.go
@@ -4,10 +4,12 @@ import jwt "github.com/dgrijalva/jwt-go"
//Tenant represents a tenant
type Tenant struct {
- ID int `json:"id"`
- Name string `json:"name"`
- Subdomain string `json:"subdomain"`
- CNAME string `json:"cname"`
+ ID int `json:"id"`
+ Name string `json:"name"`
+ Subdomain string `json:"subdomain"`
+ Invitation string `json:"invitation"`
+ WelcomeMessage string `json:"welcomeMessage"`
+ CNAME string `json:"cname"`
}
//User represents an user inside our application
diff --git a/app/models/im/tenant.go b/app/models/im/tenant.go
index c50e02fd2..80cd1a197 100644
--- a/app/models/im/tenant.go
+++ b/app/models/im/tenant.go
@@ -1,6 +1,8 @@
package im
import (
+ "strings"
+
"github.com/getfider/fider/app"
"github.com/getfider/fider/app/models"
"github.com/getfider/fider/app/pkg/env"
@@ -49,3 +51,39 @@ func (i *CreateTenant) Validate(services *app.Services) *validate.Result {
return result
}
+
+//UpdateTenantSettings is the input model used to update tenant settings
+type UpdateTenantSettings struct {
+ Title string `json:"title"`
+ Invitation string `json:"invitation"`
+ WelcomeMessage string `json:"welcomeMessage"`
+ UserClaims *models.OAuthClaims
+}
+
+// IsAuthorized returns true if current user is authorized to perform this action
+func (input *UpdateTenantSettings) IsAuthorized(user *models.User) bool {
+ return user != nil && user.Role == models.RoleAdministrator
+}
+
+// Validate is current model is valid
+func (input *UpdateTenantSettings) Validate(services *app.Services) *validate.Result {
+ result := validate.Success()
+
+ input.Title = strings.Trim(input.Title, " ")
+ input.Invitation = strings.Trim(input.Invitation, " ")
+ input.WelcomeMessage = strings.Trim(input.WelcomeMessage, " ")
+
+ if input.Title == "" {
+ result.AddFieldFailure("title", "Title is required.")
+ }
+
+ if len(input.Title) > 60 {
+ result.AddFieldFailure("title", "Title must have less than 60 characters.")
+ }
+
+ if len(input.Invitation) > 60 {
+ result.AddFieldFailure("invitation", "Invitation must have less than 60 characters.")
+ }
+
+ return result
+}
diff --git a/app/models/im/tenant_test.go b/app/models/im/tenant_test.go
index 5dc895bd4..76e721677 100644
--- a/app/models/im/tenant_test.go
+++ b/app/models/im/tenant_test.go
@@ -30,3 +30,27 @@ func TestCreateTenant_EmptySubdomain(t *testing.T) {
result := input.Validate(services)
ExpectFailed(result, "subdomain")
}
+
+func TestUpdateTenantSettings_EmptyTitle(t *testing.T) {
+ RegisterTestingT(t)
+
+ input := im.UpdateTenantSettings{}
+ result := input.Validate(services)
+ ExpectFailed(result, "title")
+}
+
+func TestUpdateTenantSettings_LargeTitle(t *testing.T) {
+ RegisterTestingT(t)
+
+ input := im.UpdateTenantSettings{Title: "123456789012345678901234567890123456789012345678901234567890123"}
+ result := input.Validate(services)
+ ExpectFailed(result, "title")
+}
+
+func TestUpdateTenantSettings_LargeInvitation(t *testing.T) {
+ RegisterTestingT(t)
+
+ input := im.UpdateTenantSettings{Title: "Ok", Invitation: "123456789012345678901234567890123456789012345678901234567890123"}
+ result := input.Validate(services)
+ ExpectFailed(result, "invitation")
+}
diff --git a/app/pkg/dbx/setup.sql b/app/pkg/dbx/setup.sql
index 2ccecc810..07d9d9ba3 100644
--- a/app/pkg/dbx/setup.sql
+++ b/app/pkg/dbx/setup.sql
@@ -1,6 +1,6 @@
TRUNCATE TABLE tenants RESTART IDENTITY CASCADE;
-INSERT INTO tenants (name, subdomain, created_on, cname) VALUES ('Demonstration', 'demo', now(), '');
+INSERT INTO tenants (name, subdomain, created_on, cname, invitation, welcome_message) VALUES ('Demonstration', 'demo', now(), '', '', '');
INSERT INTO users (name, email, tenant_id, created_on, role) VALUES ('Jon Snow', '[email protected]', 1, now(), 3);
INSERT INTO user_providers (user_id, provider, provider_uid, created_on) VALUES (1, 'facebook', 'FB1234', now());
@@ -8,7 +8,7 @@ INSERT INTO user_providers (user_id, provider, provider_uid, created_on) VALUES
INSERT INTO users (name, email, tenant_id, created_on, role) VALUES ('Arya Stark', '[email protected]', 1, now(), 1);
INSERT INTO user_providers (user_id, provider, provider_uid, created_on) VALUES (2, 'google', 'GO5678', now());
-INSERT INTO tenants (name, subdomain, created_on, cname) VALUES ('Orange Inc.', 'orange', now(), 'feedback.orangeinc.com');
+INSERT INTO tenants (name, subdomain, created_on, cname, invitation, welcome_message) VALUES ('Orange Inc.', 'orange', now(), 'feedback.orangeinc.com', '', '');
INSERT INTO users (name, email, tenant_id, created_on, role) VALUES ('Tony Stark', '[email protected]', 2, now(), 3);
INSERT INTO user_providers (user_id, provider, provider_uid, created_on) VALUES (3, 'facebook', 'FB2222', now());
diff --git a/app/pkg/validate/validation.go b/app/pkg/validate/validation.go
index e45608875..85ce4cc37 100644
--- a/app/pkg/validate/validation.go
+++ b/app/pkg/validate/validation.go
@@ -11,6 +11,11 @@ type Validatable interface {
IsAuthorized(user *models.User) bool
}
+// ValidationContext is the validation context
+type ValidationContext struct {
+ Services *app.Services
+}
+
// Result is returned after each validation
type Result struct {
Ok bool
diff --git a/app/pkg/web/context.go b/app/pkg/web/context.go
index 5783b0312..e43de811c 100644
--- a/app/pkg/web/context.go
+++ b/app/pkg/web/context.go
@@ -89,7 +89,6 @@ func (ctx *Context) HandleValidation(result *validate.Result) error {
return ctx.Unauthorized()
}
- fmt.Print(result)
return ctx.BadRequest(Map{
"message": result.Messages,
"failures": result.Failures,
diff --git a/app/storage/identity.go b/app/storage/identity.go
index 9621ace9c..4a08c19c3 100644
--- a/app/storage/identity.go
+++ b/app/storage/identity.go
@@ -16,5 +16,6 @@ type Tenant interface {
Add(name string, subdomain string) (*models.Tenant, error)
First() (*models.Tenant, error)
GetByDomain(domain string) (*models.Tenant, error)
+ UpdateSettings(tenantID int, title, invitation, welcomeMessage string) error
IsSubdomainAvailable(subdomain string) (bool, error)
}
diff --git a/app/storage/inmemory/tenant.go b/app/storage/inmemory/tenant.go
index 6819e7745..321241da0 100644
--- a/app/storage/inmemory/tenant.go
+++ b/app/storage/inmemory/tenant.go
@@ -51,6 +51,19 @@ func (s *TenantStorage) IsSubdomainAvailable(subdomain string) (bool, error) {
return true, nil
}
+// UpdateSettings of given tenant
+func (s *TenantStorage) UpdateSettings(tenantID int, title, invitation, welcomeMessage string) error {
+ for _, tenant := range s.tenants {
+ if tenant.ID == tenantID {
+ tenant.Invitation = invitation
+ tenant.WelcomeMessage = welcomeMessage
+ tenant.Name = title
+ return nil
+ }
+ }
+ return nil
+}
+
func extractSubdomain(domain string) string {
if idx := strings.Index(domain, "."); idx != -1 {
return domain[:idx]
diff --git a/app/storage/postgres/tenant.go b/app/storage/postgres/tenant.go
index f6b2b1560..7a0b2cd21 100644
--- a/app/storage/postgres/tenant.go
+++ b/app/storage/postgres/tenant.go
@@ -22,26 +22,30 @@ func NewTenantStorage(trx *dbx.Trx) *TenantStorage {
}
type dbTenant struct {
- ID int `db:"id"`
- Name string `db:"name"`
- Subdomain string `db:"subdomain"`
- CNAME string `db:"cname"`
+ ID int `db:"id"`
+ Name string `db:"name"`
+ Subdomain string `db:"subdomain"`
+ CNAME string `db:"cname"`
+ Invitation string `db:"invitation"`
+ WelcomeMessage string `db:"welcome_message"`
}
func (t *dbTenant) toModel() *models.Tenant {
return &models.Tenant{
- ID: t.ID,
- Name: t.Name,
- Subdomain: t.Subdomain,
- CNAME: t.CNAME,
+ ID: t.ID,
+ Name: t.Name,
+ Subdomain: t.Subdomain,
+ CNAME: t.CNAME,
+ Invitation: t.Invitation,
+ WelcomeMessage: t.WelcomeMessage,
}
}
// Add given tenant to tenant list
func (s *TenantStorage) Add(name string, subdomain string) (*models.Tenant, error) {
var id int
- row := s.trx.QueryRow(`INSERT INTO tenants (name, subdomain, created_on, cname)
- VALUES ($1, $2, $3, '')
+ row := s.trx.QueryRow(`INSERT INTO tenants (name, subdomain, created_on, cname, invitation, welcome_message)
+ VALUES ($1, $2, $3, '', '', '')
RETURNING id`, name, subdomain, time.Now())
if err := row.Scan(&id); err != nil {
return nil, err
@@ -54,7 +58,7 @@ func (s *TenantStorage) Add(name string, subdomain string) (*models.Tenant, erro
func (s *TenantStorage) First() (*models.Tenant, error) {
tenant := dbTenant{}
- err := s.trx.Get(&tenant, "SELECT id, name, subdomain, cname FROM tenants LIMIT 1")
+ err := s.trx.Get(&tenant, "SELECT id, name, subdomain, cname, invitation, welcome_message FROM tenants LIMIT 1")
if err == sql.ErrNoRows {
return nil, app.ErrNotFound
} else if err != nil {
@@ -68,7 +72,7 @@ func (s *TenantStorage) First() (*models.Tenant, error) {
func (s *TenantStorage) GetByDomain(domain string) (*models.Tenant, error) {
tenant := dbTenant{}
- err := s.trx.Get(&tenant, "SELECT id, name, subdomain, cname FROM tenants WHERE subdomain = $1 OR cname = $2", extractSubdomain(domain), domain)
+ err := s.trx.Get(&tenant, "SELECT id, name, subdomain, cname, invitation, welcome_message FROM tenants WHERE subdomain = $1 OR cname = $2", extractSubdomain(domain), domain)
if err == sql.ErrNoRows {
return nil, app.ErrNotFound
} else if err != nil {
@@ -78,6 +82,12 @@ func (s *TenantStorage) GetByDomain(domain string) (*models.Tenant, error) {
return tenant.toModel(), nil
}
+// UpdateSettings of given tenant
+func (s *TenantStorage) UpdateSettings(tenantID int, title, invitation, welcomeMessage string) error {
+ query := "UPDATE tenants SET name = $1, invitation = $2, welcome_message = $3 WHERE id = $4"
+ return s.trx.Execute(query, title, invitation, welcomeMessage, tenantID)
+}
+
// IsSubdomainAvailable returns true if subdomain is available to use
func (s *TenantStorage) IsSubdomainAvailable(subdomain string) (bool, error) {
exists, err := s.trx.Exists("SELECT id FROM tenants WHERE subdomain = $1", subdomain)
diff --git a/app/storage/postgres/tenant_test.go b/app/storage/postgres/tenant_test.go
index b45b8e1fd..1e10ea67a 100644
--- a/app/storage/postgres/tenant_test.go
+++ b/app/storage/postgres/tenant_test.go
@@ -112,3 +112,26 @@ func TestTenantStorage_IsSubdomainAvailable_NewDomain(t *testing.T) {
Expect(available).To(BeTrue())
Expect(err).To(BeNil())
}
+
+func TestTenantStorage_UpdateSettings(t *testing.T) {
+ RegisterTestingT(t)
+ db, _ := dbx.New()
+ db.Seed()
+ defer db.Close()
+
+ trx, _ := db.Begin()
+ defer trx.Rollback()
+
+ tenants := postgres.NewTenantStorage(trx)
+ tenant, _ := tenants.GetByDomain("demo")
+
+ err := tenants.UpdateSettings(tenant.ID, "New Demonstration", "Leave us your suggestion", "Welcome!")
+ Expect(err).To(BeNil())
+
+ tenant, err = tenants.GetByDomain("demo")
+ Expect(err).To(BeNil())
+ Expect(tenant.ID).To(Equal(1))
+ Expect(tenant.Name).To(Equal("New Demonstration"))
+ Expect(tenant.Invitation).To(Equal("Leave us your suggestion"))
+ Expect(tenant.WelcomeMessage).To(Equal("Welcome!"))
+}
diff --git a/migrations/201707271826_new_tenant_settings.up.sql b/migrations/201707271826_new_tenant_settings.up.sql
new file mode 100644
index 000000000..49dc5caec
--- /dev/null
+++ b/migrations/201707271826_new_tenant_settings.up.sql
@@ -0,0 +1,4 @@
+alter table tenants add invitation varchar(100) null;
+alter table tenants add welcome_message text null;
+
+update tenants set invitation = '', welcome_message = '';
\ No newline at end of file
diff --git a/public/index.tsx b/public/index.tsx
index aa290f63c..74a6f1324 100644
--- a/public/index.tsx
+++ b/public/index.tsx
@@ -1,7 +1,7 @@
import * as React from 'react';
import * as ReactDOM from 'react-dom';
-import { AdminHomePage } from '@fider/pages/AdminHomePage';
+import { AdminHomePage } from '@fider/pages/admin/AdminHomePage';
import { SiteHomePage } from '@fider/pages/home/SiteHomePage';
import { ShowIdeaPage } from '@fider/pages/ShowIdeaPage';
import { SignUpPage } from '@fider/pages/signup/SignUpPage';
@@ -19,7 +19,7 @@ container.bind<Session>(injectables.Session).toConstantValue(new BrowserSession(
container.bind<IdeaService>(injectables.IdeaService).to(HttpIdeaService);
container.bind<TenantService>(injectables.TenantService).to(HttpTenantService);
-import '@fider/main.scss';
+import '@fider/styles/main.scss';
const pathRegex = [
{ regex: new RegExp('^\/$'), component: <SiteHomePage /> },
diff --git a/public/models/identity.ts b/public/models/identity.ts
index 70c6ce742..e3e81cef0 100644
--- a/public/models/identity.ts
+++ b/public/models/identity.ts
@@ -2,6 +2,8 @@ export interface Tenant {
id: number;
name: string;
domain: string;
+ invitation: string;
+ welcomeMessage: string;
}
export interface User {
diff --git a/public/pages/AdminHomePage.tsx b/public/pages/AdminHomePage.tsx
deleted file mode 100644
index abb9dbe32..000000000
--- a/public/pages/AdminHomePage.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-import * as React from 'react';
-
-import { Header, Footer } from '@fider/components/common';
-
-export class AdminHomePage extends React.Component<{}, {}> {
-
- constructor(props: {}) {
- super(props);
- }
-
- public render() {
- return <div>
- <Header />
- <div className="ui container">
- <h1 className="ui header">Administration</h1>
- <span>You're a Member or Admin!</span>
- </div>
- <Footer />
- </div>;
- }
-}
diff --git a/public/pages/admin/AdminHomePage.tsx b/public/pages/admin/AdminHomePage.tsx
new file mode 100644
index 000000000..35b9a1a35
--- /dev/null
+++ b/public/pages/admin/AdminHomePage.tsx
@@ -0,0 +1,107 @@
+import * as React from 'react';
+
+import { Header, Footer, Button, DisplayError } from '@fider/components/common';
+import { Tenant } from '@fider/models';
+import { inject, injectables } from '@fider/di';
+import { Session, TenantService, Failure } from '@fider/services';
+
+interface AdminHomePageState {
+ title: string;
+ welcomeMessage: string;
+ invitation: string;
+ error?: Failure;
+}
+
+export class AdminHomePage extends React.Component<{}, AdminHomePageState> {
+
+ @inject(injectables.Session)
+ public session: Session;
+
+ @inject(injectables.TenantService)
+ public service: TenantService;
+
+ private tenant: Tenant;
+
+ constructor(props: {}) {
+ super(props);
+ this.tenant = this.session.getCurrentTenant();
+
+ this.state = {
+ title: this.tenant.name,
+ welcomeMessage: this.tenant.welcomeMessage,
+ invitation: this.tenant.invitation
+ };
+ }
+
+ private async confirm() {
+ const result = await this.service.updateSettings(this.state.title, this.state.invitation, this.state.welcomeMessage);
+ if (result.ok) {
+ location.href = `/`;
+ } else if (result.error) {
+ this.setState({ error: result.error });
+ }
+ }
+
+ public render() {
+ return <div>
+ <Header />
+ <div className="ui container">
+ <h1 className="ui header">Administration</h1>
+ <h4 className="ui header">General Settings</h4>
+
+ <div className="ui form">
+ <DisplayError fields={['title']} error={this.state.error} />
+ <div className="six wide field">
+ <label htmlFor="title">Title</label>
+ <input id="title"
+ type="text"
+ placeholder="Title"
+ maxLength={60}
+ disabled={ !this.session.isAdmin() }
+ value={ this.state.title }
+ onChange={(e) => this.setState({ title: e.currentTarget.value })}/>
+ <p className="info">
+ <p>Use this field to change the title that is shown on the top of your page.</p>
+ </p>
+ </div>
+ <DisplayError fields={['welcomeMessage']} error={this.state.error} />
+ <div className="six wide field">
+ <label htmlFor="welcome-message">Welcome Message</label>
+ <textarea id="welcome-message"
+ placeholder="Welcome Message"
+ disabled={ !this.session.isAdmin() }
+ onChange={(e) => this.setState({ welcomeMessage: e.currentTarget.value })}>
+ { this.state.welcomeMessage }
+ </textarea>
+ <p className="info">
+ <p>Use this space to change message of your initial page.</p>
+ <p>Common use cases for this are to briefly explain what is your Company/Product, why you created this space and how the visitors can collaborate.</p>
+ <p>This field is powered by Commonmark, which means you can style and add links to your message. Learn more at <a target="_blank" href="http://commonmark.org/help/">http://commonmark.org/help/</a>.</p>
+ </p>
+ </div>
+ <DisplayError fields={['invitation']} error={this.state.error} />
+ <div className="six wide field">
+ <label htmlFor="invitation">Invitation</label>
+ <input id="invitation"
+ type="text"
+ placeholder="Invitation"
+ maxLength={60}
+ disabled={ !this.session.isAdmin() }
+ value={ this.state.invitation }
+ onChange={(e) => this.setState({ invitation: e.currentTarget.value })}/>
+ <p className="info">
+ <p>This is your customized message to invite visitors to share their ideas and suggestions.</p>
+ </p>
+ </div>
+ {
+ this.session.isAdmin() &&
+ <div className="six wide field">
+ <Button className="positive" size="tiny" onClick={async () => await this.confirm()}>Confirm</Button>
+ </div>
+ }
+ </div>
+ </div>
+ <Footer />
+ </div>;
+ }
+}
diff --git a/public/pages/home/IdeaInput.tsx b/public/pages/home/IdeaInput.tsx
index 75a008a2a..d0fb7c14c 100644
--- a/public/pages/home/IdeaInput.tsx
+++ b/public/pages/home/IdeaInput.tsx
@@ -4,12 +4,16 @@ import { DisplayError, Button, Form, SocialSignInList } from '@fider/components/
import { inject, injectables } from '@fider/di';
import { Session, IdeaService, Failure } from '@fider/services';
+interface IdeaInputProps {
+ placeholder: string;
+}
+
interface IdeaInputState {
title: string;
focused: boolean;
}
-export class IdeaInput extends React.Component<{}, IdeaInputState> {
+export class IdeaInput extends React.Component<IdeaInputProps, IdeaInputState> {
private title: HTMLInputElement;
private description: HTMLTextAreaElement;
private form: Form;
@@ -86,7 +90,7 @@ export class IdeaInput extends React.Component<{}, IdeaInputState> {
ref={(e) => this.title = e! }
maxLength={100}
onKeyUp={(e) => { this.setState({ title: e.currentTarget.value }); }}
- placeholder="Tell us your ideas" />
+ placeholder={this.props.placeholder} />
{ (this.session.getCurrentUser() || this.state.title) && details }
</Form>;
}
diff --git a/public/pages/home/SiteHomePage.scss b/public/pages/home/SiteHomePage.scss
index 8a5c29db5..6e9152923 100644
--- a/public/pages/home/SiteHomePage.scss
+++ b/public/pages/home/SiteHomePage.scss
@@ -1,8 +1,9 @@
-@import '~@fider/variables.scss';
+@import '~@fider/styles/variables.scss';
.SiteHomePage {
- h1.ui.header:first-child {
- margin: 30px 0px;
+
+ .welcome-message {
+ margin-bottom: 20px;
}
.fdr-idea-list {
diff --git a/public/pages/home/SiteHomePage.tsx b/public/pages/home/SiteHomePage.tsx
index 61f764ba5..8f1cf0e66 100644
--- a/public/pages/home/SiteHomePage.tsx
+++ b/public/pages/home/SiteHomePage.tsx
@@ -1,5 +1,5 @@
import * as React from 'react';
-import { Idea, IdeaStatus, User } from '@fider/models';
+import { Idea, IdeaStatus, User, Tenant } from '@fider/models';
import { Gravatar, MultiLineText, Moment, Header, Footer } from '@fider/components/common';
import { ShowIdeaResponse } from '@fider/components/ShowIdeaResponse';
import { SupportCounter } from '@fider/components/SupportCounter';
@@ -17,6 +17,7 @@ interface SiteHomePageState {
export class SiteHomePage extends React.Component<{}, SiteHomePageState> {
private user: User;
+ private tenant: Tenant;
private allIdeas: Idea[];
private filter: HTMLDivElement;
@@ -26,6 +27,7 @@ export class SiteHomePage extends React.Component<{}, SiteHomePageState> {
constructor(props: {}) {
super(props);
this.user = this.session.getCurrentUser();
+ this.tenant = this.session.getCurrentTenant();
this.allIdeas = this.session.get<Idea[]>('ideas') || [];
this.state = {
@@ -56,15 +58,19 @@ export class SiteHomePage extends React.Component<{}, SiteHomePageState> {
</div>
: <p>No ideas found for given filter.</p>;
+ const welcomeMessage = this.tenant.welcomeMessage ||
+ `## Welcome to our feedback forum!
+
+We'd love to hear what you're thinking about. This is the place for you to submit your feedback.`;
+
return <div className="SiteHomePage">
<Header />
<div className="ui container">
- <h1 className="ui header">Welcome to our feedback forum!</h1>
<div className="ui grid stackable">
<div className="six wide column">
- <p>We'd love to hear what you're thinking about. This is the place for you to submit your feedback.</p>
- <IdeaInput />
+ <MultiLineText className="welcome-message" text={ welcomeMessage } markdown={true} />
+ <IdeaInput placeholder={this.tenant.invitation || 'Tell us your ideas'} />
</div>
<div className="ten wide column">
{
diff --git a/public/pages/signup/SignUpPage.tsx b/public/pages/signup/SignUpPage.tsx
index 8152be75f..a27bce77f 100644
--- a/public/pages/signup/SignUpPage.tsx
+++ b/public/pages/signup/SignUpPage.tsx
@@ -114,7 +114,7 @@ export class SignUpPage extends React.Component<{}, SignUpPageState> {
}
<div className="ui section divider"></div>
- <h3 className="ui header">2. Company/Product details</h3>
+ <h3 className="ui header">2. Your Company/Product</h3>
<DisplayError fields={['name', 'subdomain']} error={this.state.error} />
<div className="ui form">
<div className="inline field">
diff --git a/public/services/Session.ts b/public/services/Session.ts
index 992743f59..b0c26bd88 100644
--- a/public/services/Session.ts
+++ b/public/services/Session.ts
@@ -1,9 +1,11 @@
-import { User, AppSettings } from '@fider/models';
+import { User, AppSettings, Tenant } from '@fider/models';
import { injectable } from '@fider/di';
export interface Session {
getCurrentUser(): User;
+ getCurrentTenant(): Tenant;
setUser(user: User): void;
+ isAdmin(): boolean;
isStaff(): boolean;
set<T>(key: string, value: T): void;
get<T>(key: string): T;
@@ -30,10 +32,20 @@ export class BrowserSession implements Session {
return w[`_user`] as User;
}
+ public getCurrentTenant(): Tenant {
+ const w: any = window;
+ return w[`_tenant`] as Tenant;
+ }
+
public setUser(user: User): void {
this.set<User>('user', user);
}
+ public isAdmin(): boolean {
+ const user = this.getCurrentUser();
+ return user && user.role === 3;
+ }
+
public isStaff(): boolean {
const user = this.getCurrentUser();
return user && user.role >= 2;
diff --git a/public/services/TenantService.ts b/public/services/TenantService.ts
index 5cf6e12d9..2cc1b5018 100644
--- a/public/services/TenantService.ts
+++ b/public/services/TenantService.ts
@@ -4,6 +4,7 @@ import { Tenant } from '@fider/models';
export interface TenantService {
create(token?: string, name?: string, subdomain?: string): Promise<Result>;
+ updateSettings(title: string, invitation: string, welcomeMessage: string): Promise<Result>;
checkAvailability(subdomain: string): Promise<Result<CheckAvailabilityResponse>>;
}
@@ -19,6 +20,12 @@ export class HttpTenantService implements TenantService {
});
}
+ public async updateSettings(title: string, invitation: string, welcomeMessage: string): Promise<Result> {
+ return await post('/api/settings', {
+ title, invitation, welcomeMessage,
+ });
+ }
+
public async checkAvailability(subdomain: string): Promise<Result<CheckAvailabilityResponse>> {
return await get<CheckAvailabilityResponse>(`/api/tenants/${subdomain}/availability`);
}
diff --git a/public/styles/form.scss b/public/styles/form.scss
new file mode 100644
index 000000000..d0caba2ae
--- /dev/null
+++ b/public/styles/form.scss
@@ -0,0 +1,7 @@
+.field {
+ .info {
+ font-size: 90%;
+ color: rgba(0,0,0,.6);
+ padding: 5px 0px 0px 5px;
+ }
+}
\ No newline at end of file
diff --git a/public/main.scss b/public/styles/main.scss
similarity index 96%
rename from public/main.scss
rename to public/styles/main.scss
index d275f053a..260f63efa 100644
--- a/public/main.scss
+++ b/public/styles/main.scss
@@ -1,4 +1,5 @@
-@import '~@fider/variables.scss';
+@import 'variables.scss';
+@import 'form.scss';
.idea-header {
margin-left: 20px;
@@ -15,6 +16,7 @@ body {
#menu {
margin-top: 0px;
background-color: $violet;
+ margin-bottom: 30px;
div, a {
border: none;
color: #fff;
@@ -38,6 +40,14 @@ code {
}
}
+.no-border {
+ border-radius: 0px !important;
+}
+
+.no-margin {
+ margin: 0px !important;
+}
+
.support-counter {
width: 130px;
@@ -55,14 +65,6 @@ code {
}
}
-.no-border {
- border-radius: 0px !important;
-}
-
-.no-margin {
- margin: 0px !important;
-}
-
.fdr-profile-popup div.item {
padding: 10px 5px !important;
}
diff --git a/public/variables.scss b/public/styles/variables.scss
similarity index 100%
rename from public/variables.scss
rename to public/styles/variables.scss
diff --git a/router.go b/router.go
index dd465cd79..24f19dd81 100644
--- a/router.go
+++ b/router.go
@@ -83,6 +83,10 @@ func GetMainEngine(settings *models.AppSettings) *web.Engine {
private.Post("/api/ideas/:number/status", handlers.SetResponse())
private.Post("/api/ideas/:number/support", handlers.AddSupporter())
private.Post("/api/ideas/:number/unsupport", handlers.RemoveSupporter())
+
+ private.Use(middlewares.IsAuthorized(models.RoleMember, models.RoleAdministrator))
+
+ private.Post("/api/settings", handlers.UpdateSettings())
}
admin := page.Group("/admin")