mirror of
https://github.com/astuto/astuto.git
synced 2025-12-15 03:07:52 +01:00
Add some welcome entities on tenant signup (#266)
This commit is contained in:
committed by
GitHub
parent
d80f63f27f
commit
30b7b0f5f4
@@ -85,7 +85,7 @@
|
||||
.mb-3,
|
||||
.p-3;
|
||||
|
||||
height: 140px;
|
||||
min-height: 140px;
|
||||
color: var(--astuto-black);
|
||||
|
||||
@include media-breakpoint-down(sm) {
|
||||
@@ -104,14 +104,16 @@
|
||||
|
||||
.postTitle {
|
||||
@extend
|
||||
.font-weight-bold;
|
||||
.font-weight-bold,
|
||||
.mb-2;
|
||||
}
|
||||
|
||||
.postDetails {
|
||||
@extend
|
||||
.d-flex,
|
||||
.justify-content-start,
|
||||
.text-uppercase;
|
||||
.text-uppercase,
|
||||
.mt-2;
|
||||
|
||||
.badge {
|
||||
@extend .mr-2;
|
||||
|
||||
@@ -40,14 +40,14 @@ class OAuthsController < ApplicationController
|
||||
Current.tenant = Tenant.find_by(subdomain: tenant_domain)
|
||||
end
|
||||
|
||||
user_profile = OAuthExchangeAuthCodeForProfile.new(
|
||||
user_profile = OAuthExchangeAuthCodeForProfileWorkflow.new(
|
||||
authorization_code: params[:code],
|
||||
o_auth: @o_auth
|
||||
).run
|
||||
|
||||
if reason == 'login'
|
||||
|
||||
user = OAuthSignInUser.new(
|
||||
user = OAuthSignInUserWorkflow.new(
|
||||
user_profile: user_profile,
|
||||
o_auth: @o_auth
|
||||
).run
|
||||
|
||||
@@ -45,6 +45,8 @@ class TenantsController < ApplicationController
|
||||
|
||||
@user.save!
|
||||
|
||||
CreateWelcomeEntitiesWorkflow.new().run
|
||||
|
||||
render json: @tenant, status: :created
|
||||
|
||||
rescue ActiveRecord::RecordInvalid => exception
|
||||
|
||||
@@ -26,6 +26,7 @@ const NewPostForm = ({
|
||||
type="text"
|
||||
value={title}
|
||||
onChange={e => handleTitleChange(e.target.value)}
|
||||
maxLength={128}
|
||||
|
||||
id="postTitle"
|
||||
className="form-control"
|
||||
|
||||
@@ -11,7 +11,7 @@ class Post < ApplicationRecord
|
||||
has_many :comments, dependent: :destroy
|
||||
has_many :post_status_changes, dependent: :destroy
|
||||
|
||||
validates :title, presence: true, length: { in: 4..64 }
|
||||
validates :title, presence: true, length: { in: 4..128 }
|
||||
|
||||
paginates_per Rails.application.posts_per_page
|
||||
|
||||
|
||||
71
app/workflows/create_welcome_entities_workflow.rb
Normal file
71
app/workflows/create_welcome_entities_workflow.rb
Normal file
@@ -0,0 +1,71 @@
|
||||
class CreateWelcomeEntitiesWorkflow
|
||||
def run
|
||||
tenant = Current.tenant_or_raise! # check that Current Tenant is set
|
||||
owner = tenant.users.first
|
||||
|
||||
# Create some Boards
|
||||
feature_board = Board.create!(
|
||||
name: 'Feature Requests',
|
||||
description: 'This is a **board**! You can create as many as you want from **site settings** and their description can be *Markdown formatted*.',
|
||||
order: 0
|
||||
)
|
||||
bug_board = Board.create!(
|
||||
name: 'Bug Reports',
|
||||
description: 'Tell us everything about problems you encountered in our services!',
|
||||
order: 1
|
||||
)
|
||||
|
||||
# Create some Post Statuses
|
||||
planned_post_status = PostStatus.create!(
|
||||
name: 'Planned',
|
||||
color: '#0096ff',
|
||||
order: 0,
|
||||
show_in_roadmap: true
|
||||
)
|
||||
in_progress_post_status = PostStatus.create!(
|
||||
name: 'In Progress',
|
||||
color: '#9437ff',
|
||||
order: 1,
|
||||
show_in_roadmap: true
|
||||
)
|
||||
completed_post_status = PostStatus.create!(
|
||||
name: 'Completed',
|
||||
color: '#6ac47c',
|
||||
order: 2,
|
||||
show_in_roadmap: true
|
||||
)
|
||||
rejected_post_status = PostStatus.create!(
|
||||
name: 'Rejected',
|
||||
color: '#ff2600',
|
||||
order: 3,
|
||||
show_in_roadmap: false
|
||||
)
|
||||
|
||||
# Create some Posts
|
||||
post1 = Post.create!(
|
||||
title: "Welcome #{owner.full_name}! This is an example feedback post, click to learn more!",
|
||||
description: 'Users can submit feedback by publishing posts like this. You can assign a **status** to each post: this one, for example, is marked as "Planned". Remember that you can customise post statuses from Site settings > Statuses',
|
||||
board_id: feature_board.id,
|
||||
user_id: owner.id,
|
||||
post_status_id: planned_post_status.id
|
||||
)
|
||||
PostStatusChange.create!(
|
||||
post_id: post1.id,
|
||||
user_id: owner.id,
|
||||
post_status_id: planned_post_status.id
|
||||
)
|
||||
|
||||
post2 = Post.create!(
|
||||
title: 'There are multiple boards',
|
||||
description: 'For now you have Feature Requests and Bug Reports, but you can add or remove as many as you want! Just go to Site settings > Boards!',
|
||||
board_id: bug_board.id,
|
||||
user_id: owner.id
|
||||
)
|
||||
|
||||
# Create some comments
|
||||
post1.comments.create!(
|
||||
body: 'Users can comment to express their opinions! As with posts and board descriptions, comments can be *Markdown* **formatted**',
|
||||
user_id: owner.id
|
||||
)
|
||||
end
|
||||
end
|
||||
@@ -1,4 +1,4 @@
|
||||
class OAuthExchangeAuthCodeForProfile
|
||||
class OAuthExchangeAuthCodeForProfileWorkflow
|
||||
include HTTParty
|
||||
|
||||
attr_accessor :authorization_code, :o_auth
|
||||
@@ -1,11 +1,11 @@
|
||||
class OAuthSignInUser
|
||||
class OAuthSignInUserWorkflow
|
||||
include OAuthsHelper
|
||||
|
||||
attr_accessor :user_profile, :o_auth
|
||||
|
||||
# Given:
|
||||
# user_profile: ruby Hash containing information about the user
|
||||
# Could've been returned from OAuthExchangeAuthCodeForProfile
|
||||
# Could've been returned from OAuthExchangeAuthCodeForProfileWorkflow
|
||||
# o_auth: ActiveRecord model with information about the OAuth provider
|
||||
#
|
||||
# The workfow creates a new user if it doesn't exist, or select the existing one
|
||||
67
db/seeds.rb
67
db/seeds.rb
@@ -1,6 +1,6 @@
|
||||
# Create tenant
|
||||
tenant = Tenant.create(
|
||||
site_name: 'Default site name',
|
||||
site_name: 'Default Site Name',
|
||||
subdomain: 'default',
|
||||
status: 'active'
|
||||
)
|
||||
@@ -15,70 +15,7 @@ owner = User.create(
|
||||
confirmed_at: Time.zone.now
|
||||
)
|
||||
|
||||
# Create some boards
|
||||
feature_board = Board.create(
|
||||
name: 'Feature Requests',
|
||||
description: 'This is a **board**! You can create as many as you want from **site settings** and their description can be *Markdown formatted*.',
|
||||
order: 0
|
||||
)
|
||||
bug_board = Board.create(
|
||||
name: 'Bug Reports',
|
||||
description: 'Tell us everything about problems you encountered in our services!',
|
||||
order: 1
|
||||
)
|
||||
|
||||
# Create some post statuses
|
||||
planned_post_status = PostStatus.create(
|
||||
name: 'Planned',
|
||||
color: '#0096ff',
|
||||
order: 0,
|
||||
show_in_roadmap: true
|
||||
)
|
||||
in_progress_post_status = PostStatus.create(
|
||||
name: 'In Progress',
|
||||
color: '#9437ff',
|
||||
order: 1,
|
||||
show_in_roadmap: true
|
||||
)
|
||||
completed_post_status = PostStatus.create(
|
||||
name: 'Completed',
|
||||
color: '#6ac47c',
|
||||
order: 2,
|
||||
show_in_roadmap: true
|
||||
)
|
||||
rejected_post_status = PostStatus.create(
|
||||
name: 'Rejected',
|
||||
color: '#ff2600',
|
||||
order: 3,
|
||||
show_in_roadmap: false
|
||||
)
|
||||
|
||||
# Create some posts
|
||||
post1 = Post.create(
|
||||
title: 'Users can submit feedback by publishing posts!',
|
||||
description: 'You can assign a **status** to each post: this one, for example, is marked as "Planned". Remember that you can customise post statuses from Site settings > Statuses',
|
||||
board_id: feature_board.id,
|
||||
user_id: owner.id,
|
||||
post_status_id: planned_post_status.id
|
||||
)
|
||||
PostStatusChange.create(
|
||||
post_id: post1.id,
|
||||
user_id: owner.id,
|
||||
post_status_id: planned_post_status.id
|
||||
)
|
||||
|
||||
post2 = Post.create(
|
||||
title: 'There are multiple boards',
|
||||
description: 'For now you have Feature Requests and Bug Reports, but you can add or remove as many as you want! Just go to Site settings > Boards!',
|
||||
board_id: bug_board.id,
|
||||
user_id: owner.id
|
||||
)
|
||||
|
||||
# # Create some comments
|
||||
post1.comments.create(
|
||||
body: 'Users can comment to express their opinions! As with posts and board descriptions, comments can be *Markdown* **formatted**',
|
||||
user_id: owner.id
|
||||
)
|
||||
CreateWelcomeEntitiesWorkflow.new().run
|
||||
|
||||
# Let the user know how to log in with admin account
|
||||
puts "A default tenant has been created with name #{tenant.site_name}"
|
||||
|
||||
@@ -15,11 +15,11 @@ RSpec.describe Post, type: :model do
|
||||
expect(empty_post).to be_invalid
|
||||
end
|
||||
|
||||
it 'has a title between 4 and 64 characters' do
|
||||
it 'has a title between 4 and 128 characters' do
|
||||
too_short_post = FactoryBot.build(:post, title: 'a' * 3)
|
||||
short_post = FactoryBot.build(:post, title: 'a' * 4)
|
||||
long_post = FactoryBot.build(:post, title: 'a' * 64)
|
||||
too_long_post = FactoryBot.build(:post, title: 'a' * 65)
|
||||
long_post = FactoryBot.build(:post, title: 'a' * 128)
|
||||
too_long_post = FactoryBot.build(:post, title: 'a' * 129)
|
||||
|
||||
expect(too_short_post).to be_invalid
|
||||
expect(short_post).to be_valid
|
||||
|
||||
Reference in New Issue
Block a user