diff --git a/app/controllers/contestnotifications_controller.rb b/app/controllers/contestnotifications_controller.rb index 15455c806..110f26466 100644 --- a/app/controllers/contestnotifications_controller.rb +++ b/app/controllers/contestnotifications_controller.rb @@ -1,9 +1,9 @@ class ContestnotificationsController < ApplicationController # GET /contestnotifications # GET /contestnotifications.json - layout 'base_contest' - default_search_scope :contestnotification - model_object Contestnotification + layout 'base_newcontest' + default_search_scope :contestnotifications + model_object Contestnotifications before_filter :find_model_object_contest, :except => [:new, :create, :index] before_filter :find_contest_from_association, :except => [:new, :create, :index] before_filter :find_contest_by_contest_id, :only => [:new, :create] @@ -30,18 +30,18 @@ class ContestnotificationsController < ApplicationController scope = @contest ? @contest.contestnotifications.visible : Contestnotifications.visible - @contestnotification_count = scope.count - @contestnotification_pages = Paginator.new @contestnotification_count, @limit, params['page'] - @offset ||= @contestnotification_pages.offset + @contestnotifications_count = scope.count + @contestnotifications_pages = Paginator.new @contestnotifications_count, @limit, params['page'] + @offset ||= @contestnotifications_pages.offset @contestnotificationss = scope.all(:include => [:author, :contest], - :order => "#{Contestnotification.table_name}.created_on DESC", + :order => "#{Contestnotifications.table_name}.created_on DESC", :offset => @offset, :limit => @limit) respond_to do |format| format.html { - @contestnotifications = Contestnotifications.new # for adding news inline - render :layout => 'base_contest' + @contestnotification = Contestnotification.new # for adding news inline + render :layout => 'base_newcontest' } format.api format.atom { render_feed(@contestnotificationss, :title => (@contest ? @contest.name : Setting.app_title) + ": #{l(:label_contest_notification)}") } @@ -60,7 +60,7 @@ class ContestnotificationsController < ApplicationController # end @comments = @contestnotifications.comments @comments.reverse! if User.current.wants_comments_in_reverse_order? - render :layout => 'base_contest' + render :layout => 'base_newcontest' end diff --git a/app/controllers/contests_controller.rb b/app/controllers/contests_controller.rb index b51a11436..bd4206808 100644 --- a/app/controllers/contests_controller.rb +++ b/app/controllers/contests_controller.rb @@ -4,9 +4,9 @@ class ContestsController < ApplicationController menu_item :respond menu_item :project, :only => :show_project menu_item :application, :only => :show_softapplication - menu_item :attendingcontest, :only => :show_attendingcontest - menu_item :contestnotification, :only => :show_notification - 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, + menu_item :attendingcontests, :only => :show_attendingcontest + menu_item :contestnotifications, :only => :index + 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] # added by fq diff --git a/app/controllers/roles_controller.rb b/app/controllers/roles_controller.rb deleted file mode 100644 index f4bae1e81..000000000 --- a/app/controllers/roles_controller.rb +++ /dev/null @@ -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 diff --git a/app/models/contestnotification.rb b/app/models/contestnotification.rb index f7087c49d..75b0f5814 100644 --- a/app/models/contestnotification.rb +++ b/app/models/contestnotification.rb @@ -31,12 +31,12 @@ class Contestnotification < ActiveRecord::Base safe_attributes 'title', 'summary', 'description' def visible?(user=User.current) - !user.nil? && user.allowed_to?(:view_contestnotification, contest) + !user.nil? && user.allowed_to?(:view_contestnotifications, contest) end # Returns true if the news can be commented by user def commentable?(user=User.current) - user.allowed_to?(:comment_contestnotification, contest) + user.allowed_to?(:comment_contestnotifications, contest) end def recipients @@ -57,5 +57,5 @@ class Contestnotification < ActiveRecord::Base def act_as_activity self.acts << Activity.new(:user_id => self.author_id) end - + end diff --git a/app/views/contestnotifications/index.html.erb b/app/views/contestnotifications/index.html.erb index 514b89060..e69de29bb 100644 --- a/app/views/contestnotifications/index.html.erb +++ b/app/views/contestnotifications/index.html.erb @@ -1,133 +0,0 @@ - - - -<% - btn_tips = l(:label_news_new) - label_tips = l(:label_news) -%> - - - <%= label_tips %> - - -<%= 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) %> - -<% end %> -
- <% if @contestnotificationss.empty? %> -

- <%= l(:label_no_data) %> -

- <% else %> - <% @contestnotificationss.each do |contestnotifications| %> - - - - - - -
<%= link_to image_tag(url_to_avatar(contestnotifications.author), :class => "avatar"), user_path(contestnotifications.author) %> - - - - - - - - - - - - -
- <%= link_to_user(contestnotifications.author) if contestnotifications.respond_to?(:author) %><%= l(:label_project_notice) %><%= link_to h(news.title), news_path(news) %> - <%= delete_link contestnotifications_path(news) if User.current.allowed_to?(:manage_contestnotification, @contest) %> -
- <%= textilizable(contestnotifications, :description) %>
<%= l :label_update_time %> - : <%= format_time(contestnotifications.created_at) %><%= link_to l(:label_project_newother), contestnotifications_path(contestnotifications) %><%= "(#{l(:label_x_comments, :count => contestnotifications.comments_count)})" if contestnotifications.comments_count >= 0 %>
-
- <% end %> - <% end %> -
- -
- - - <% 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)) -%> -
- - - - diff --git a/config/routes.rb b/config/routes.rb index ef63888f8..c6a727ca6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -16,8 +16,9 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. RedmineApp::Application.routes.draw do - resources :contestnotifications - + resources :contestnotifications + + match '/contests/:id/contestnotifications', :controller => 'contestnotifications', :action => 'index' resources :homework_users @@ -85,7 +86,7 @@ RedmineApp::Application.routes.draw do match 'show_project' , via: :get match 'show_softapplication' , via: :get match 'show_attendingcontest' , via: :get - match 'show_notification' , via: :get + #match 'show_notification' , via: :get match 'show_participator' , via: :get match 'set_reward_project' , 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 'create' , via: :post match 'settings' , via: [:get, :post] + end end diff --git a/lib/redmine.rb b/lib/redmine.rb index a72e74ce4..861e14f7e 100644 --- a/lib/redmine.rb +++ b/lib/redmine.rb @@ -93,6 +93,7 @@ Redmine::AccessControl.map do |map| map.permission :edit_project, {:projects => [:settings, :edit, :update]}, :require => :member map.permission :close_project, {:projects => [:close, :reopen]}, :require => :member, :read => true 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_versions, {:projects => :settings, :versions => [:new, :create, :edit, :update, :close_completed, :destroy]}, :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} end - map.project_module :contestnotification do |map| - map.permission :manage_contestnotification, {:contestnotifications => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member - map.permission :view_contestnotification, {:contestnotifications => [:index, :show]}, :public => true, :read => true - map.permission :comment_contestnotification, {:comments => :create} + map.contest_module :contestnotifications do |map| + map.permission :manage_contestnotifications, {:contestnotifications => [:new, :create, :edit, :update, :destroy], :comments => [:destroy]}, :require => :member + map.permission :view_contestnotifications, {:contestnotifications => [:index, :show]}, :public => true, :read => true + map.permission :comment_contestnotifications, {:comments => :create} end 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 :application, :show_softapplication_contest_path, :caption => :label_contest_application 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 :result, { :controller => 'bids', :action => 'show_results' }, # :caption => :label_bidding_results,:if => Proc.new{ |p| User.current.id == p } diff --git a/lib/redmine/access_control.rb b/lib/redmine/access_control.rb index 7c4a5a5ec..dfde5debc 100644 --- a/lib/redmine/access_control.rb +++ b/lib/redmine/access_control.rb @@ -67,20 +67,26 @@ module Redmine def available_project_modules @available_project_modules ||= @permissions.collect(&:project_module).uniq.compact end - + def available_contest_modules + @available_contest_modules ||= @permissions.collect(&:contest_module).uniq.compact + end + def modules_permissions(modules) @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 class Mapper def initialize @project_module = nil + @contest_module = nil end def permission(name, hash, options={}) @permissions ||= [] options.merge!(:project_module => @project_module) + options.merge!(:contest_module => @contest_module) @permissions << Permission.new(name, hash, options) end @@ -90,13 +96,19 @@ module Redmine @project_module = nil end + def contest_module(name, options={}) + @contest_module = name + yield self + @contest_module = nil + end + def mapped_permissions @permissions end end class Permission - attr_reader :name, :actions, :project_module + attr_reader :name, :actions, :project_module, :contest_module def initialize(name, hash, options) @name = name @@ -105,6 +117,8 @@ module Redmine @require = options[:require] @read = options[:read] || false @project_module = options[:project_module] + @contest_module = options[:contest_module] + hash.each do |controller, actions| if actions.is_a? Array @actions << actions.collect {|action| "#{controller}/#{action}"}