Skip to content

Commit

Permalink
add inputs and text to group requests
Browse files Browse the repository at this point in the history
  • Loading branch information
nikolai-b committed May 15, 2015
1 parent 2488067 commit a44eccc
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 17 deletions.
17 changes: 11 additions & 6 deletions app/models/group_request.rb
Expand Up @@ -7,8 +7,9 @@ class GroupRequest < ActiveRecord::Base
attr_accessible :email, :name, :short_name, :website, :default_thread_privacy, :message, :rejection_message
validates :user, :name, :short_name, :email, presence: true
validates :name, :short_name, :email, uniqueness: true
validate :name_is_not_taken, :short_name_is_not_taken, :email_is_not_taken
validate :short_name, format: { with: /\A[a-z0-9]+\z/ }
validate :name_is_not_taken, :short_name_is_not_taken, :email_is_not_taken, unless: :confirmed?
validates :short_name, subdomain: true
validates :default_thread_privacy, inclusion: { in: MessageThread::ALLOWED_PRIVACY }

state_machine :status, initial: :pending do
after_transition any => :confirmed do |request, transition|
Expand Down Expand Up @@ -36,10 +37,14 @@ class GroupRequest < ActiveRecord::Base

def create_group
group = Group.create attributes.slice('name', 'short_name', 'website', 'email', 'default_thread_privacy')
membership = group.memberships.new
membership.user = user
membership.role = 'committee'
membership.save
if group.valid?
membership = group.memberships.new
membership.user = user
membership.role = 'committee'
membership.save
else
false
end
end

private
Expand Down
1 change: 1 addition & 0 deletions app/views/group_requests/_form.html.haml
Expand Up @@ -5,5 +5,6 @@
= f.input :website
= f.input :email
= f.input :message
= f.input :default_thread_privacy, as: :select, collection: MessageThread::non_committee_privacies_map, include_blank: false
= f.actions do
= f.action :submit, button_html: {class: "btn-green submit", data: { disable_with: t("formtastic.actions.saving") }}
2 changes: 0 additions & 2 deletions app/views/group_requests/index.html.haml
Expand Up @@ -10,7 +10,6 @@
%th= t ".user"
%th= t ".name"
%th= t ".group_email"
%th= t ".message"
%th= t ".requested_at"
%th= t ".status"
%th{colspan: 3}= t ".actions"
Expand All @@ -20,7 +19,6 @@
%td= link_to_profile(r.user)
%td= link_to r.name, r
%td= auto_link r.email
%td= link_to t(".view_message"), review_group_request_path(r) unless r.message.blank?
%td
= time_tag_with_title(r.created_at) do
- t ".created_at", time_ago: time_ago_in_words(r.created_at)
Expand Down
4 changes: 3 additions & 1 deletion app/views/groups/index.html.haml
@@ -1,6 +1,8 @@
%section.groups.content-no-sidebar#content
%header#group-list-header
%h1= t ".title"
.tasks
= link_to t(".group_request"), new_group_request_path, class: "btn-green", style: 'float: right'
#group-list-tabs
%ul.tabs.styled-tabs
%li= link_to t(".list_tab"), "#", class: "list"
Expand All @@ -15,4 +17,4 @@
= will_paginate @groups
.pane
= render "all_map"
%p= t ".new_group_instructions_html", feedback_link: link_to(t(".send_some_feedback"), new_site_comment_path)
%p= t ".new_group_instructions_html", feedback_link: link_to(t(".send_some_feedback"), new_site_comment_path)
1 change: 0 additions & 1 deletion app/views/shared/_profile_menu.html.haml
Expand Up @@ -5,4 +5,3 @@
%li= link_to t(".update_account"), edit_user_registration_path, class: "btn-grey"
%li= link_to t(".my_locations"), user_locations_path, class: "btn-grey"
%li= link_to t(".edit_preferences"), edit_user_prefs_path(current_user), class: "btn-grey"
%li= link_to t('.group_request'), new_group_request_path, title: t('.group_request_tooltip'), class: "btn-grey"
6 changes: 3 additions & 3 deletions config/locales/en-GB.yml
Expand Up @@ -365,6 +365,7 @@
new_group_instructions_html: "To create a group on Cyclescape for your local cycling campaign please %{feedback_link} and we'll get back in touch with you soon."
send_some_feedback: "send some feedback"
title: "Groups directory"
group_request: Request New Group
compact:
already_member: "You are already a member of this group"
no_location: "This group doesn't have a location yet."
Expand Down Expand Up @@ -394,7 +395,7 @@
create:
requested: You have requested a new campaigning group, you will be notifed when it is created
new:
new_group_request_introduction: We moderate requests for new groups.
new_group_request_introduction: We moderate requests for new groups. You will be set as the first Committee member of the group, enabling you to administer it.
index: &group_requests_index
<<: *group_membership_requests_index
name: Requested Name
Expand All @@ -403,6 +404,7 @@
new_group: Create a New Group
group_email: Email
destroy: Remove request
no_message: There was no message included with this group request.
review:
<<: *group_requests_index
short_name: Short name
Expand Down Expand Up @@ -856,8 +858,6 @@
edit_preferences: "Manage My Preferences"
my_locations: "My Locations"
update_account: "Update My Account Details"
group_request_tooltip: Request the creation of a new campaigning group
group_request: Request New Group
tags:
panel:
edit_tags: "Edit tags"
Expand Down
6 changes: 5 additions & 1 deletion config/locales/forms.en-GB.yml
Expand Up @@ -21,6 +21,11 @@
group:
name: "Name of the group"
short_name: "Subdomain"
group_request:
name: Name of the group
short_name: Subdomain (at .cyclescape.org)
website: Your organisation's main website
email: Your organisation's main e-mail address
group_membership:
role: "Membership type"
group_pref:
Expand Down Expand Up @@ -77,7 +82,6 @@
short_name: "Must be lower-case alphanumeric; a-z, 0-9"
group_request:
short_name: "Must be lower-case alphanumeric; a-z, 0-9"
email: A public email address for the group
message: A short message to explain the group (helps us stop spam requests)
group_membership:
email: "Please enter their email. If this matches an existing Cyclescape account they will be added to the group immediately. Otherwise an invitation to join Cyclescape will be sent to this address."
Expand Down
14 changes: 11 additions & 3 deletions spec/models/group_request_spec.rb
Expand Up @@ -3,10 +3,9 @@
describe GroupRequest do
let(:user) { FactoryGirl.create(:user) }
let(:group) { FactoryGirl.create(:group) }
let(:boss) { FactoryGirl.create(:user) }

describe 'newly created' do
subject { described_class.new }

it 'must have a user' do
expect(subject).to have(1).error_on(:user)
subject.user = user
Expand All @@ -20,6 +19,10 @@
it 'has an optional message' do
expect(subject).to have(0).error_on(:message)
end

it { is_expected.to allow_value('public').for(:default_thread_privacy) }
it { is_expected.to allow_value('group').for(:default_thread_privacy) }
it { is_expected.not_to allow_value('other').for(:default_thread_privacy) }
end

describe 'must not conflict with existing groups' do
Expand All @@ -39,11 +42,16 @@
subject.email = group.email
expect(subject).to have(1).error_on(:email)
end

it 'except when confirmed' do
subject.actioned_by = boss
subject.confirm!
expect(subject).to be_valid
end
end

context 'pending request' do
subject { FactoryGirl.create(:group_request) }
let(:boss) { FactoryGirl.create(:user) }

it 'can be cancelled' do
subject.cancel
Expand Down

0 comments on commit a44eccc

Please sign in to comment.