@@ -164,96 +164,101 @@ class SettingsController(BaseController)
except Exception:
log.error(traceback.format_exc())
h.flash(_('Error occurred during updating '
'application settings'),
category='error')
if setting_id == 'visual':
application_form = ApplicationVisualisationForm()()
try:
form_result = application_form.to_python(dict(request.POST))
except formencode.Invalid, errors:
return htmlfill.render(
render('admin/settings/settings.html'),
defaults=errors.value,
errors=errors.error_dict or {},
prefix_error=False,
encoding="UTF-8"
)
#TODO: rewrite this to something less ugly
sett1 = RhodeCodeSetting.get_by_name_or_create('show_public_icon')
sett1.app_settings_value = \
form_result['rhodecode_show_public_icon']
Session().add(sett1)
sett2 = RhodeCodeSetting.get_by_name_or_create('show_private_icon')
sett2.app_settings_value = \
form_result['rhodecode_show_private_icon']
Session().add(sett2)
sett3 = RhodeCodeSetting.get_by_name_or_create('stylify_metatags')
sett3.app_settings_value = \
form_result['rhodecode_stylify_metatags']
Session().add(sett3)
sett4 = RhodeCodeSetting.get_by_name_or_create('repository_fields')
sett4.app_settings_value = \
form_result['rhodecode_repository_fields']
Session().add(sett4)
sett5 = RhodeCodeSetting.get_by_name_or_create('dashboard_items')
sett5.app_settings_value = \
form_result['rhodecode_dashboard_items']
Session().add(sett5)
sett6 = RhodeCodeSetting.get_by_name_or_create('show_version')
sett6.app_settings_value = \
form_result['rhodecode_show_version']
Session().add(sett6)
Session().commit()
set_rhodecode_config(config)
h.flash(_('Updated visualisation settings'),
category='success')
'visualisation settings'),
if setting_id == 'vcs':
application_form = ApplicationUiSettingsForm()()
sett = RhodeCodeUi.get_by_key('push_ssl')
sett.ui_value = form_result['web_push_ssl']
Session().add(sett)
sett = RhodeCodeUi.get_by_key('/')
sett.ui_value = form_result['paths_root_path']
#HOOKS
sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_UPDATE)
sett.ui_active = form_result['hooks_changegroup_update']
sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_REPO_SIZE)
sett.ui_active = form_result['hooks_changegroup_repo_size']
sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_PUSH)
sett.ui_active = form_result['hooks_changegroup_push_logger']
sett = RhodeCodeUi.get_by_key(RhodeCodeUi.HOOK_PULL)
sett.ui_active = form_result['hooks_outgoing_pull_logger']
@@ -228,96 +228,98 @@ class BaseVCSController(object):
# unlock if we have push from user who locked
make_lock = False
else:
# we're not the same user who locked, ban with 423 !
locked = True
if action == 'pull':
if repo.locked[0] and repo.locked[1]:
log.debug('Setting lock on repo %s by %s' % (repo, user))
make_lock = True
log.debug('Repository %s do not have locking enabled' % (repo))
log.debug('FINAL locking values make_lock:%s,locked:%s,locked_by:%s'
% (make_lock, locked, locked_by))
return make_lock, locked, locked_by
def __call__(self, environ, start_response):
start = time.time()
return self._handle_request(environ, start_response)
finally:
log = logging.getLogger('rhodecode.' + self.__class__.__name__)
log.debug('Request time: %.3fs' % (time.time() - start))
meta.Session.remove()
class BaseController(WSGIController):
def __before__(self):
"""
__before__ is called before controller methods and after __call__
c.rhodecode_version = __version__
c.rhodecode_instanceid = config.get('instance_id')
c.rhodecode_name = config.get('rhodecode_title')
c.use_gravatar = str2bool(config.get('use_gravatar'))
c.ga_code = config.get('rhodecode_ga_code')
# Visual options
c.visual = AttributeDict({})
rc_config = RhodeCodeSetting.get_app_settings()
## DB stored
c.visual.show_public_icon = str2bool(rc_config.get('rhodecode_show_public_icon'))
c.visual.show_private_icon = str2bool(rc_config.get('rhodecode_show_private_icon'))
c.visual.stylify_metatags = str2bool(rc_config.get('rhodecode_stylify_metatags'))
c.visual.dashboard_items = safe_int(rc_config.get('rhodecode_dashboard_items', 100))
c.visual.repository_fields = str2bool(rc_config.get('rhodecode_repository_fields'))
c.visual.show_version = str2bool(rc_config.get('rhodecode_show_version'))
## INI stored
self.cut_off_limit = int(config.get('cut_off_limit'))
c.repo_name = get_repo_slug(request) # can be empty
c.backends = BACKENDS.keys()
c.unread_notifications = NotificationModel()\
.get_unread_cnt_for_user(c.rhodecode_user.user_id)
self.sa = meta.Session
self.scm_model = ScmModel(self.sa)
"""Invoke the Controller"""
# WSGIController.__call__ dispatches to the Controller method
# the request is routed to. This routing information is
# available in environ['pylons.routes_dict']
self.ip_addr = _get_ip_addr(environ)
# make sure that we update permissions each time we call controller
api_key = request.GET.get('api_key')
cookie_store = CookieStoreWrapper(session.get('rhodecode_user'))
user_id = cookie_store.get('user_id', None)
username = get_container_username(environ, config)
auth_user = AuthUser(user_id, api_key, username, self.ip_addr)
request.user = auth_user
self.rhodecode_user = c.rhodecode_user = auth_user
if not self.rhodecode_user.is_authenticated and \
self.rhodecode_user.user_id is not None:
self.rhodecode_user.set_authenticated(
cookie_store.get('is_authenticated')
log.info('IP: %s User: %s accessed %s' % (
self.ip_addr, auth_user, safe_unicode(_get_access_path(environ)))
return WSGIController.__call__(self, environ, start_response)
class BaseRepoController(BaseController):
Base class for controllers responsible for loading all needed data for
repository loaded items are
c.rhodecode_repo: instance of scm repository
c.rhodecode_db_repo: instance of db
c.repository_followers: number of followers
c.repository_forks: number of forks
c.repository_following: weather the current user is following the current repo
@@ -614,96 +614,97 @@ class DbManage(object):
# check write access
elif not os.access(path, os.W_OK) and path_ok:
path_ok = False
log.error('No write permission to given path %s' % path)
if retries == 0:
sys.exit('max retries reached')
if not path_ok:
retries -= 1
return self.config_prompt(test_repo_path, retries)
real_path = os.path.normpath(os.path.realpath(path))
if real_path != os.path.normpath(path):
if not ask_ok(('Path looks like a symlink, Rhodecode will store '
'given path as %s ? [y/n]') % (real_path)):
log.error('Canceled by user')
sys.exit(-1)
return real_path
def create_settings(self, path):
self.create_ui_settings()
ui_config = [
('web', 'push_ssl', 'false'),
('web', 'allow_archive', 'gz zip bz2'),
('web', 'allow_push', '*'),
('web', 'baseurl', '/'),
('paths', '/', path),
#('phases', 'publish', 'false')
]
for section,key,value in ui_config:
ui_conf = RhodeCodeUi()
setattr(ui_conf, 'ui_section', section)
setattr(ui_conf, 'ui_key', key)
setattr(ui_conf, 'ui_value', value)
settings = [
('realm', 'RhodeCode authentication', unicode),
('title', 'RhodeCode', unicode),
('ga_code', '', unicode),
('show_public_icon', True, bool),
('show_private_icon', True, bool),
('stylify_metatags', False, bool),
('dashboard_items', 100, int),
('show_version', True, bool)
for key, val, type_ in settings:
sett = RhodeCodeSetting(key, val)
self.sa.add(sett)
self.create_ldap_options()
self.create_default_options()
log.info('created ui config')
def create_user(self, username, password, email='', admin=False):
log.info('creating user %s' % username)
UserModel().create_or_update(username, password, email,
firstname='RhodeCode', lastname='Admin',
active=True, admin=admin)
def create_default_user(self):
log.info('creating default user')
# create default user for handling default permissions.
UserModel().create_or_update(username='default',
password=str(uuid.uuid1())[:8],
email='anonymous@rhodecode.org',
firstname='Anonymous', lastname='User')
def create_permissions(self):
Creates all permissions defined in the system
# module.(access|create|change|delete)_[name]
# module.(none|read|write|admin)
log.info('creating permissions')
PermissionModel(self.sa).create_permissions()
def populate_default_permissions(self):
Populate default permissions. It will create only the default
permissions that are missing, and not alter already defined ones
log.info('creating default user permissions')
PermissionModel(self.sa).create_default_permissions(user=User.DEFAULT_USER)
@staticmethod
def check_waitress():
Function executed at the end of setup
if not __py_version__ >= (2, 6):
notify('Python2.5 detected, please switch '
@@ -241,96 +241,97 @@ def RepoFieldForm():
new_field_desc = v.UnicodeString(not_empty=False)
return _RepoFieldForm
def RepoForkForm(edit=False, old_data={}, supported_backends=BACKENDS.keys(),
repo_groups=[], landing_revs=[]):
class _RepoForkForm(formencode.Schema):
allow_extra_fields = True
filter_extra_fields = False
repo_name = All(v.UnicodeString(strip=True, min=1, not_empty=True),
v.SlugifyName())
repo_group = All(v.CanWriteGroup(),
v.OneOf(repo_groups, hideList=True))
repo_type = All(v.ValidForkType(old_data), v.OneOf(supported_backends))
description = v.UnicodeString(strip=True, min=1, not_empty=True)
private = v.StringBoolean(if_missing=False)
copy_permissions = v.StringBoolean(if_missing=False)
update_after_clone = v.StringBoolean(if_missing=False)
fork_parent_id = v.UnicodeString()
chained_validators = [v.ValidForkName(edit, old_data)]
landing_rev = v.OneOf(landing_revs, hideList=True)
return _RepoForkForm
def ApplicationSettingsForm():
class _ApplicationSettingsForm(formencode.Schema):
rhodecode_title = v.UnicodeString(strip=True, min=1, not_empty=True)
rhodecode_realm = v.UnicodeString(strip=True, min=1, not_empty=True)
rhodecode_ga_code = v.UnicodeString(strip=True, min=1, not_empty=False)
return _ApplicationSettingsForm
def ApplicationVisualisationForm():
class _ApplicationVisualisationForm(formencode.Schema):
rhodecode_show_public_icon = v.StringBoolean(if_missing=False)
rhodecode_show_private_icon = v.StringBoolean(if_missing=False)
rhodecode_stylify_metatags = v.StringBoolean(if_missing=False)
rhodecode_repository_fields = v.StringBoolean(if_missing=False)
rhodecode_lightweight_journal = v.StringBoolean(if_missing=False)
rhodecode_dashboard_items = v.UnicodeString()
rhodecode_show_version = v.StringBoolean(if_missing=False)
return _ApplicationVisualisationForm
def ApplicationUiSettingsForm():
class _ApplicationUiSettingsForm(formencode.Schema):
web_push_ssl = v.StringBoolean(if_missing=False)
paths_root_path = All(
v.ValidPath(),
v.UnicodeString(strip=True, min=1, not_empty=True)
hooks_changegroup_update = v.StringBoolean(if_missing=False)
hooks_changegroup_repo_size = v.StringBoolean(if_missing=False)
hooks_changegroup_push_logger = v.StringBoolean(if_missing=False)
hooks_outgoing_pull_logger = v.StringBoolean(if_missing=False)
extensions_largefiles = v.StringBoolean(if_missing=False)
extensions_hgsubversion = v.StringBoolean(if_missing=False)
extensions_hggit = v.StringBoolean(if_missing=False)
return _ApplicationUiSettingsForm
def DefaultPermissionsForm(repo_perms_choices, group_perms_choices,
user_group_perms_choices, create_choices,
repo_group_create_choices, user_group_create_choices,
fork_choices, register_choices, extern_activate_choices):
class _DefaultPermissionsForm(formencode.Schema):
filter_extra_fields = True
overwrite_default_repo = v.StringBoolean(if_missing=False)
overwrite_default_group = v.StringBoolean(if_missing=False)
overwrite_default_user_group = v.StringBoolean(if_missing=False)
anonymous = v.StringBoolean(if_missing=False)
default_repo_perm = v.OneOf(repo_perms_choices)
default_group_perm = v.OneOf(group_perms_choices)
default_user_group_perm = v.OneOf(user_group_perms_choices)
default_repo_create = v.OneOf(create_choices)
default_user_group_create = v.OneOf(user_group_create_choices)
#default_repo_group_create = v.OneOf(repo_group_create_choices) #not impl. yet
default_fork = v.OneOf(fork_choices)
default_register = v.OneOf(register_choices)
default_extern_activate = v.OneOf(extern_activate_choices)
return _DefaultPermissionsForm
@@ -89,96 +89,101 @@
</div>
<div class="input">
${h.text('rhodecode_title',size=30)}
<div class="field">
<div class="label">
<label for="rhodecode_realm">${_('HTTP authentication realm')}:</label>
${h.text('rhodecode_realm',size=30)}
<label for="rhodecode_ga_code">${_('Google Analytics code')}:</label>
${h.text('rhodecode_ga_code',size=30)}
<div class="buttons">
${h.submit('save',_('Save settings'),class_="ui-btn large")}
${h.reset('reset',_('Reset'),class_="ui-btn large")}
${h.end_form()}
<h3>${_('Visualisation settings')}</h3>
${h.form(url('admin_setting', setting_id='visual'),method='put')}
<div class="form">
<!-- fields -->
<div class="fields">
<div class="label label-checkbox">
<label>${_('General')}:</label>
<div class="checkboxes">
<div class="checkbox">
${h.checkbox('rhodecode_repository_fields','True')}
<label for="rhodecode_repository_fields">${_('Use repository extra fields')}</label>
<span class="help-block">${_('Allows storing additional customized fields per repository.')}</span>
${h.checkbox('rhodecode_show_version','True')}
<label for="rhodecode_show_version">${_('Show RhodeCode version')}</label>
<span class="help-block">${_('Shows or hides displayed version of RhodeCode in the footer')}</span>
<label for="rhodecode_realm">${_('Dashboard items')}:</label>
${h.text('rhodecode_dashboard_items',size=5)}
<span class="help-block">${_('Number of items displayed in lightweight dashboard before pagination is shown.')}</span>
<label>${_('Icons')}:</label>
${h.checkbox('rhodecode_show_public_icon','True')}
<label for="rhodecode_show_public_icon">${_('Show public repo icon on repositories')}</label>
${h.checkbox('rhodecode_show_private_icon','True')}
<label for="rhodecode_show_private_icon">${_('Show private repo icon on repositories')}</label>
<span class="help-block">${_('Show public/private icons next to repositories names')}</span>
<label>${_('Meta-Tagging')}:</label>
${h.checkbox('rhodecode_stylify_metatags','True')}
<label for="rhodecode_stylify_metatags">${_('Stylify recognised metatags:')}</label>
<div style="padding-left: 20px;">
<ul> <!-- Fix style here -->
<li>[featured] <span class="metatag" tag="featured">featured</span></li>
<li>[stale] <span class="metatag" tag="stale">stale</span></li>
<li>[dead] <span class="metatag" tag="dead">dead</span></li>
<li>[lang => lang] <span class="metatag" tag="lang" >lang</span></li>
<li>[license => License] <span class="metatag" tag="license"><a href="http://www.opensource.org/licenses/License" >License</a></span></li>
<li>[requires => Repo] <span class="metatag" tag="requires" >requires => <a href="#" >Repo</a></span></li>
<li>[recommends => Repo] <span class="metatag" tag="recommends" >recommends => <a href="#" >Repo</a></span></li>
<li>[see => URI] <span class="metatag" tag="see">see => <a href="#">URI</a> </span></li>
</ul>
## -*- coding: utf-8 -*-
<%inherit file="root.html"/>
<!-- HEADER -->
<div id="header-dd"></div>
<div id="header">
<div id="header-inner" class="title">
<div id="logo">
<h1><a href="${h.url('home')}">${c.rhodecode_name}</a></h1>
<!-- MENU -->
${self.page_nav()}
<!-- END MENU -->
${self.body()}
<!-- END HEADER -->
<!-- CONTENT -->
<div id="content">
<div class="flash_msg">
<% messages = h.flash.pop_messages() %>
% if messages:
<ul id="flash-messages">
% for message in messages:
<li class="${message.category}_msg">${message}</li>
% endfor
% endif
<div id="main">
${next.main()}
<!-- END CONTENT -->
<!-- FOOTER -->
<div id="footer">
<div id="footer-inner" class="title">
<div>
<p class="footer-link">
${_('Server instance: %s') % c.rhodecode_instanceid if c.rhodecode_instanceid else ''}
</p>
<p class="footer-link-right">
<a href="${h.url('rhodecode_official')}">RhodeCode ${c.rhodecode_version}</a>
<a href="${h.url('rhodecode_official')}">
RhodeCode
%if c.visual.show_version:
${c.rhodecode_version}
%endif
</a>
© 2010-${h.datetime.today().year} by Marcin Kuzminski and others
– <a href="${h.url('bugtracker')}">${_('Report a bug')}</a>
<!-- END FOOTER -->
### MAKO DEFS ###
<%def name="breadcrumbs()">
<div class="breadcrumbs">
${self.breadcrumbs_links()}
</%def>
<%def name="context_bar(current)">
${repo_context_bar(current)}
<%def name="admin_menu()">
<ul class="admin_menu">
<li>${h.link_to(_('Admin journal'),h.url('admin_home'),class_='journal ')}</li>
<li>${h.link_to(_('Repositories'),h.url('repos'),class_='repos')}</li>
<li>${h.link_to(_('Repository groups'),h.url('repos_groups'),class_='repos_groups')}</li>
<li>${h.link_to(_('Users'),h.url('users'),class_='users')}</li>
<li>${h.link_to(_('User groups'),h.url('users_groups'),class_='groups')}</li>
<li>${h.link_to(_('Permissions'),h.url('edit_permission',id='default'),class_='permissions')}</li>
<li>${h.link_to(_('LDAP'),h.url('ldap_home'),class_='ldap')}</li>
<li>${h.link_to(_('Defaults'),h.url('defaults'),class_='defaults')}</li>
<li class="last">${h.link_to(_('Settings'),h.url('admin_settings'),class_='settings')}</li>
<%def name="admin_menu_simple(repositories=None, repository_groups=None, user_groups=None)">
<ul>
%if repositories:
%if repository_groups:
%if user_groups:
Status change: