Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/api/route/thread_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class ThreadApi < Base
optional :end_date, types: [DateTime, Date], desc: 'Only threads after or at the end date or time are returned'
optional :start_date, types: [DateTime, Date], desc: 'Only threads before or at the start date or time are returned'
optional :after_id, types: Integer, desc: 'Only threads with ID greather than this are returned'
optional :external_service, type: String, desc: 'Filter by external service short name'
end

helpers do
Expand All @@ -27,6 +28,7 @@ def post_or_get_thread
scope = scope.before_date(params[:end_date]) if params[:end_date]
scope = scope.after_date(params[:start_date]) if params[:start_date]
scope = scope.after_id(params[:after_id]) if params[:after_id]
scope = scope.joins(:external_service).where('external_services.short_name' => params[:external_service]) if params[:external_service]
scope = paginate scope
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/content.scss
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@
.meta {
float:left;
}
.permissions {
.thread-parameters {
float:right;
}
}
Expand Down
4 changes: 2 additions & 2 deletions app/assets/stylesheets/shared_elements.scss
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ ul.thread-list {
padding-left:42px;
background: image-url("map-icons/m-roadworks.png") 0 20px no-repeat;
}
.permissions {
.thread-parameters {
float:right;
}
}
Expand All @@ -278,7 +278,7 @@ ul.thread-list {
}
}

.permissions {
.thread-parameters {
width: 80px;
color: $lightgrey;
text: {
Expand Down
44 changes: 44 additions & 0 deletions app/controllers/admin/external_services_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
class Admin::ExternalServicesController < ApplicationController
def index
@external_services = ExternalService.all
end

def new
@external_service = ExternalService.new
end

def create
@external_service = ExternalService.new(permitted_params)
puts @external_service
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove this after merging.


if @external_service.save
set_flash_message(:success)
redirect_to action: :index
else
render :new
end
end

def edit
external_service
end

def update
if external_service.update permitted_params
set_flash_message :success
redirect_to action: :index
else
render :edit
end
end

protected

def permitted_params
params.require(:external_service).permit :name, :short_name
end

def external_service
@external_service ||= ExternalService.find params[:id]
end
end
18 changes: 18 additions & 0 deletions app/controllers/issue/message_threads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,24 @@ def new
@message = @thread.messages.build
@message.body = issue.description if issue.threads.count == 0
@available_groups = current_user.groups
@external_services = ExternalService.all
end

helper_method :new_external

def new_external
@thread = issue.threads.build
set_page_title nil, issue: issue.title
if current_group
@thread.group = current_group
@thread.privacy = current_group.default_thread_privacy
end
@message = @thread.messages.build
@message.body = issue.description
@thread.title = issue.title
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about setting the thread title equal to the issue title.
I think it should be:
Issue: New housing will be built
Thread: Increased congestion on the road
Thread: Cycle Parking on the New housing application is poor

etc.

See #43 for context.

@thread.privacy = "public"
@available_groups = current_user.groups
@external_services = ExternalService.all
end

def create
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/message_threads_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def thread
end

def permitted_params
params.require(:thread).permit :title, :privacy, :group_id, :issue_id, :tags_string
params.require(:thread).permit :title, :privacy, :group_id, :issue_id, :tags_string, :external_service_id
end

def permitted_message_params
Expand Down
27 changes: 27 additions & 0 deletions app/models/external_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# == Schema Information
#
# Table name: external_services
#
# id :integer not null, primary key
# name :string(255) not null
# short_name :string(255) not null
#
# Indexes
#
# index_external_services_on_short_name (short_name)
#

class ExternalService < ActiveRecord::Base
has_many :threads, class_name: 'MessageThread', inverse_of: :external_service

validates :name, presence: true, uniqueness: true
validates :short_name, presence: true, uniqueness: true, subdomain: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this? As in what is the difference between the name and short name? Why not just use the name?


normalize_attributes :short_name, with: [:strip, :blank, :downcase]

def to_param
"#{id}-#{short_name}"
end

protected
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason this is here?

end
2 changes: 2 additions & 0 deletions app/models/message_thread.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class MessageThread < ActiveRecord::Base
belongs_to :group, inverse_of: :threads, counter_cache: true
belongs_to :issue, inverse_of: :threads
belongs_to :user, inverse_of: :private_threads
belongs_to :external_service, inverse_of: :threads
has_many :messages, -> { order(created_at: :asc) }, foreign_key: 'thread_id', autosave: true, inverse_of: :thread
has_many :subscriptions, -> { where(deleted_at: nil) }, class_name: 'ThreadSubscription', foreign_key: 'thread_id', inverse_of: :thread
has_many :subscribers, through: :subscriptions, source: :user
Expand Down Expand Up @@ -327,6 +328,7 @@ def as_json(_options = nil)
group_id: group_id,
title: title,
public_token: public_token,
external_service: external_service ? external_service.short_name : nil,
created_at: created_at,
updated_at: updated_at,
closed: closed,
Expand Down
7 changes: 7 additions & 0 deletions app/views/admin/external_services/_form.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
= semantic_form_for @external_service, url: [:admin, @external_service] do |f|
= f.inputs do
= f.input :name, input_html: { size: 30 }
= f.input :short_name, input_html: { size: 30 }
= f.actions do
= f.action :submit, button_html: {class: "btn-green submit"}
= cancel_link
5 changes: 5 additions & 0 deletions app/views/admin/external_services/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%header
%h1
= t ".edit_external_service"
%section
= render "form"
15 changes: 15 additions & 0 deletions app/views/admin/external_services/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
%header
%h1= t ".title"
%section
.tasks
%p= link_to t(".new_external_service"), new_admin_external_service_path
%table
%thead
%th= t ".name"
%th= t ".short_name"
%tbody
- @external_services.each do |external_service|
%tr
%td= external_service.name
%td= external_service.short_name
%td= link_to t(".edit"), [:edit, :admin, external_service]
5 changes: 5 additions & 0 deletions app/views/admin/external_services/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
%header
%h1= t ".title"
%p= t ".introduction"
%section
= render "form"
1 change: 1 addition & 0 deletions app/views/admin/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
%li= link_to t(".manage_users"), admin_users_path
%li= link_to t(".manage_comments"), site_comments_path
%li= link_to t(".manage_message_moderations"), admin_message_moderations_path
%li= link_to t(".manage_external_services"), admin_external_services_path
%li= link_to t(".manage_site_config"), admin_site_config_path
%li= link_to t(".stats"), admin_stats_path
%li= link_to t(".resque"), resque_server_path
Expand Down
12 changes: 9 additions & 3 deletions app/views/home/issue_template.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,29 @@
<p><a href="/">Cambridge Cycling Campaign</a> 5 days ago</p>
</div>

<div class="permissions">private</div>
<div class="thread-parameters">
<div class="permissions">private</div>
</div>
</li>
<li>
<h4><a href="/">Planning office discussions</a></h4>

<div class="meta">
<p><a href="/">Placeford Cycles</a> 5 days ago</p>
</div>
<div class="permissions">private</div>
<div class="thread-parameters">
<div class="permissions">private</div>
</div>
</li>
<li>
<h4><a href="/">Planning office discussions</a></h4>

<div class="meta">
<p><a href="/">Cambridge Cycling Campaign</a> 5 days ago</p>
</div>
<div class="permissions">shared</div>
<div class="thread-parameters">
<div class="permissions">shared</div>
</div>
</li>
</ul>
</section>
Expand Down
12 changes: 9 additions & 3 deletions app/views/home/user_profile_template.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,9 @@
</ul>
</div>
</div>
<div class="permissions">private</div>
<div class="thread-parameters">
<div class="permissions">private</div>
</div>
</li>
<li>
<div class="message-count"><span>21</span>replies</div>
Expand All @@ -63,7 +65,9 @@
</ul>
</div>
</div>
<div class="permissions">private</div>
<div class="thread-parameters">
<div class="permissions">private</div>
</div>
</li>
<li>
<div class="message-count"><span>13</span>replies</div>
Expand All @@ -79,7 +83,9 @@
</ul>
</div>
</div>
<div class="permissions">shared</div>
<div class="thread-parameters">
<div class="permissions">shared</div>
</div>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this whole code is left over from the initial design (i.e. it isn't used live). @mvl22 was there a reason the original designs were kept as part of this repository? Can we delete it? They will exists in git if we do ever need to refer to them.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was there a reason the original designs were kept as part of this repository

Because the design has never actually been fully implemented yet! That said, I am trying to get round to commissioning a fresh new design that mops up piles of usability issues.

</li>
</ul>
</div>
Expand Down
25 changes: 25 additions & 0 deletions app/views/issue/message_threads/new_external.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
%section.new-thread
%h2= t ".title", issue: @issue.title.truncate(50)
- if @issue.threads.count == 0
%div.meta
%p
%i= simple_format t ".new_hint"
= semantic_form_for @thread, as: :thread, url: {action: :create}, html: {class: 'guided'} do |f|
= f.semantic_errors
= f.inputs do
= f.input :title
- if @available_groups.present?
= f.input :group,
collection: @available_groups.map {|g| [g.name, g.id, "data-privacy" => g.default_thread_privacy, "data-privacy-options" => Hash[g.thread_privacy_options_map_for(current_user).map { |n,v| [v, n]}].to_json] },
include_blank: false
- if @external_services.present?
= f.input :external_service,
as: :select,
collection: @external_services.map {|g| [g.name, g.id] },
include_blank: false
= semantic_fields_for @message do |f2|
= f2.semantic_errors
= f2.input :body, input_html: { rows: 10 }
= f.actions do
= f.action :submit, button_html: {class: "btn-green submit", data: { disable_with: t("formtastic.actions.saving") }}
= cancel_link issue_path(@issue)
4 changes: 4 additions & 0 deletions app/views/issues/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
%aside#sidebar.wide
- if permitted_to? :create, :issue_message_threads
= link_to t(".new_thread", count: @issue.threads.count), new_issue_thread_path(@issue), class: "btn-green", rel: "#overlay"
- if current_user and current_user.groups.present?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and is a trick in ruby and doesn't do things sensibly, I'll change to && when I merge

- if ExternalService.all.present?
- if permitted_to? :create, :issue_message_threads
= link_to t(".new_send_thread", count: @issue.threads.count), issue_threads_new_external_path(@issue), class: "btn-green", rel: "#overlay"
%section.social
= tweet_button text: @issue.title, link: issue_url(@issue)
= facebook_like issue_url(@issue)
Expand Down
5 changes: 4 additions & 1 deletion app/views/message_threads/_compact.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
= thread.latest_activity_by.display_name_or_anon
= time_tag_with_title(thread.latest_activity_at) do
- t ".posted_at", time_ago: time_ago_in_words(thread.latest_activity_at)
.permissions= thread_type(thread)
.thread-parameters
- if thread.external_service
.external-service= thread.external_service.name
.permissions= thread_type(thread)
2 changes: 2 additions & 0 deletions app/views/message_threads/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
- unless f.object.private_message?
= f.input :group
= f.input :privacy, as: :select, collection: f.object.class.privacies_map
-if ExternalService.all.present?
= f.input :external_service
= f.input :issue, as: :select, collection: Issue.by_most_recent.map { |iss| ["#{iss.id} - #{iss.title}", iss.id] }
= f.actions do
= f.action :submit, button_html: {class: "btn-green submit", data: { disable_with: t("formtastic.actions.saving") }}
Expand Down
5 changes: 4 additions & 1 deletion app/views/shared/_message_threads_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,7 @@
- t ".posted_at", time_ago: time_ago_in_words(thread.latest_activity_at)
.status
= render 'message_threads/subscribe_button', thread: thread
.permissions= thread_type(thread)
.thread-parameters
- if thread.external_service
.external-service= thread.external_service.name
.permissions= thread_type(thread)
3 changes: 2 additions & 1 deletion config/authorization_rules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
includes :member
has_permission_on :group_members, :group_memberships, :group_membership_requests, :group_profiles, :group_prefs, to: :manage
has_permission_on :admin_groups, to: [:manage, :disable, :enable]
has_permission_on :admin_external_services, to: :manage
has_permission_on :group_requests do
to [:index, :review, :confirm, :reject, :destroy]
end
Expand Down Expand Up @@ -86,7 +87,7 @@
has_permission_on :messages, to: [:new, :create, :vote_up, :vote_clear]
has_permission_on :message_library_notes, to: [:new, :create]
has_permission_on :message_library_documents, to: [:new, :create]
has_permission_on :issue_message_threads, to: [:new, :create]
has_permission_on :issue_message_threads, to: [:new, :new_external, :create]
has_permission_on :group_message_threads do
to [:new, :create]
if_attribute group: is_in { user.groups }
Expand Down
Loading