This commit is contained in:
wanglinchun 2014-06-03 15:27:04 +08:00
parent 528af32f91
commit 81a45fe977
8 changed files with 44 additions and 267 deletions

View File

@ -1,9 +1,9 @@
class ContestnotificationsController < ApplicationController class ContestnotificationsController < ApplicationController
# GET /contestnotifications # GET /contestnotifications
# GET /contestnotifications.json # GET /contestnotifications.json
layout 'base_contest' layout 'base_newcontest'
default_search_scope :contestnotification default_search_scope :contestnotifications
model_object Contestnotification model_object Contestnotifications
before_filter :find_model_object_contest, :except => [:new, :create, :index] before_filter :find_model_object_contest, :except => [:new, :create, :index]
before_filter :find_contest_from_association, :except => [:new, :create, :index] before_filter :find_contest_from_association, :except => [:new, :create, :index]
before_filter :find_contest_by_contest_id, :only => [:new, :create] before_filter :find_contest_by_contest_id, :only => [:new, :create]
@ -30,18 +30,18 @@ class ContestnotificationsController < ApplicationController
scope = @contest ? @contest.contestnotifications.visible : Contestnotifications.visible scope = @contest ? @contest.contestnotifications.visible : Contestnotifications.visible
@contestnotification_count = scope.count @contestnotifications_count = scope.count
@contestnotification_pages = Paginator.new @contestnotification_count, @limit, params['page'] @contestnotifications_pages = Paginator.new @contestnotifications_count, @limit, params['page']
@offset ||= @contestnotification_pages.offset @offset ||= @contestnotifications_pages.offset
@contestnotificationss = scope.all(:include => [:author, :contest], @contestnotificationss = scope.all(:include => [:author, :contest],
:order => "#{Contestnotification.table_name}.created_on DESC", :order => "#{Contestnotifications.table_name}.created_on DESC",
:offset => @offset, :offset => @offset,
:limit => @limit) :limit => @limit)
respond_to do |format| respond_to do |format|
format.html { format.html {
@contestnotifications = Contestnotifications.new # for adding news inline @contestnotification = Contestnotification.new # for adding news inline
render :layout => 'base_contest' render :layout => 'base_newcontest'
} }
format.api format.api
format.atom { render_feed(@contestnotificationss, :title => (@contest ? @contest.name : Setting.app_title) + ": #{l(:label_contest_notification)}") } format.atom { render_feed(@contestnotificationss, :title => (@contest ? @contest.name : Setting.app_title) + ": #{l(:label_contest_notification)}") }
@ -60,7 +60,7 @@ class ContestnotificationsController < ApplicationController
# end # end
@comments = @contestnotifications.comments @comments = @contestnotifications.comments
@comments.reverse! if User.current.wants_comments_in_reverse_order? @comments.reverse! if User.current.wants_comments_in_reverse_order?
render :layout => 'base_contest' render :layout => 'base_newcontest'
end end

View File

@ -4,9 +4,9 @@ class ContestsController < ApplicationController
menu_item :respond menu_item :respond
menu_item :project, :only => :show_project menu_item :project, :only => :show_project
menu_item :application, :only => :show_softapplication menu_item :application, :only => :show_softapplication
menu_item :attendingcontest, :only => :show_attendingcontest menu_item :attendingcontests, :only => :show_attendingcontest
menu_item :contestnotification, :only => :show_notification menu_item :contestnotifications, :only => :index
before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :show_notification, :set_reward_project, :set_reward_softapplication, :create,:destroy,:more,:back,:add,:add_softapplication,:new,:show_results, :set_reward, before_filter :find_contest, :only => [:show_contest, :show_project, :show_softapplication, :show_attendingcontest, :index, :set_reward_project, :set_reward_softapplication, :create,:destroy,:more,:back,:add,:add_softapplication,:new,:show_results, :set_reward,
:show_contest_project, :show_contest_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings] :show_contest_project, :show_contest_user, :join_in_contest, :unjoin_in_contest, :new_join,:show_participator, :settings]
# added by fq # added by fq

View File

@ -1,108 +0,0 @@
# Redmine - project management software
# Copyright (C) 2006-2013 Jean-Philippe Lang
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
class RolesController < ApplicationController
layout 'admin'
before_filter :require_admin, :except => [:index, :show]
before_filter :require_admin_or_api_request, :only => [:index, :show]
before_filter :find_role, :only => [:show, :edit, :update, :destroy]
accept_api_auth :index, :show
def index
respond_to do |format|
format.html {
@role_pages, @roles = paginate Role.sorted, :per_page => 25
render :action => "index", :layout => false if request.xhr?
}
format.api {
@roles = Role.givable.all
}
end
end
def show
respond_to do |format|
format.api
end
end
def new
# Prefills the form with 'Non member' role permissions by default
@role = Role.new(params[:role] || {:permissions => Role.non_member.permissions})
if params[:copy].present? && @copy_from = Role.find_by_id(params[:copy])
@role.copy_from(@copy_from)
end
@roles = Role.sorted.all
end
def create
@role = Role.new(params[:role])
if request.post? && @role.save
# workflow copy
if !params[:copy_workflow_from].blank? && (copy_from = Role.find_by_id(params[:copy_workflow_from]))
@role.workflow_rules.copy(copy_from)
end
flash[:notice] = l(:notice_successful_create)
redirect_to roles_path
else
@roles = Role.sorted.all
render :action => 'new'
end
end
def edit
end
def update
if request.put? and @role.update_attributes(params[:role])
flash[:notice] = l(:notice_successful_update)
redirect_to roles_path
else
render :action => 'edit'
end
end
def destroy
@role.destroy
redirect_to roles_path
rescue
flash[:error] = l(:error_can_not_remove_role)
redirect_to roles_path
end
def permissions
@roles = Role.sorted.all
@permissions = Redmine::AccessControl.permissions.select { |p| !p.public? }
if request.post?
@roles.each do |role|
role.permissions = params[:permissions][role.id.to_s]
role.save
end
flash[:notice] = l(:notice_successful_update)
redirect_to roles_path
end
end
private
def find_role
@role = Role.find(params[:id])
rescue ActiveRecord::RecordNotFound
render_404
end
end

View File

@ -31,12 +31,12 @@ class Contestnotification < ActiveRecord::Base
safe_attributes 'title', 'summary', 'description' safe_attributes 'title', 'summary', 'description'
def visible?(user=User.current) def visible?(user=User.current)
!user.nil? && user.allowed_to?(:view_contestnotification, contest) !user.nil? && user.allowed_to?(:view_contestnotifications, contest)
end end
# Returns true if the news can be commented by user # Returns true if the news can be commented by user
def commentable?(user=User.current) def commentable?(user=User.current)
user.allowed_to?(:comment_contestnotification, contest) user.allowed_to?(:comment_contestnotifications, contest)
end end
def recipients def recipients
@ -57,5 +57,5 @@ class Contestnotification < ActiveRecord::Base
def act_as_activity def act_as_activity
self.acts << Activity.new(:user_id => self.author_id) self.acts << Activity.new(:user_id => self.author_id)
end end
end end

View File

@ -1,133 +0,0 @@
<!-- <h1>Listing contestnotifications</h1>
<table>
<tr>
<th>Contest</th>
<th>Title</th>
<th>Summary</th>
<th>Description</th>
<th>Author</th>
<th>Comments count</th>
<th></th>
<th></th>
<th></th>
</tr>
<% @contestnotifications.each do |contestnotification| %>
<tr>
<td><%= contestnotification.contest_id %></td>
<td><%= contestnotification.title %></td>
<td><%= contestnotification.summary %></td>
<td><%= contestnotification.description %></td>
<td><%= contestnotification.author_id %></td>
<td><%= contestnotification.comments_count %></td>
<td><%= link_to 'Show', contestnotification %></td>
<td><%= link_to 'Edit', edit_contestnotification_path(contestnotification) %></td>
<td><%= link_to 'Destroy', contestnotification, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
<br />
<%= link_to 'New Contestnotification', new_contestnotification_path %> -->
<!--begin-->
<%
btn_tips = l(:label_news_new)
label_tips = l(:label_news)
%>
<span style="font-size: 16px; border-bottom:1px solid #f0f0f0; margin-right: 15px;">
<%= label_tips %>
</span>
<%= link_to(btn_tips,
new_contest_contestnotification_path(@contest),
:class => 'icon icon-add',
:onclick => 'showAndScrollTo("add-news", "news_title"); return false;') %>
<% if @contest && User.current.allowed_to?(:manage_news, @contest) %>
<div id="add-news" class="add_frame" style="display:none;">
<%= labelled_form_for @contestnotifications, :url => contest_contestnotifications_index_path(@contest),
:html => {:id => 'news-form', :multipart => true} do |f| %>
<%= render :partial => 'news/form', :locals => {:f => f} %>
<%= submit_tag l(:button_create), :class => 'whiteButton m3p10 h30', :name => nil %><!-- button-submit --> |
<%= preview_link preview_contestnotifications_path(:contest_id => @contest), 'news-form', target='preview', {:class => 'whiteButton m3p10'} %>
|
<%= link_to l(:button_cancel), "#", :onclick => '$("#add-news").hide()', :class => 'whiteButton m3p10' %>
<% end if @contest %>
<div id="preview" class="wiki"></div>
</div>
<% end %>
<div>
<% if @contestnotificationss.empty? %>
<p class="nodata">
<%= l(:label_no_data) %>
</p>
<% else %>
<% @contestnotificationss.each do |contestnotifications| %>
<table class="content-text-list">
<tr>
<td colspan="2" valign="top" width="50"><%= link_to image_tag(url_to_avatar(contestnotifications.author), :class => "avatar"), user_path(contestnotifications.author) %></td>
<td>
<table width="580px" border="0">
<tr>
<td colspan="2" valign="top">
<strong><%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %></strong><span style="margin-left: 4px;" class="font_lighter"><%= l(:label_project_notice) %></span><span><%= link_to h(news.title), news_path(news) %></span>
<span style="float: right"><%= delete_link contestnotifications_path(news) if User.current.allowed_to?(:manage_contestnotification, @contest) %> </span>
</td>
</tr>
<tr>
<td colspan="2" width="580px">
<span class="font_description"><%= textilizable(contestnotifications, :description) %></span></td>
</tr>
<tr>
<td align="left"><span class="font_lighter"> <%= l :label_update_time %>
&nbsp;<%= format_time(contestnotifications.created_at) %></span></td>
<td width="350" align="right" class="a"><%= link_to l(:label_project_newother), contestnotifications_path(contestnotifications) %><%= "(#{l(:label_x_comments, :count => contestnotifications.comments_count)})" if contestnotifications.comments_count >= 0 %></td>
</tr>
</table>
</td>
</tr>
</table>
<% end %>
<% end %>
</div>
<!--end-->
<div style="padding-right: 10px">
<div class="pagination">
<ul>
<%= pagination_links_full @news_pages %>
</ul>
</div>
<% other_formats_links do |f| %>
<%= f.link_to 'Atom', :url => {:project_id => @project, :key => User.current.rss_key} %>
<% end %>
<% content_for :header_tags do %>
<%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %>
<%= stylesheet_link_tag 'scm' %>
<% end %>
<% html_title(l(:label_news_plural)) -%>
</div>
<script type='text/javascript'>
$(document).ready(function ($) {
$('.content-text-list').each(function () {
$(this).find('.delete_icon').hide();
$(this).mouseenter(function (event) {
$(this).find('.delete_icon').show();
});
$(this).mouseleave(function (event) {
$(this).find('.delete_icon').hide();
});
});
});
</script>
<!--end-->

View File

@ -16,8 +16,9 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
RedmineApp::Application.routes.draw do RedmineApp::Application.routes.draw do
resources :contestnotifications resources :contestnotifications
match '/contests/:id/contestnotifications', :controller => 'contestnotifications', :action => 'index'
resources :homework_users resources :homework_users
@ -85,7 +86,7 @@ RedmineApp::Application.routes.draw do
match 'show_project' , via: :get match 'show_project' , via: :get
match 'show_softapplication' , via: :get match 'show_softapplication' , via: :get
match 'show_attendingcontest' , via: :get match 'show_attendingcontest' , via: :get
match 'show_notification' , via: :get #match 'show_notification' , via: :get
match 'show_participator' , via: :get match 'show_participator' , via: :get
match 'set_reward_project' , via: [:get, :post] match 'set_reward_project' , via: [:get, :post]
match 'set_reward_softapplication' , via: [:get, :post] match 'set_reward_softapplication' , via: [:get, :post]
@ -93,6 +94,7 @@ RedmineApp::Application.routes.draw do
match 'add_softapplication' , via: [:get, :post] match 'add_softapplication' , via: [:get, :post]
match 'create' , via: :post match 'create' , via: :post
match 'settings' , via: [:get, :post] match 'settings' , via: [:get, :post]
end end
end end

View File

@ -93,6 +93,7 @@ Redmine::AccessControl.map do |map|
map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member
map.permission :close_project, {:projects => [:close, :reopen]}, :require => :member, :read => true map.permission :close_project, {:projects => [:close, :reopen]}, :require => :member, :read => true
map.permission :select_project_modules, {:projects => :modules}, :require => :member map.permission :select_project_modules, {:projects => :modules}, :require => :member
map.permission :select_contest_modules, {:contests => :modules}, :require => :member
map.permission :manage_members, {:projects => :settings, :members => [:index, :show, :create, :update, :destroy, :autocomplete]}, :require => :member map.permission :manage_members, {:projects => :settings, :members => [:index, :show, :create, :update, :destroy, :autocomplete]}, :require => :member
map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member map.permission :manage_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :require => :member
map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member map.permission :add_subprojects, {:projects => [:new, :create]}, :require => :member
@ -146,10 +147,10 @@ Redmine::AccessControl.map do |map|
map.permission :comment_news, {:comments => :create} map.permission :comment_news, {:comments => :create}
end end
map.project_module :contestnotification do |map| map.contest_module :contestnotifications do |map|
map.permission :manage_contestnotification, {:contestnotifications => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member map.permission :manage_contestnotifications, {:contestnotifications => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member
map.permission :view_contestnotification, {:contestnotifications => [:index, :show]}, :public => true, :read => true map.permission :view_contestnotifications, {:contestnotifications => [:index, :show]}, :public => true, :read => true
map.permission :comment_contestnotification, {:comments => :create} map.permission :comment_contestnotifications, {:comments => :create}
end end
map.project_module :documents do |map| map.project_module :documents do |map|
@ -293,7 +294,8 @@ Redmine::MenuManager.map :contest_menu do |menu|
#menu.push :project, :show_project_contest_path, :caption => :label_contest_project #menu.push :project, :show_project_contest_path, :caption => :label_contest_project
#menu.push :application, :show_softapplication_contest_path, :caption => :label_contest_application #menu.push :application, :show_softapplication_contest_path, :caption => :label_contest_application
menu.push :attendingcontest, {:controller => 'contests', :action => 'show_attendingcontest'}, :caption => :label_attending_contest menu.push :attendingcontest, {:controller => 'contests', :action => 'show_attendingcontest'}, :caption => :label_attending_contest
menu.push :contestnotification, {:controller => 'contests', :action => 'show_notification'}, :caption => :label_contest_notification menu.push :contestnotifications, { :controller => 'contestnotifications', :action => 'index' }, :param => :contest_id, :caption => :label_contest_notification
#menu.push :contestnotification, {:controller => 'contests', :action => 'show_notification'}, :caption => :label_contest_notification
# menu.push :attendingcontest, :show_attendingcontest_contest_path, :caption => :label_attendin,g_contest # menu.push :attendingcontest, :show_attendingcontest_contest_path, :caption => :label_attendin,g_contest
# menu.push :result, { :controller => 'bids', :action => 'show_results' }, # menu.push :result, { :controller => 'bids', :action => 'show_results' },
# :caption => :label_bidding_results,:if => Proc.new{ |p| User.current.id == p } # :caption => :label_bidding_results,:if => Proc.new{ |p| User.current.id == p }

View File

@ -67,20 +67,26 @@ module Redmine
def available_project_modules def available_project_modules
@available_project_modules ||= @permissions.collect(&:project_module).uniq.compact @available_project_modules ||= @permissions.collect(&:project_module).uniq.compact
end end
def available_contest_modules
@available_contest_modules ||= @permissions.collect(&:contest_module).uniq.compact
end
def modules_permissions(modules) def modules_permissions(modules)
@permissions.select {|p| p.project_module.nil? || modules.include?(p.project_module.to_s)} @permissions.select {|p| p.project_module.nil? || modules.include?(p.project_module.to_s)}
@permissions.select {|p| p.contest_module.nil? || modules.include?(p.contest_module.to_s)}
end end
end end
class Mapper class Mapper
def initialize def initialize
@project_module = nil @project_module = nil
@contest_module = nil
end end
def permission(name, hash, options={}) def permission(name, hash, options={})
@permissions ||= [] @permissions ||= []
options.merge!(:project_module => @project_module) options.merge!(:project_module => @project_module)
options.merge!(:contest_module => @contest_module)
@permissions << Permission.new(name, hash, options) @permissions << Permission.new(name, hash, options)
end end
@ -90,13 +96,19 @@ module Redmine
@project_module = nil @project_module = nil
end end
def contest_module(name, options={})
@contest_module = name
yield self
@contest_module = nil
end
def mapped_permissions def mapped_permissions
@permissions @permissions
end end
end end
class Permission class Permission
attr_reader :name, :actions, :project_module attr_reader :name, :actions, :project_module, :contest_module
def initialize(name, hash, options) def initialize(name, hash, options)
@name = name @name = name
@ -105,6 +117,8 @@ module Redmine
@require = options[:require] @require = options[:require]
@read = options[:read] || false @read = options[:read] || false
@project_module = options[:project_module] @project_module = options[:project_module]
@contest_module = options[:contest_module]
hash.each do |controller, actions| hash.each do |controller, actions|
if actions.is_a? Array if actions.is_a? Array
@actions << actions.collect {|action| "#{controller}/#{action}"} @actions << actions.collect {|action| "#{controller}/#{action}"}