Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Pending review] Superadmin UI, creating new communities #393

Merged
merged 3 commits into from
May 2, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ gem 'ts-delayed-delta', "~>2.0.2",
:git => 'git://github.com/pat/ts-delayed-delta.git',
:branch => 'master',
:ref => '839284f2f28b3f4caf3a3bf5ccde9a6d222c7f4d'
gem 'possibly',
:git => 'git://github.com/rap1ds/ruby-possibly',
:branch => 'master',
:ref => '8080a913653a1c0efe566dbf8f8973b6cf0f882c'
gem 'recaptcha'
gem 'delayed_job', "~>3.0.5"
gem 'delayed_job_active_record'
Expand Down
9 changes: 9 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ GIT
delayed_job
thinking-sphinx (>= 1.5.0)

GIT
remote: git://github.com/rap1ds/ruby-possibly
revision: 8080a913653a1c0efe566dbf8f8973b6cf0f882c
ref: 8080a913653a1c0efe566dbf8f8973b6cf0f882c
branch: master
specs:
possibly (0.0.0)

GEM
remote: http://rubygems.org/
specs:
Expand Down Expand Up @@ -475,6 +483,7 @@ DEPENDENCIES
paperclip
parallel_tests
pickle
possibly!
postmark-rails
pry
pry-nav
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,13 @@ def ensure_is_admin
end
end

def ensure_is_superadmin
unless Maybe(@current_user).is_admin?.get_or_else(false)
flash[:error] = t("layouts.notifications.only_kassi_administrators_can_access_this_area")
redirect_to root and return
end
end

# Does a push to Google Analytics on next page load
# the reason to go via session is that the actions that cause events
# often do a redirect.
Expand Down
69 changes: 69 additions & 0 deletions app/controllers/superadmin/communities_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
class Superadmin::CommunitiesController < ApplicationController
before_filter :ensure_is_superadmin
skip_filter :dashboard_only

def new
@new_community = Community.new
end

def create
p = Maybe(params)

defaults = {
consent: "SHARETRIBE1.0",
feedback_to_admin: 1,
logo_change_allowed: 1,
terms_change_allowed: 1,
privacy_policy_change_allowed: 1,
custom_fields_allowed: 1,
category_change_allowed: 1
}

language = p["language"].get_or_else("en")
community_params = defaults.merge(p["community"].merge(settings: {"locales" => [language]}).get)

@community = Community.create(community_params)
if @community.save

transaction_type = create_transaction_type!(p, language, @community)
create_category!(p, language, transaction_type, @community)

link = view_context.link_to "#{@community.domain}.#{APP_CONFIG.domain}", "//#{@community.domain}.#{APP_CONFIG.domain}"
flash[:notice] = "Successfully created new community '#{@community.name}' (#{link})".html_safe

redirect_to :superadmin_communities
else
binding.pry
flash[:error] = "Error: #{@community.errors.messages}"
redirect_to new_superadmin_community_path
end
end

def create_transaction_type!(p, language, community)
transaction_type = p["transaction_type"].get_or_else("Sell").constantize.new()
transaction_type.community = community
transaction_type.save!
community.transaction_types << transaction_type

transaction_type_translation = TransactionTypeTranslation.create({
transaction_type_id: transaction_type.id,
locale: language,
name: t("admin.transaction_types.sell"),
action_button_label: t("admin.transaction_types.default_action_button_labels.sell")
});

transaction_type
end

def create_category!(p, language, transaction_type, community)
category = community.categories.create;

category_translations = CategoryTranslation.create(:category_id => category.id,
:locale => language,
:name => p[:category].get_or_else("Default"));

CategoryTransactionType.create(:category_id => category.id, :transaction_type_id => transaction_type.id)

category
end
end
1 change: 1 addition & 0 deletions app/models/transaction_types/rent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class Rent < Offer

before_validation(:on => :create) do
self.price_field ||= 1
self.price_quantity_placeholder ||= "time"
end

end
1 change: 1 addition & 0 deletions app/views/superadmin/communities/index.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= link_to "Create a new Marketplace", new_superadmin_community_path
32 changes: 32 additions & 0 deletions app/views/superadmin/communities/new.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
- content_for(:title_header) do
%h1="Create a new Marketplace"

.centered-section
= form_for @new_community, url: superadmin_communities_path do |form|
.row
.col-12
= form.label :name, "Name", :class => "input"
= form.text_field :name, :class => "text_field", :placeholder => "Marketplace name"
.row
.col-12
= form.label :domain, "Domain (domain.#{APP_CONFIG.domain})", :class => "input"
= form.text_field :domain, :class => "text_field", :placeholder => "marketplacedomain"
.row
.col-12
= label_tag :language, "Language", :class => "input"
= select_tag :language, options_for_select(Kassi::Application.config.AVAILABLE_LOCALES)
.row
.col-12
= form.label :available_currencies, "Currency", :class => "input"
= form.select :available_currencies, options_for_select(Money::Currency.table.map { |k, v| [k.upcase, v] })
.row
.col-12
= label_tag :transaction_type, "Transaction type", :class => "input"
= select_tag :transaction_type, options_for_select([["Give", "Give"], ["Inquiry", "Inquiry"], ["Lend", "Lend"], ["Rent", "Rent"], ["Sell", "Sell"], ["Service", "Service"], ["Share for free", "ShareForFree"], ["Swap", "Swap"]])
.row
.col-12
= label_tag :category, "Category", :class => "input"
= text_field_tag :category, nil, :class => "text_field", :placeholder => "Category title"
.row
.col-12
= form.button "Create community"
57 changes: 31 additions & 26 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,21 @@
scope "(/:locale)" do
scope :module => "api", :constraints => ApiRequest do
resources :listings, :only => :index

match 'api_version' => "api#version_check"
match '/' => 'dashboard#api'
match '/' => 'dashboard#api'
end
devise_for :people, :controllers => { :confirmations => "confirmations", :registrations => "people", :omniauth_callbacks => "sessions"}, :path_names => { :sign_in => 'login'}
devise_scope :person do

devise_for :people, :controllers => { :confirmations => "confirmations", :registrations => "people", :omniauth_callbacks => "sessions"}, :path_names => { :sign_in => 'login'}
devise_scope :person do
# these matches need to be before the general resources to have more priority
get "/people/confirmation" => "confirmations#show", :as => :confirmation
put "/people/confirmation" => "confirmations#create"
match "/people/password/edit" => "devise/passwords#edit"
post "/people/password" => "devise/passwords#create"
put "/people/password" => "devise/passwords#update"
match "/people/sign_up" => redirect("/%{locale}/login")

resources :people do
collection do
get :check_username_availability
Expand All @@ -59,9 +59,9 @@
resources :listings do
member do
put :close
end
end
resources :messages, :controller => :conversations do
end
end
resources :messages, :controller => :conversations do
collection do
get :received
get :sent
Expand All @@ -79,15 +79,15 @@
resources :feedbacks, :controller => :testimonials do
collection do
put :skip
end
end
end
resources :payments do
member do
get :done
end
end
resources :braintree_payments

end
resource :settings do
member do
Expand All @@ -108,11 +108,16 @@
end
end
end

# List few specific routes here for Devise to understand those
match "/signup" => "people#new", :as => :sign_up
match "/people/:id/:type" => "people#show", :as => :person_listings

match "/signup" => "people#new", :as => :sign_up
match "/people/:id/:type" => "people#show", :as => :person_listings

end

namespace :superadmin do
resources :communities do
end
end

namespace :admin do
Expand Down Expand Up @@ -162,7 +167,7 @@
end
end
end

resources :contact_requests
resources :invitations
resources :user_feedbacks, :controller => :feedbacks
Expand All @@ -174,7 +179,7 @@
end
end
resources :tribes, :controller => :communities do
collection do
collection do
get :check_domain_availability
get :change_form_language
post :set_organization_email
Expand Down Expand Up @@ -224,27 +229,27 @@
get :terms
get :privacy
get :news
end
end
end
resource :terms do
member do
post :accept
end
end
end
end
resources :sessions do
collection do
post :request_new_password
post :change_mistyped_email
end
end
end
resources :consent
resource :sms do
get :message_arrived
end
resources :news_items
resources :statistics
end

# Some non-RESTful mappings

get '/webhooks/braintree' => 'braintree_webhooks#challenge'
Expand Down Expand Up @@ -290,11 +295,11 @@
constraints(CommunityDomain) do
match '/:locale/' => 'homepage#index'
match '/' => 'homepage#index'
end
end

# Below are the routes that are matched if didn't match inside subdomain constraints
match '/:locale' => 'dashboard#index'

root :to => 'dashboard#index'

end