comparison rhodecode/controllers/admin/auth_settings.py @ 4116:ffd45b185016 rhodecode-2.2.5-gpl

Imported some of the GPLv3'd changes from RhodeCode v2.2.5. This imports changes between changesets 21af6c4eab3d and 6177597791c2 in RhodeCode's original repository, including only changes to Python files and HTML. RhodeCode clearly licensed its changes to these files under GPLv3 in their /LICENSE file, which states the following: The Python code and integrated HTML are licensed under the GPLv3 license. (See: https://code.rhodecode.com/rhodecode/files/v2.2.5/LICENSE or http://web.archive.org/web/20140512193334/https://code.rhodecode.com/rhodecode/files/f3b123159901f15426d18e3dc395e8369f70ebe0/LICENSE for an online copy of that LICENSE file) Conservancy reviewed these changes and confirmed that they can be licensed as a whole to the Kallithea project under GPLv3-only. While some of the contents committed herein are clearly licensed GPLv3-or-later, on the whole we must assume the are GPLv3-only, since the statement above from RhodeCode indicates that they intend GPLv3-only as their license, per GPLv3ยง14 and other relevant sections of GPLv3.
author Bradley M. Kuhn <bkuhn@sfconservancy.org>
date Wed, 02 Jul 2014 19:03:13 -0400
parents
children 7e5f8c12a3fc
comparison
equal deleted inserted replaced
4115:8b7294a804a0 4116:ffd45b185016
1 # -*- coding: utf-8 -*-
2 # This program is free software: you can redistribute it and/or modify
3 # it under the terms of the GNU General Public License as published by
4 # the Free Software Foundation, either version 3 of the License, or
5 # (at your option) any later version.
6 #
7 # This program is distributed in the hope that it will be useful,
8 # but WITHOUT ANY WARRANTY; without even the implied warranty of
9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 # GNU General Public License for more details.
11 #
12 # You should have received a copy of the GNU General Public License
13 # along with this program. If not, see <http://www.gnu.org/licenses/>.
14 """
15 rhodecode.controllers.admin.auth_settings
16 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
17
18 pluggable authentication controller for RhodeCode
19
20 :created_on: Nov 26, 2010
21 :author: akesterson
22 """
23
24 import pprint
25 import logging
26 import formencode.htmlfill
27 import traceback
28
29 from pylons import request, response, session, tmpl_context as c, url
30 from pylons.controllers.util import abort, redirect
31 from pylons.i18n.translation import _
32
33 from sqlalchemy.exc import DatabaseError
34
35 from rhodecode.lib import helpers as h
36 from rhodecode.lib.compat import json, formatted_json
37 from rhodecode.lib.base import BaseController, render
38 from rhodecode.lib.auth import LoginRequired, HasPermissionAllDecorator
39 from rhodecode.lib import auth_modules
40 from rhodecode.model.forms import AuthSettingsForm
41 from rhodecode.model.db import RhodeCodeSetting
42 from rhodecode.model.meta import Session
43
44 log = logging.getLogger(__name__)
45
46
47 class AuthSettingsController(BaseController):
48
49 @LoginRequired()
50 @HasPermissionAllDecorator('hg.admin')
51 def __before__(self):
52 super(AuthSettingsController, self).__before__()
53
54 def __load_defaults(self):
55 c.available_plugins = [
56 'rhodecode.lib.auth_modules.auth_rhodecode',
57 'rhodecode.lib.auth_modules.auth_container',
58 'rhodecode.lib.auth_modules.auth_ldap',
59 'rhodecode.lib.auth_modules.auth_crowd',
60 ]
61 c.enabled_plugins = RhodeCodeSetting.get_auth_plugins()
62
63 def index(self, defaults=None, errors=None, prefix_error=False):
64 self.__load_defaults()
65 _defaults = {}
66 # default plugins loaded
67 formglobals = {
68 "auth_plugins": ["rhodecode.lib.auth_modules.auth_rhodecode"]
69 }
70 formglobals.update(RhodeCodeSetting.get_auth_settings())
71 formglobals["plugin_settings"] = {}
72 formglobals["auth_plugins_shortnames"] = {}
73 _defaults["auth_plugins"] = formglobals["auth_plugins"]
74
75 for module in formglobals["auth_plugins"]:
76 plugin = auth_modules.loadplugin(module)
77 plugin_name = plugin.name
78 formglobals["auth_plugins_shortnames"][module] = plugin_name
79 formglobals["plugin_settings"][module] = plugin.plugin_settings()
80 for v in formglobals["plugin_settings"][module]:
81 fullname = ("auth_" + plugin_name + "_" + v["name"])
82 if "default" in v:
83 _defaults[fullname] = v["default"]
84 # Current values will be the default on the form, if there are any
85 setting = RhodeCodeSetting.get_by_name(fullname)
86 if setting:
87 _defaults[fullname] = setting.app_settings_value
88 # we want to show , seperated list of enabled plugins
89 _defaults['auth_plugins'] = ','.join(_defaults['auth_plugins'])
90 if defaults:
91 _defaults.update(defaults)
92
93 formglobals["defaults"] = _defaults
94 # set template context variables
95 for k, v in formglobals.iteritems():
96 setattr(c, k, v)
97
98 log.debug(pprint.pformat(formglobals, indent=4))
99 log.debug(formatted_json(defaults))
100 return formencode.htmlfill.render(
101 render('admin/auth/auth_settings.html'),
102 defaults=_defaults,
103 errors=errors,
104 prefix_error=prefix_error,
105 encoding="UTF-8",
106 force_defaults=True,
107 )
108
109 def auth_settings(self):
110 """POST create and store auth settings"""
111 self.__load_defaults()
112 _form = AuthSettingsForm(c.enabled_plugins)()
113 log.debug("POST Result: %s" % formatted_json(dict(request.POST)))
114
115 try:
116 form_result = _form.to_python(dict(request.POST))
117 for k, v in form_result.items():
118 if k == 'auth_plugins':
119 # we want to store it comma separated inside our settings
120 v = ','.join(v)
121 log.debug("%s = %s" % (k, str(v)))
122 setting = RhodeCodeSetting.create_or_update(k, v)
123 Session().add(setting)
124 Session().commit()
125 h.flash(_('Auth settings updated successfully'),
126 category='success')
127 except formencode.Invalid, errors:
128 log.error(traceback.format_exc())
129 e = errors.error_dict or {}
130 return self.index(
131 defaults=errors.value,
132 errors=e,
133 prefix_error=False)
134 except Exception:
135 log.error(traceback.format_exc())
136 h.flash(_('error occurred during update of auth settings'),
137 category='error')
138
139 return redirect(url('auth_home'))