Project

General

Profile

RE: Webdav plugin » webdav_settings_controller.rb

Terence Mill, 2011-08-02 09:29

 
1
# Wiki Extensions plugin for Redmine
2
# Copyright (C) 2009  Haruyuki Iida
3
#
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License
6
# as published by the Free Software Foundation; either version 2
7
# of the License, or (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17

    
18
class WebdavSettingsController < ApplicationController
19
  unloadable
20
  layout 'base'
21

    
22
  before_filter :find_project, :authorize, :find_user
23

    
24
  def update    
25
    menus = params[:menus]
26

    
27
    files_enabled = (params[:setting][:files_enabled].to_i == 1)
28
    documents_enabled = (params[:setting][:documents_enabled].to_i == 1)
29
    subversion_enabled = (params[:setting][:subversion_enabled].to_i == 1)
30
    subversion_only = (params[:setting][:subversion_only].to_i == 1)
31
    macosx_write = (params[:setting][:macosx_write].to_i == 1)
32
    setting = WebdavSetting.find_or_create @project.id
33
    begin
34
      setting.transaction do
35
        setting.files_enabled = files_enabled
36
        setting.documents_enabled = documents_enabled
37
        setting.subversion_enabled = subversion_enabled
38
        setting.subversion_only = subversion_only
39
        setting.macosx_write = macosx_write
40
        setting.files_label = params[:setting][:files_label].empty? ? l(:files_label) : params[:setting][:files_label]
41
        setting.documents_label = params[:setting][:documents_label].empty? ? l(:documents_label) : params[:setting][:documents_label]
42
        setting.subversion_label = params[:setting][:subversion_label].empty? ? l(:subversion_label) : params[:setting][:subversion_label]
43
        setting.save!
44
      end
45
      flash[:notice] = l(:notice_successful_update)
46
    rescue
47
      flash[:error] = "Updating failed."
48
    end
49
    
50
    redirect_to :controller => 'projects', :action => "settings", :id => @project, :tab => 'webdav'
51
  end
52

    
53
  private
54
  def find_project
55
    # @project variable must be set before calling the authorize filter
56
    @project = Project.find(params[:id])
57
  end
58

    
59
  def find_user
60
    @user = User.current
61
  end
62
end
(3-3/3)