mirror of
https://github.com/astuto/astuto.git
synced 2025-12-16 03:37:56 +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,
|
.mb-3,
|
||||||
.p-3;
|
.p-3;
|
||||||
|
|
||||||
height: 140px;
|
min-height: 140px;
|
||||||
color: var(--astuto-black);
|
color: var(--astuto-black);
|
||||||
|
|
||||||
@include media-breakpoint-down(sm) {
|
@include media-breakpoint-down(sm) {
|
||||||
@@ -104,14 +104,16 @@
|
|||||||
|
|
||||||
.postTitle {
|
.postTitle {
|
||||||
@extend
|
@extend
|
||||||
.font-weight-bold;
|
.font-weight-bold,
|
||||||
|
.mb-2;
|
||||||
}
|
}
|
||||||
|
|
||||||
.postDetails {
|
.postDetails {
|
||||||
@extend
|
@extend
|
||||||
.d-flex,
|
.d-flex,
|
||||||
.justify-content-start,
|
.justify-content-start,
|
||||||
.text-uppercase;
|
.text-uppercase,
|
||||||
|
.mt-2;
|
||||||
|
|
||||||
.badge {
|
.badge {
|
||||||
@extend .mr-2;
|
@extend .mr-2;
|
||||||
|
|||||||
@@ -40,14 +40,14 @@ class OAuthsController < ApplicationController
|
|||||||
Current.tenant = Tenant.find_by(subdomain: tenant_domain)
|
Current.tenant = Tenant.find_by(subdomain: tenant_domain)
|
||||||
end
|
end
|
||||||
|
|
||||||
user_profile = OAuthExchangeAuthCodeForProfile.new(
|
user_profile = OAuthExchangeAuthCodeForProfileWorkflow.new(
|
||||||
authorization_code: params[:code],
|
authorization_code: params[:code],
|
||||||
o_auth: @o_auth
|
o_auth: @o_auth
|
||||||
).run
|
).run
|
||||||
|
|
||||||
if reason == 'login'
|
if reason == 'login'
|
||||||
|
|
||||||
user = OAuthSignInUser.new(
|
user = OAuthSignInUserWorkflow.new(
|
||||||
user_profile: user_profile,
|
user_profile: user_profile,
|
||||||
o_auth: @o_auth
|
o_auth: @o_auth
|
||||||
).run
|
).run
|
||||||
|
|||||||
@@ -45,6 +45,8 @@ class TenantsController < ApplicationController
|
|||||||
|
|
||||||
@user.save!
|
@user.save!
|
||||||
|
|
||||||
|
CreateWelcomeEntitiesWorkflow.new().run
|
||||||
|
|
||||||
render json: @tenant, status: :created
|
render json: @tenant, status: :created
|
||||||
|
|
||||||
rescue ActiveRecord::RecordInvalid => exception
|
rescue ActiveRecord::RecordInvalid => exception
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ const NewPostForm = ({
|
|||||||
type="text"
|
type="text"
|
||||||
value={title}
|
value={title}
|
||||||
onChange={e => handleTitleChange(e.target.value)}
|
onChange={e => handleTitleChange(e.target.value)}
|
||||||
|
maxLength={128}
|
||||||
|
|
||||||
id="postTitle"
|
id="postTitle"
|
||||||
className="form-control"
|
className="form-control"
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ class Post < ApplicationRecord
|
|||||||
has_many :comments, dependent: :destroy
|
has_many :comments, dependent: :destroy
|
||||||
has_many :post_status_changes, 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
|
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
|
include HTTParty
|
||||||
|
|
||||||
attr_accessor :authorization_code, :o_auth
|
attr_accessor :authorization_code, :o_auth
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
class OAuthSignInUser
|
class OAuthSignInUserWorkflow
|
||||||
include OAuthsHelper
|
include OAuthsHelper
|
||||||
|
|
||||||
attr_accessor :user_profile, :o_auth
|
attr_accessor :user_profile, :o_auth
|
||||||
|
|
||||||
# Given:
|
# Given:
|
||||||
# user_profile: ruby Hash containing information about the user
|
# 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
|
# 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
|
# 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
|
# Create tenant
|
||||||
tenant = Tenant.create(
|
tenant = Tenant.create(
|
||||||
site_name: 'Default site name',
|
site_name: 'Default Site Name',
|
||||||
subdomain: 'default',
|
subdomain: 'default',
|
||||||
status: 'active'
|
status: 'active'
|
||||||
)
|
)
|
||||||
@@ -15,70 +15,7 @@ owner = User.create(
|
|||||||
confirmed_at: Time.zone.now
|
confirmed_at: Time.zone.now
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create some boards
|
CreateWelcomeEntitiesWorkflow.new().run
|
||||||
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
|
|
||||||
)
|
|
||||||
|
|
||||||
# Let the user know how to log in with admin account
|
# Let the user know how to log in with admin account
|
||||||
puts "A default tenant has been created with name #{tenant.site_name}"
|
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
|
expect(empty_post).to be_invalid
|
||||||
end
|
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)
|
too_short_post = FactoryBot.build(:post, title: 'a' * 3)
|
||||||
short_post = FactoryBot.build(:post, title: 'a' * 4)
|
short_post = FactoryBot.build(:post, title: 'a' * 4)
|
||||||
long_post = FactoryBot.build(:post, title: 'a' * 64)
|
long_post = FactoryBot.build(:post, title: 'a' * 128)
|
||||||
too_long_post = FactoryBot.build(:post, title: 'a' * 65)
|
too_long_post = FactoryBot.build(:post, title: 'a' * 129)
|
||||||
|
|
||||||
expect(too_short_post).to be_invalid
|
expect(too_short_post).to be_invalid
|
||||||
expect(short_post).to be_valid
|
expect(short_post).to be_valid
|
||||||
|
|||||||
Reference in New Issue
Block a user