Commit 1ed890be3e264906855bcc8889e53d6744ab017d

Refactored Members tab to Team (with new messages and members controllers)

Commit diff

app/controllers/members_controller.rb

 
33 before_filter :find_project
44
55 def index
6 @title, @url_suffix = Project.tab_settings(PRJ_TAB_MEMBERS)
7 @members = Member.find_by_project_alpha(@project.id)
8 if @is_member
9 @messages = Message.find_by_project_user(@project.id, current_user.id, 40)
10 else
11 @messages = Message.find_by_project(@project.id, 40)
12 end
13 render :action => "ac_project_index"
146 end
157
168end
toggle raw diff

app/controllers/projects_controller.rb

 
8989 render :action => "ac_forum"
9090 end
9191
92 def team
93 @title, @url_suffix = Project.tab_settings(PRJ_TAB_TEAM)
94 @members = Member.find_by_project_alpha(@project.id)
95 if @is_member
96 @messages = Message.find_by_project_user(@project.id, current_user.id, 40)
97 else
98 @messages = Message.find_by_project(@project.id, 40)
99 end
100 render :action => "ac_team"
101 end
102
92103 def roadmap
93104 @title, @url_suffix = Project.tab_settings(PRJ_TAB_SUMMARY)
94105 render :action => "ac_roadmap"
toggle raw diff

app/controllers/tickets_controller.rb

 
55 def index
66 @title, @url_suffix = Project.tab_settings(PRJ_TAB_TICKETS)
77 @tickets = Ticket.filtered(params[:ticket] ? params[:ticket] : "")
8 #@assignees = @project.tickets.assignees
89 render :action => "ac_project_index"
910 end
1011
toggle raw diff

app/helpers/application_helper.rb

 
328328 out = %Q{<table class='right_default_table'>}
329329 out << %Q{<tr><th>Actions</th></tr>}
330330 #
331 #FIXME finish this, also it must must only be true if logged_in?
332 logged_in? ? is_member = true : is_member = false
333331 acts = ""
334332 acts << %Q{<li>#{link_to("List Wiki Pages", project_wikis_path(@project.slug))}</li>} if flags[:list_project_wikis]
335 acts << %Q{<li>#{link_to("Edit Wiki Page", edit_project_wiki_path(@project.slug, @wiki.slug))}</li>} if flags[:edit_project_wiki] && is_member
336 acts << %Q{<li>#{link_to("New Wiki Page", new_project_wiki_path(@project.slug))}</li>} if flags[:new_project_wiki] && is_member
337 acts << %Q{<li>#{link_to("Edit Article", edit_project_article_path(@project.slug, @article.slug))}</li>} if flags[:edit_article] && is_member
338 acts << %Q{<li>#{link_to("New Article", new_project_article_path(@project.slug))}</li>} if flags[:new_article] && is_member
333 acts << %Q{<li>#{link_to("Edit Wiki Page", edit_project_wiki_path(@project.slug, @wiki.slug))}</li>} if flags[:edit_project_wiki] && @is_member
334 acts << %Q{<li>#{link_to("New Wiki Page", new_project_wiki_path(@project.slug))}</li>} if flags[:new_project_wiki] && @is_member
335 acts << %Q{<li>#{link_to("Edit Article", edit_project_article_path(@project.slug, @article.slug))}</li>} if flags[:edit_article] && @is_member
336 acts << %Q{<li>#{link_to("New Article", new_project_article_path(@project.slug))}</li>} if flags[:new_article] && @is_member
339337 acts << %Q{<li>#{link_to("New Ticket", new_project_ticket_path(@project.slug))}</li>} if flags[:new_ticket]
340338 acts << %Q{<li>#{link_to("Edit Ticket", edit_project_ticket_path(@project.slug))}</li>} if flags[:edit_ticket]
341339 acts << %Q{<li>#{link_to("Close Ticket", root_path)}</li>} if flags[:close_ticket]
342340 acts << %Q{<li>#{link_to("List Tickets", project_tickets_path(@project.slug))}</li>} if flags[:list_tickets]
343 acts << %Q{<li>#{link_to("New Milestone", new_project_milestone_path(@project.slug))}</li>} if flags[:new_milestone] && is_member
341 acts << %Q{<li>#{link_to("New Milestone", new_project_milestone_path(@project.slug))}</li>} if flags[:new_milestone] && @is_member
344342 acts << %Q{<li>#{link_to("List Active Milestones", root_path)}</li>} if flags[:list_active_milestones]
345343 acts << %Q{<li>#{link_to("List Completed Milestones", root_path)}</li>} if flags[:list_completed_milestones]
346 acts << %Q{<li>#{link_to("Edit Milestones", root_path)}</li>} if flags[:edit_milestones] && is_member
347 acts << %Q{<li>#{link_to("Edit Components", root_path)}</li>} if flags[:edit_components] && is_member
344 acts << %Q{<li>#{link_to("Edit Milestones", root_path)}</li>} if flags[:edit_milestones] && @is_member
345 acts << %Q{<li>#{link_to("Edit Components", root_path)}</li>} if flags[:edit_components] && @is_member
346 acts << %Q{<li>#{link_to("New Member", root_path)}</li>} if flags[:new_member] && @is_member
347 acts << %Q{<li>#{link_to("List Members", root_path)}</li>} if flags[:list_members]
348348 acts << %Q{<li>#{link_to("Clone Mainline", new_project_repository_path(@project.slug, @repository))}</li>} if flags[:clone_mainline] && logged_in?
349349 out << %Q{<tr><td><ul>#{acts}</ul></td></tr>} if acts != ""
350350 out << %Q{<tr><td>#{actionbox_default(flags)}</td></tr>}
toggle raw diff

app/helpers/messages_helper.rb

 
1module MessagesHelper
2end
toggle raw diff

app/helpers/projects_helper.rb

 
6464 out << "<ul id='tabmenu'>"
6565 out << project_tab(active_tab, PRJ_TAB_SUMMARY)
6666 out << project_tab(active_tab, PRJ_TAB_GIT)
67 out << project_tab(active_tab, PRJ_TAB_MEMBERS)
67 out << project_tab(active_tab, PRJ_TAB_TEAM)
6868 out << project_tab(active_tab, PRJ_TAB_TICKETS)
6969 out << project_tab(active_tab, PRJ_TAB_WIKI)
7070 out << project_tab(active_tab, PRJ_TAB_ARTICLES)
120120 when PRJ_TAB_GIT_MERGEREQUESTS
121121 out << actionbox_basic(:allow_shortcuts => true)
122122 end
123 when PRJ_TAB_MEMBERS
124 out << actionbox_basic(:allow_shortcuts => true)
125 out << render(:partial => "ac_right_actionbox_post_message") if @is_member
126 out << render_right_project_members
123 when PRJ_TAB_TEAM
124 case subtab
125 when PRJ_TAB_SUBTAB_NONE
126 out << actionbox_complex(:allow_shortcuts => true, :new_member => true, :list_members => true)
127 out << render(:partial => "messages/ac_right_actionbox_post_message") if @is_member
128 out << render_right_project_members
129 when PRJ_TAB_TEAM_NEW
130 when PRJ_TAB_TEAM_LIST
131 end
127132 when PRJ_TAB_TICKETS
128133 case subtab
129134 when PRJ_TAB_SUBTAB_NONE
toggle raw diff

app/models/article.rb

 
5555
5656 #public version of .count to filter articles you are not authorised to see
5757 def self.public_count (curruser)
58 @projects = Project.list_for_user(curruser)
58 @projects = Project.list_for_user(curruser.id)
5959 #FIXME is there a faster way of doing this?
6060 @articles = find(:all, :conditions => ["status = '#{:published}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"], :order => "created_at DESC")
6161 return @articles.size
6666 #
6767 def self.find_by_date (curruser, year, month = nil, day = nil)
6868 from, to = self.time_delta(year, month, day)
69 @projects = Project.list_for_user(curruser)
69 @projects = Project.list_for_user(curruser.id)
7070 find(:all, :conditions => [ "status = '#{:published}' AND (created_at BETWEEN ? AND ?) AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )", from, to ])
7171 end
7272
7373 #
7474 def self.find_all_articles (curruser)
75 @projects = Project.list_for_user(curruser)
75 @projects = Project.list_for_user(curruser.id)
7676 find(:all, :conditions => ["status = '#{:published}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"], :order => "created_at DESC")
7777 end
7878
7979 #
8080 def self.find_home (curruser)
81 @projects = Project.list_for_user(curruser)
81 @projects = Project.list_for_user(curruser.id)
8282 find(:all, :conditions => ["status = '#{:published}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"], :order => "created_at DESC", :limit => 3)
8383 end
8484
8585 # finds articles for a user based on the user slug e.g. /profiles/test-user/articles
8686 def self.find_by_id (id, curruser)
87 @projects = Project.list_for_user(curruser)
87 @projects = Project.list_for_user(curruser.id)
8888 find(:first, :conditions => ["status = '#{:published}' AND id = '#{id}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"])
8989 end
9090
9595
9696 # finds articles for a user based on the user slug e.g. /profiles/test-user/articles
9797 def self.find_by_user (user_id, curruser)
98 @projects = Project.list_for_user(curruser)
98 @projects = Project.list_for_user(curruser.id)
9999 find(:all, :conditions => ["status = '#{:published}' AND user_id = '#{user_id}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"], :order => "created_at DESC")
100100 end
101101
102102 # finds articles for a user/project based on the user slug e.g. /profiles/test-user/project/project_id/articles
103103 def self.find_by_user_project (user_id, project_id, curruser)
104 @projects = Project.list_for_user(curruser)
104 @projects = Project.list_for_user(curruser.id)
105105 find(:all, :conditions => ["status = '#{:published}' AND user_id = '#{user_id}' AND project_id = '#{project_id}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"], :order => "created_at DESC")
106106 end
107107
108108 #
109109 def self.find_by_permalink (permalink, curruser)
110 @projects = Project.list_for_user(curruser)
110 @projects = Project.list_for_user(curruser.id)
111111 find(:first, :conditions => ["status = '#{:published}' AND permalink = '#{permalink}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"])
112112 end
113113
114114 #
115115 def self.find_by_type (article_type, curruser)
116 @projects = Project.list_for_user(curruser)
116 @projects = Project.list_for_user(curruser.id)
117117 find(:all, :conditions => ["status = '#{:published}' AND article_type = '#{article_type}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"], :order => "created_at DESC")
118118 end
119119
120120 #
121121 def self.find_by_category (category_id, curruser)
122 @projects = Project.list_for_user(curruser)
122 @projects = Project.list_for_user(curruser.id)
123123 find(:all, :conditions => ["status = '#{:published}' AND category_id = '#{category_id}' AND ( audience = '#{:public}' OR project_id IN (" << @projects << ") )"], :order => "created_at DESC")
124124 end
125125
130130
131131 #
132132 def self.find_by_project (project_id, curruser)
133 projects_allowed = Project.list_for_user(curruser)
133 projects_allowed = Project.list_for_user(curruser.id)
134134 find(:all, :conditions => ["status = '#{:published}' AND project_id = '#{project_id}' AND ( audience = '#{:public}' OR project_id IN (" << projects_allowed << ") )"], :order => "created_at DESC")
135135 end
136136
146146
147147 #
148148 def self.find_by_project_and_type (article_type, project_id, curruser)
149 projects_allowed = Project.list_for_user(curruser)
149 projects_allowed = Project.list_for_user(curruser.id)
150150 find(:all, :conditions => ["status = '#{:published}' AND project_id = '#{project_id}' AND article_type = '#{article_type}' AND ( audience = '#{:public}' OR project_id IN (" << projects_allowed << ") )"], :order => "created_at DESC")
151151 end
152152
toggle raw diff

app/models/category.rb

 
1414
1515 #
1616 def self.find_by_all_with_count (curruser)
17 @projects = Project.list_for_user(curruser)
17 @projects = Project.list_for_user(curruser.id)
1818 find_by_sql ["SELECT categories.name, category_type, categories.slug, COUNT(articles.id) AS num_articles FROM categories JOIN articles ON categories.id = articles.category_id WHERE articles.status = '#{:published}' AND (articles.audience = '#{:public}' OR articles.project_id IN (" << @projects << ") ) GROUP BY articles.category_id ORDER BY parent ASC, categories.name"]
1919 end
2020
toggle raw diff

app/models/milestone.rb

 
66 protected
77
88 def self.find_by_project(project_id, curruser)
9 projects_allowed = Project.list_for_user(curruser)
9 projects_allowed = Project.list_for_user(curruser.id)
1010 find(:all, :conditions => ["project_id = '#{project_id}' AND ( audience = '#{:public}' OR project_id IN (" << projects_allowed << ") )"], :order => "created_at DESC")
1111 end
1212
1313 #FIXME maybe expand this to return all tasks so it doesn't need to revisit table so many times
1414 #to display roadmap, except it's now also used by the project summary tab
1515 def self.roadmap(project_id, curruser)
16 projects_allowed = Project.list_for_user(curruser)
16 projects_allowed = Project.list_for_user(curruser.id)
1717 find(:all, :conditions => ["project_id = '#{project_id}' AND NOT status = 'complete' AND ( audience = '#{:public}' OR project_id IN (" << projects_allowed << ") )"], :order => "due_date ASC")
1818 end
1919
2020 def self.find_by_project_excl_proposed(project_id, curruser)
21 projects_allowed = Project.list_for_user(curruser)
21 projects_allowed = Project.list_for_user(curruser.id)
2222 find(:all, :conditions => ["project_id = '#{project_id}' AND status <> '#{:proposed}' AND ( audience = '#{:public}' OR project_id IN (" << projects_allowed << ") )"], :order => "created_at DESC")
2323 end
2424
2525 def self.find_by_id(milestone_id, curruser)
26 projects_allowed = Project.list_for_user(curruser)
26 projects_allowed = Project.list_for_user(curruser.id)
2727 #FIXME don't need the ORDER BY as it only returns one result, should probably check for other cases of this
2828 find(:first, :conditions => ["id = '#{milestone_id}' AND ( audience = '#{:public}' OR project_id IN (" << projects_allowed << ") )"], :order => "created_at DESC")
2929 end
toggle raw diff

app/models/project.rb

 
11class Project < ActiveRecord::Base
2
23 belongs_to :user
34 has_many :comments, :dependent => :destroy
5 has_many :tickets
46 has_many :repositories, :order => "repositories.mainline desc, repositories.created_at asc",
57 :dependent => :destroy
68 has_one :mainline_repository, :conditions => ["mainline = ?", true],
5858 end
5959
6060 def self.find_by_slug(slug, curruser)
61 projects_allowed = Project.list_for_user(curruser)
61 projects_allowed = Project.list_for_user(curruser.id)
6262 find(:first, :conditions => ["status = '#{:active}' AND projects.slug = '#{slug}' AND ( audience = '#{:public}' OR projects.id IN (#{projects_allowed}) )"])
6363 end
6464
148148
149149 #
150150 def self.allowed_access (project_id, curruser)
151 projects_allowed = Project.list_for_user(curruser)
151 projects_allowed = Project.list_for_user(curruser.id)
152152 find(:first, :conditions => ["status = '#{:active}' AND projects.id = '" << project_id.to_s << "' AND ( audience = '#{:public}' OR projects.id IN (" << projects_allowed << ") )"])
153153 end
154154
155155 #
156156 #FIXME this should maybe show inactive too
157157 def self.find_by_user(user, curruser)
158 projects_allowed = Project.list_for_user(curruser)
158 projects_allowed = Project.list_for_user(curruser.id)
159159 projects_available = Project.list_for_user(user)
160160 find(:all, :conditions => ["status = '#{:active}' AND projects.id IN (" << projects_available << ") AND ( audience = '#{:public}' OR projects.id IN (" << projects_allowed << ") )"])
161161 end
162162
163163 # returns all allowed projects
164164 def self.find_all_projects (curruser)
165 projects_allowed = Project.list_for_user(curruser)
165 projects_allowed = Project.list_for_user(curruser.id)
166166 find(:all, :conditions => ["status = '#{:active}' AND ( audience = '#{:public}' OR id IN (" << projects_allowed << ") )"])
167167 end
168168
169169 def self.find_popular_projects (curruser)
170 projects_allowed = Project.list_for_user(curruser)
170 projects_allowed = Project.list_for_user(curruser.id)
171171 find(:all, :conditions => ["status = '#{:active}' AND ( audience = '#{:public}' OR id IN (" << projects_allowed << ") )"], :limit => 10, :order => "views DESC")
172172 end
173173
174174 # returns all public projects (no private regardless of allowed)
175175 def self.find_all_active_public_projects (curruser)
176 projects_allowed = Project.list_for_user(curruser)
176 projects_allowed = Project.list_for_user(curruser.id)
177177 find(:all, :conditions => ["status = '#{:active}' AND ( audience = '#{:public}' AND NOT id IN (" << projects_allowed << ") )"])
178178 end
179179
187187
188188 # takes a list of project_ids e.g. '1','2','3'
189189 def self.find_by_list (list, curruser)
190 projects_allowed = Project.list_for_user(curruser)
190 projects_allowed = Project.list_for_user(curruser.id)
191191 find(:all, :conditions => ["status = '#{:active}' AND id IN (" << list << ") AND ( audience = '#{:public}' AND id IN (" << projects_allowed << ") )"])
192192 end
193193
194194 #
195195 # Get a list of project_ids of a user is a members of in the format '1','2','3'
196196 #
197 def self.list_for_user(user)
198 if user
197 def self.list_for_user(user_id)
198 if user_id
199199 list = ""
200 projects = Member.find_by_user(user.id)
200 projects = Member.find_by_user(user_id)
201201 unless projects.empty?
202202 start = true
203203 for project in projects
221221 when PRJ_TAB_GIT
222222 title = "Git"
223223 url_suffix = "/git/"
224 when PRJ_TAB_MEMBERS
225 title = "Members"
226 url_suffix = "/members/"
224 when PRJ_TAB_TEAM
225 title = "Team"
226 url_suffix = "/team/"
227227 when PRJ_TAB_WIKI
228228 title = "Wiki"
229229 url_suffix = "/wikis/" + wiki_slug
toggle raw diff

app/models/ticket.rb

 
22
33class Ticket < ActiveRecord::Base
44
5
6 belongs_to :assignee, :class_name => 'User', :foreign_key => 'assignee_id'
7 belongs_to :submitter, :class_name => 'User', :foreign_key => 'submitter_id'
5 belongs_to :assignee, :class_name => 'User', :foreign_key => 'assignee_id'
6 belongs_to :submitter, :class_name => 'User', :foreign_key => 'submitter_id'
87
98 def formatted_ttype
109 case self.ttype
5959 ORDER BY created_at DESC
6060 LIMIT 3") if first_milestone
6161 end
62
6362
6463 def self.qconcat (filters, types, lstart)
6564 s = ""
toggle raw diff

app/models/user/user.rb

 
141141
142142 def self.find_popular_authors (curruser)
143143 #FIXME see note in Article model about major conflict on audience
144 projects_allowed = Project.list_for_user(curruser)
144 projects_allowed = Project.list_for_user(curruser.id)
145145 find_by_sql ["SELECT *, COUNT(articles.id) AS num_articles FROM users JOIN articles ON users.id = articles.user_id WHERE articles.status = '#{:published}' AND (articles.audience = '#{:public}' OR project_id IN (" << projects_allowed << ") ) GROUP BY users.id ORDER BY num_articles DESC"]
146146 end
147147end
toggle raw diff

app/views/members/_ac_list_messages.html.erb

 
0<ul>
1<% @messages.each do |m| %>
2 <li>
3 <% if show_name %>
4 <strong><%= m.user.fullname %></strong>
5 <% end %>
6 <%= m.activity %>
7 <span class='small_grey'>(<%= time_ago_in_words(m.created_at) %> ago)</span>
8 </li>
9<% end %>
10</ul>
toggle raw diff

app/views/members/_ac_right_actionbox_post_message.html.erb

 
0
1<table class='right_input'>
2<tr><td>
3<% form_for :message, :url => project_members_path(@project.slug), :method => :post, :html => {:name => 'postmessage', :id => 'input'} do |f| -%>
4
5 <label>Message:</label>
6 <%= f.text_area(:activity, :rows => 2) -%>
7
8 <p>
9 <a href="javascript:document.postmessage.submit();">Update</a>
10 </p>
11
12<% end -%>
13</td></tr>
14</table>
toggle raw diff

app/views/members/ac_project_index.html.erb

 
0<%= render :partial => "projects/ac_project_header", :locals => { :tab => PRJ_TAB_MEMBERS,
1 :subtab => PRJ_TAB_SUBTAB_NONE,
2 :project => @project,
3 :pagetitle => @title } %>
4
5<% if @is_member && !@members.empty? %>
6<div id='projectmembers'>
7<ul>
8<% @members.each do |m| %>
9 <% if m.user != current_user %>
10 <li><%= m.user.fullname %></li>
11 <% end %>
12<% end %>
13</ul>
14</div>
15<% end %>
16
17<%= div_formattedtext_open %>
18
19<h4>Recent Messages</h4>
20<%= render :partial => "ac_list_messages", :locals => { :show_name => !@is_member } %>
21
22<%= div_formattedtext_close %>
23
24<%= render :partial => "projects/ac_project_footer" %>
toggle raw diff

app/views/messages/_ac_list_messages.html.erb

 
1<ul>
2<% @messages.each do |m| %>
3 <li>
4 <% if show_name %>
5 <strong><%= m.user.fullname %></strong>
6 <% end %>
7 <%= m.activity %>
8 <span class='small_grey'>(<%= time_ago_in_words(m.created_at) %> ago)</span>
9 </li>
10<% end %>
11</ul>
toggle raw diff

app/views/messages/_ac_right_actionbox_post_message.html.erb

 
1
2<table class='right_input'>
3<tr><td>
4<% form_for :message, :url => project_members_path(@project.slug), :method => :post, :html => {:name => 'postmessage', :id => 'input'} do |f| -%>
5
6 <label>Message:</label>
7 <%= f.text_area(:activity, :rows => 2) -%>
8
9 <p>
10 <a href="javascript:document.postmessage.submit();">Update</a>
11 </p>
12
13<% end -%>
14</td></tr>
15</table>
toggle raw diff

app/views/projects/ac_show.html.erb

 
3434<% unless @messages.empty? %>
3535<h4>Recent Messages</h4>
3636<hr />
37<%= render :partial => "members/ac_list_messages", :locals => { :show_name => true } %>
37<%= render :partial => "messages/ac_list_messages", :locals => { :show_name => true } %>
3838<%= link_to "[more]", project_members_path(@project), :class => "small" %><br />
3939<% end %>
4040
toggle raw diff

app/views/projects/ac_team.html.erb

 
1<%= render :partial => "ac_project_header", :locals => { :tab => PRJ_TAB_TEAM,
2 :subtab => PRJ_TAB_SUBTAB_NONE,
3 :project => @project,
4 :pagetitle => @title } %>
5
6<% if @is_member && !@members.empty? %>
7<div id='projectmembers'>
8<ul>
9<% @members.each do |m| %>
10 <% if m.user != current_user %>
11 <li><%= m.user.fullname %></li>
12 <% end %>
13<% end %>
14</ul>
15</div>
16<% end %>
17
18<%= div_formattedtext_open %>
19
20<h4>Recent Messages</h4>
21<%= render :partial => "messages/ac_list_messages", :locals => { :show_name => !@is_member } %>
22
23<%= div_formattedtext_close %>
24
25<%= render :partial => "ac_project_footer" %>
toggle raw diff

app/views/tickets/_ac_right_ticket_filter.html.erb

 
3131<%= check_box(:ticket, :priority_critical, {:checked => ticket_value_checked?(:priority_critical)}, "1", "0") %>Critical<br />
3232<br />
3333</small></td>
34
34
35</tr>
36
37<tr>
38<td colspan=2><small>
39Milestone: <br />
40Assignee:<br />
41Submitter:<br />
42
43
44Sort by:<br />
45</small></td>
3546</tr>
3647
3748<tr><td colspan=2>
toggle raw diff

config/initializers/gitlab_constants.rb

<