Commit 9350cd8015a35c3b539cdac000d701bc9b9de995

Added project membership system
Added list wikis

Commit diff

app/controllers/application.rb

 
99 rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
1010 rescue_from ActionController::UnknownController, :with => :render_not_found
1111 rescue_from ActionController::UnknownAction, :with => :render_not_found
12
12
1313 def rescue_action(exception)
1414 return super if RAILS_ENV != "production"
1515
7070 "appcast"
7171 end
7272 end
73
7374end
toggle raw diff

app/controllers/articles_controller.rb

 
44class ArticlesController < ApplicationController
55
66 after_filter :after_article
7
78
89 # Show all articles, render grouped by year, month
910 def index
toggle raw diff

app/controllers/wikis_controller.rb

 
11class WikisController < ApplicationController
22
33 def index
4 # Project Wiki index page, shows list of all wikis for that project
54 if params[:project_id] != nil
6 @project = Project.find_by_slug(params[:project_id], current_user)
5 # Project Wiki index page, shows list of all wikis for that project
6 @project, @member = Project.find_by_slug_public_or_member(params[:project_id], current_user)
77 if @project != nil
8 @title = "List Wikis"
9 #@url_suffix = Project.tab_settings(PRJ_TAB_DOCUMENTATION)
10 @url_suffix = ""
118 @wikis = Wiki.find_by_project(@project.id)
12 if @wikis.size > 0
9 if @wikis.size > 0
10 @title = "List Wikis"
11 @url_suffix = ""
1312 render :action => "ac_project_index"
1413 else
1514 flash[:error] = "No wikis for this project."
1919 redirect_to root_path
2020 end
2121 else
22 # show default wiki page
22 # Main wiki - default page
2323 @wiki = Wiki.find_by_slug("wiki-contents")
2424 @wiki_breadcrumb = false
2525 @title = "Wiki"
2929
3030 def show
3131 if params[:project_id] != nil
32 @project = Project.find_by_slug(params[:project_id], current_user)
32 # Project wiki, page specfied
33 @project, @member = Project.find_by_slug_public_or_member(params[:project_id], current_user)
3334 if @project != nil
34 # Project wiki, page specfied
3535 @wiki = Wiki.find_by_slug(params[:id])
3636 if @wiki != nil
3737 @title = @wiki.title
4747 redirect_to root_path
4848 end
4949 else
50 # Normal Wiki index page
50 # Main wiki index page
5151 @wiki = Wiki.find_by_slug(params[:id])
5252 if @wiki != nil
5353 @wiki_breadcrumb = true
6565
6666 def new
6767 if params[:project_id] != nil
68 @project = Project.find_by_slug(params[:project_id], current_user)
68 @project, @member = Project.find_by_slug_public_or_member(params[:project_id], current_user)
6969 if @project != nil
7070 @wiki = Wiki.new
7171 @title = "New " + @project.title + " Wiki Page"
8484
8585 def create
8686 #FIXME error check @project
87 @project = Project.find_by_slug(params[:project_id], current_user)
87 @project, @member = Project.find_by_slug_public_or_member(params[:project_id], current_user)
8888 @wiki = Wiki.new(params[:wiki])
8989 @wiki.slug = to_slug(@wiki.title)
9090 @wiki.project_id = @project.id
101101
102102 def edit
103103 if params[:project_id] != nil
104 @project = Project.find_by_slug(params[:project_id], current_user)
104 @project, @member = Project.find_by_slug_public_or_member(params[:project_id], current_user)
105105 if @project != nil
106106 # Project wiki, page specfied
107107 @wiki = Wiki.find_by_slug(params[:id])
132132
133133 def update
134134 if params[:project_id] != nil
135 @project = Project.find_by_slug(params[:project_id], current_user)
135 @project, @member = Project.find_by_slug_public_or_member(params[:project_id], current_user)
136136 if @project != nil
137137 # Project wiki, page specfied
138138 @wiki = Wiki.find_by_slug(params[:id])
toggle raw diff

app/helpers/application_helper.rb

 
11# Methods added to this helper will be available to all templates in the application.
22module ApplicationHelper
33 include TagsHelper
4
4
55 def default_css_tag_sizes
66 %w(tag_size_1 tag_size_2 tag_size_3 tag_size_4)
77 end
326326 out
327327 end
328328
329
330329 def render_right_actionbox_complex (flags = {})
331330 out = %Q{<table class='right_default_table'>}
332331 out << %Q{<tr><th>Actions</th></tr>}
333332 #
334 if logged_in?
335 acts = ""
336 acts << %Q{<li>#{link_to("Edit Wiki Page", edit_project_wiki_path(@project.slug, @wiki.slug))}</li>} if flags[:edit_project_wiki]
337 acts << %Q{<li>#{link_to("New Wiki Page", new_project_wiki_path(@project.slug))}</li>} if flags[:new_project_wiki]
338 acts << %Q{<li>#{link_to("List Wiki Pages", project_wikis_path(@project.slug))}</li>} if flags[:list_project_wikis]
339 #
340 acts << %Q{<li>#{link_to("Edit Article", edit_project_article_path(@project.slug, @article.slug))}</li>} if flags[:edit_article]
341 acts << %Q{<li>#{link_to("New Article", new_project_article_path(@project.slug))}</li>} if flags[:new_article]
342 acts << %Q{<li>#{link_to("New Milestone", new_project_milestone_path(@project.slug))}</li>} if flags[:new_milestone]
343 acts << %Q{<li>#{link_to("New Ticket", new_project_ticket_path(@project.slug))}</li>} if flags[:new_ticket]
344 acts << %Q{<li>#{link_to("Clone Mainline", new_project_repository_path(@project.slug, @repository))}</li>} if flags[:clone_mainline]
345 out << %Q{<tr><td><ul>#{acts}</ul></td></tr>} if acts != ""
346 end
333 #FIXME finish this, also it must must only be true if logged_in?
334 logged_in? ? is_member = true : is_member = false
335 acts = ""
336 acts << %Q{<li>#{link_to("Edit Wiki Page", edit_project_wiki_path(@project.slug, @wiki.slug))}</li>} if flags[:edit_project_wiki] && is_member
337 acts << %Q{<li>#{link_to("New Wiki Page", new_project_wiki_path(@project.slug))}</li>} if flags[:new_project_wiki] && is_member
338 acts << %Q{<li>#{link_to("List Wiki Pages", project_wikis_path(@project.slug))}</li>} if flags[:list_project_wikis]
339 acts << %Q{<li>#{link_to("Edit Article", edit_project_article_path(@project.slug, @article.slug))}</li>} if flags[:edit_article] && is_member
340 acts << %Q{<li>#{link_to("New Article", new_project_article_path(@project.slug))}</li>} if flags[:new_article] && is_member
341 acts << %Q{<li>#{link_to("New Milestone", new_project_milestone_path(@project.slug))}</li>} if flags[:new_milestone] && is_member
342 acts << %Q{<li>#{link_to("New Ticket", new_project_ticket_path(@project.slug))}</li>} if flags[:new_ticket]
343 acts << %Q{<li>#{link_to("Clone Mainline", new_project_repository_path(@project.slug, @repository))}</li>} if flags[:clone_mainline] && logged_in?
344 out << %Q{<tr><td><ul>#{acts}</ul></td></tr>} if acts != ""
347345 out << %Q{<tr><td>#{render_right_actionbox_default(flags)}</td></tr>}
348346 out << %Q{</table>}
349347 out
350348 end
351
349
352350end
toggle raw diff

app/helpers/members_helper.rb

 
1module MembersHelper
2
3 #
4 # FIXME pointless, and should be in model
5 def format_member_accesslevel(accesslevel)
6 case accesslevel
7 when :admin
8 return "Admin"
9 when :modify
10 return "Modify"
11 when :readonly
12 return "Read Only"
13 end
14 end
15
16end
toggle raw diff

app/helpers/projects_helper.rb

 
9898 else
9999 out << render_right_actionbox_complex(:allow_shortcuts => true, :edit_project_wiki => true, :new_project_wiki => true, :list_project_wikis => true)
100100 end
101 out << render_right_project_contributors
102101 out << render_right_project_extrainfo
102 out << render_right_project_contributors
103103 when PRJ_TAB_DOWNLOADS
104104 out << render_right_actionbox_basic(:allow_shortcuts => true)
105105 when PRJ_TAB_REPOS
135135 end
136136 out
137137 end
138
139138
140139 def format_life_cycle (ls)
141140 case ls
143143 when :mature_frozen
144144 "Mature Frozen"
145145 else
146 ls.to_s.captilize
146 ls.to_s.capitalize
147 end
148 end
149
150
151 def format_member_accesslevel (al)
152 case al
153 when :readonly
154 "Read Only"
155 else
156 al.to_s.capitalize
147157 end
148158 end
149159
toggle raw diff

app/models/appcast/member.rb

 
55
66 protected
77
8 #
98 def self.find_by_search(phrase)
109 #find(:all, :conditions => ["status = '#{:published}' AND title like ?", "%" << phrase << "%"])
1110 end
1211
13 #
1412 def self.find_by_project(project_id)
1513 find(:all, :conditions => ["project_id = '#{project_id}'"], :order => "accesslevel DESC")
1614 end
1715
18 #
1916 def self.find_by_user(user_id)
2017 find(:all, :conditions => ["user_id = '#{user_id}'"])
2118 end
2219
23 #
2420 def self.is_member? (project_id, user_id)
25 if find(:first, :conditions => ["project_id = '#{project_id}' AND user_id = '#{user_id}'"]) != nil then
26 return true
21 if find(:first, :conditions => ["project_id = '#{project_id}' AND user_id = '#{user_id}'"]) != nil
22 true
2723 else
28 return false
24 false
2925 end
3026 end
3127
toggle raw diff

app/models/project.rb

 
11class Project < ActiveRecord::Base
2 acts_as_taggable
2 acts_as_taggable if $application_mode != MODE_APPCAST
33
44 belongs_to :user
55 has_many :comments, :dependent => :destroy
188188 )
189189 end
190190
191 #
192 def self.find_by_slug_secure(slug, curruser)
191 def self.find_by_slug_public_or_member(slug, curruser)
193192 projects_allowed = Project.list_for_user(curruser)
194 find(:first, :conditions => ["status = '#{:active}' AND slug = '#{slug}' AND ( audience = '#{:public}' OR projects.id IN (" << projects_allowed << ") )"])
193 project = find(:first, :conditions => ["status = '#{:active}' AND slug = '#{slug}' AND ( audience = '#{:public}' OR projects.id IN (" << projects_allowed << ") )"])
194 #TODO this can be found from the above
195 if project
196 member = Member.is_member?(project.id, curruser.id)
197 else
198 member = false
199 end
200 return project, member
195201 end
196
202
197203 # takes a list of project_ids e.g. '1','2','3'
198204 def self.find_by_list (list, curruser)
199205 projects_allowed = Project.list_for_user(curruser)
208208
209209 #
210210 # Get a list of project_ids of a user is a members of in the format '1','2','3'
211 # FIXME this should be in a helper I think
212211 #
213212 def self.list_for_user(user)
214 #if user != nil then
215 # list = ""
216 # projects = Member.find_by_user(user.id)
217 # if projects.size > 0 then
218 # start = true
219 # for project in projects
220 # if not start then
221 # list = list << ","
222 # else
223 # start = false
224 # end
225 # list = list << "'" << project.project_id.to_s << "'"
226 # end
227 # return list
228 # else
229 # return "'1'" # see below
230 # end
231 #else
213 if user != nil then
214 list = ""
215 projects = Member.find_by_user(user.id)
216 if projects.size > 0 then
217 start = true
218 for project in projects
219 if not start then
220 list = list << ","
221 else
222 start = false
223 end
224 list = list << "'" << project.project_id.to_s << "'"
225 end
226 return list
227 else
228 return "'1'" # see below
229 end
230 else
232231 return "'1'" # Project.id 1 is no project (this is a bit of a frig really, without it 2 queries will be needed for all finds)
233 #end
232 end
234233 end
235234
236235 def self.tab_settings (tab)
toggle raw diff

app/views/layouts/appcast.html.erb

 
2121 <% end -%>
2222
2323 <div id="system_message">
24 <p><strong>Notice:</strong> this site is unstable work-in-progress, source for it is available on <a href='http://gitorious.org/projects/gitorious/repos/appcast'>gitorious.org</a>. Contact <a href='mailto:mtkd@prj2.com'>mtkd@prj2.com</a></p>
24 <p><strong>Notice:</strong> <%= @member.to_s %> this site is unstable work-in-progress, source for it is available on <a href='http://gitorious.org/projects/gitorious/repos/appcast'>gitorious.org</a>. Contact <a href='mailto:mtkd@prj2.com'>mtkd@prj2.com</a></p>
2525 </div>
2626
2727 <div id='header'>
toggle raw diff

app/views/wikis/ac_project_index.html.erb

 
88<table class='public'>
99
1010<tr>
11 <th>ID</th>
12 <th width='260'>Title</th>
13 <th>Status</th>
14 <th>Format</th>
15 <th>Slug</th>
16 <th>Created</th>
17 <th colspan='2'></th>
11 <th width='<%= STYLE_TABLE_COL_WIDTH_ID %>'>ID</th>
12 <th>Title</th>
13 <% if @member %>
14 <th width='100'>Status</th>
15 <th width='100'>Format</th>
16 <th width='180'>Slug</th>
17 <% end %>
18 <th width='<%= STYLE_TABLE_COL_WIDTH_DDMMYYHHMM %>'>Created</th>
19 <% if @member %>
20 <th colspan='2' width='<%= STYLE_TABLE_COL_WIDTH_ACTION_SHORT.to_i * 2 %>'></th>
21 <% end %>
1822</tr>
1923
2024<% for wiki in @wikis %>
2125<tr>
2226 <td><%= wiki.id %></td>
23 <td><%= wiki.title %></td>
24 <td><%= wiki.status.to_s.capitalize %></td>
25 <td><%= wiki.format.to_s.capitalize %></td>
26 <td>/<%= wiki.slug %></td>
27 <td><%= format_datetime_ddmmyyhhmm(wiki.created_at) %></td>
28 <td>Edit</td>
29 <td>Del</td>
27 <td><%= link_to wiki.title, project_wiki_path(@project.slug, wiki.slug) %></td>
28 <% if @member %>
29 <td><%= wiki.status.to_s.capitalize %></td>
30 <td><%= wiki.format.to_s.capitalize %></td>
31 <td>/<%= wiki.slug %></td>
32 <% end %>
33 <td><%= format_datetime_ddmmyyhhmm(wiki.created_at) %></td>
34 <% if @member %>
35 <td>Edit</td>
36 <td>Del</td>
37 <% end %>
3038</tr>
3139<% end %>
3240
toggle raw diff

config/initializers/appcast_config.rb

 
4848ART_LIST_PROJECT = 2
4949
5050#
51STYLE_TABLE_COL_WIDTH_ID = "30"
5152STYLE_TABLE_COL_WIDTH_DATE = "74"
5253STYLE_TABLE_COL_WIDTH_DDMMYYHHMM = "124"
5354STYLE_TABLE_COL_WIDTH_DDBBYY = "82"
toggle raw diff

public/stylesheets/appcast.css

 
164164#comments .commentdate { font-size: 0.8em; }
165165
166166/* Footer Section */
167#footer { clear: left; height: 600px; margin: 60px 0px 0px 0px; padding: 3px; border-top: 1px solid #aaa; background-color: #ededed; }
167#footer { clear: left; height: 600px; margin: 60px 360px 0px 0px; padding: 3px; border-top: 1px solid #aaa; background-color: #fff; }
168168#footer .text { margin: 0px 0px 0px 2px; font-size: 0.8em; color: #666; }
169169
170170table.admin_vert { margin-top: 20px; margin-bottom: 10px; background-color: #aaa; border-spacing: 1px; }
188188table.right_archive_summary td { font-size: 0.9em; text-align: center; margin: 0px; padding: 1px; }
189189
190190table.right_default_table { border: 2px solid #eee; width: 100%; margin: 0px 0px 20px 0px; border-spacing: 0px; }
191table.right_default_table th { font-weight: 800; text-align: left; background-color: #eee; border: 0px; margin: 0px; padding: 6px 10px 6px 10px; }
192table.right_default_table td { vertical-align: top; text-align: left; background-color: #fbfbfb; border: 0px; margin: 0px; padding: 6px 10px 6px 10px; }
191table.right_default_table th { font-weight: 800; text-align: left; background-color: #eee; border: 0px; margin: 0px; padding: 4px 10px 4px 10px; }
192table.right_default_table td { vertical-align: top; text-align: left; background-color: #fbfbfb; border: 0px; margin: 0px; padding: 4px 5px 4px 10px; }
193193table.right_default_table .count { font-size: 0.9em; }
194194/*
195195table.releasedownload { margin-top: 10px; margin-bottom: 20px; background-color: #fff; border-spacing: 0px; }
toggle raw diff

test/fixtures/members.yml

 
1#
2#
3#
4#
5<% fixtures :users, :projects %>
6
7one:
8 id: 1
9 accesslevel: :admin
10 project_id: <%= projects(:appcast) %>
11 user_id: <%= users(:mtkd) %>
12
13
14
15
16
17
18
19
20
21
toggle raw diff

test/fixtures/tickets.yml

 
88
99#
1010#
11#
11# Remove all != nil
1212#
1313# Add defaults to fixtures:
1414#
toggle raw diff