def revoke(self, redirect_url=None): v_id = request.params.get('id', None) if v_id is None: abort(401, "id of velruse account not specified") v = Velruse.by_id(v_id) if v is None: self._failure(_("You are trying to disconnect from a provider" " you are disconnected from already.")) return None elif not (v.user == c.user or h.has_permission("user.manage")): abort(403, _("You're not authorized to change %s's settings.") % c.user.id) else: v.delete_forever() model.meta.Session.commit() h.flash(_("You successfully disconnected from %(provider)s.") % {'provider': v.domain}, 'success') if redirect_url is None: redirect(h.entity_url(c.user, member='settings/login')) else: redirect(redirect_url)
def _available_badges(self): ''' Return the badges that are editable by a user. ''' c.groups = [{'permission': 'global.admin', 'label': _('In all instances'), 'show_label': True}] if c.instance: c.groups.append( {'permission': 'instance.admin', 'label': _('In instance "%s"') % c.instance.label, 'show_label': h.has_permission('global.admin')}) badges = {} if has('global.admin'): badges['global.admin'] = { 'instance': InstanceBadge.all(instance=None), 'user': UserBadge.all(instance=None), 'delegateable': DelegateableBadge.all(instance=None), 'category': CategoryBadge.all(instance=None), 'thumbnail': ThumbnailBadge.all(instance=None)} if has('instance.admin') and c.instance is not None: badges['instance.admin'] = { 'instance': InstanceBadge.all(instance=c.instance), 'user': UserBadge.all(instance=c.instance), 'delegateable': DelegateableBadge.all(instance=c.instance), 'category': CategoryBadge.all(instance=c.instance), 'thumbnail': ThumbnailBadge.all(instance=c.instance)} return badges
def delete(self, format='html'): watch = self.form_result.get('watch') require.watch.delete(watch) if watch.user != c.user and not h.has_permission('instance.admin'): abort(403, _("You're not authorized to delete %s's watchlist " "entries.") % watch.user.name) watch.delete() model.meta.Session.commit() redirect(h.entity_url(watch.entity))
def get_user_import_state(): """user import state This function can be used to generate state objects for formencode. """ class State(object): pass state = State() state.global_admin = has_permission('global.admin') return state
def revoke(self): require.user.edit(c.user) id = request.params.get('id') openid = model.OpenID.by_id(id) if not openid: abort(404, _("No OpenID with ID '%s' exists.") % id) page_user = openid.user if not (page_user == c.user or h.has_permission("user.manage")): abort(403, _("You're not authorized to change %s's settings.") % id) openid.delete() model.meta.Session.commit() redirect(h.entity_url(c.user, member='edit'))
def settings_menu(instance, current): return Menu.create(instance, current, OrderedDict([ ('general', (L_(u'General'), True, 'settings')), ('appearance', (L_('Appearance'),)), ('contents', (L_('Contents'),)), ('voting', (L_('Votings'),)), ('badges', (L_('Badges'),)), ('massmessage', (L_('Mass message service'), can.message.create(instance))), ('members_import', (_('Members import'), (h.has_permission('global.admin') or can.instance.authenticated_edit(instance)))) ]))
def index(self, format="html"): c.active_global_nav = 'instances' include_hidden = h.has_permission('global.admin') c.instance_pager = pager.solr_instance_pager(include_hidden) if format == 'json': return render_json(c.instance_pager) c.tile = tiles.instance.InstanceTile(c.instance) if format == 'overlay': return render("/instance/index.html", overlay=True) else: return render("/instance/index.html")
def settings_menu(cls, instance, current): class Menu(list): '''Subclass so we can attach attributes''' def url_for(self, value): current = [i for i in self if i['name'] == value] if not current: return ValueError('No Menu item named "%s"' % value) else: return current[0]['url'] def setting(name, label, allowed=True): return { 'name': name, 'url': settings_url(instance, name), 'label': label, 'allowed': allowed } settings = Menu( [{ 'name': 'general', 'url': h.instance.url(instance, member='settings'), 'label': L_('General') }, setting('appearance', L_('Appearance')), setting('contents', L_('Contents')), setting('voting', L_('Votings')), setting('badges', L_('Badges')), setting('members_import', L_('Members import'), allowed=(h.has_permission('global.admin') or can.instance.authenticated_edit(instance)))]) if current not in [i['name'] for i in settings]: raise ValueError('current ("%s") is no menu item' % current) for item in settings: item['class'] = '' if item.get('allowed') is None: item['allowed'] = True if current == item['name']: item['active'] = True item['class'] = 'active' settings.current = item return settings
def settings_menu(cls, instance, current): class Menu(list): '''Subclass so we can attach attributes''' def url_for(self, value): current = [i for i in self if i['name'] == value] if not current: return ValueError('No Menu item named "%s"' % value) else: return current[0]['url'] def setting(name, label, allowed=True): return {'name': name, 'url': settings_url(instance, name), 'label': label, 'allowed': allowed} settings = Menu([ {'name': 'general', 'url': h.instance.url(instance, member='settings'), 'label': L_('General')}, setting('appearance', L_('Appearance')), setting('contents', L_('Contents')), setting('voting', L_('Votings')), setting('badges', L_('Badges')), setting('massmessage', L_('Mass message service'), allowed=(can.message.create(instance))), setting('members_import', L_('Members import'), allowed=(h.has_permission('global.admin') or can.instance.authenticated_edit(instance)))]) if current not in [i['name'] for i in settings]: raise ValueError('current ("%s") is no menu item' % current) for item in settings: item['class'] = '' if item.get('allowed') is None: item['allowed'] = True if current == item['name']: item['active'] = True item['class'] = 'active' settings.current = item c.active_subheader_nav = 'settings' return settings
def settings_general_update(self, id): c.page_instance = self._get_current_instance(id) require.instance.edit(c.page_instance) updated = update_attributes(c.page_instance, self.form_result, ["description", "label", "hidden"]) if h.has_permission("global.admin"): auth_updated = update_attributes(c.page_instance, self.form_result, ["is_authenticated"]) updated = updated or auth_updated updated = updated or update_attributes(c.page_instance, self.form_result, ["default_group"]) locale = Locale(self.form_result.get("locale")) if locale and locale in i18n.LOCALES: if c.page_instance.locale != locale: c.page_instance.locale = locale updated = True return self.settings_result(updated, c.page_instance, "general")
def _get_common_fields(self, form_result): ''' return a tuple of (title, color, visible, description, impact, instance). ''' if h.has_permission('global.admin'): instance = form_result.get('instance') else: # instance only admins can only create/edit # badges inside the current instance instance = c.instance return (form_result.get('title').strip(), form_result.get('color').strip(), 'visible' in form_result, form_result.get('description').strip(), form_result.get('impact'), instance, )
def revoke(self): if not openid_login_allowed(): ret_abort(_("Removal not allowed, OpenID has been disabled on this installation"), code=403) require.user.edit(c.user) id = request.params.get('id') openid = model.OpenID.by_id(id) if not openid: abort(404, _("No OpenID with ID '%s' exists.") % id) page_user = openid.user if not (page_user == c.user or h.has_permission("user.manage")): abort(403, _("You're not authorized to change %s's settings.") % id) openid.delete() model.meta.Session.commit() h.flash(_("Successfully removed OpenID from account"), 'success') log.info("User %s revoked OpenID '%s'" % ( c.user.user_name, id)) redirect(h.entity_url(c.user, member='edit'))
def settings_menu(cls, instance, current): class Menu(list): """Subclass so we can attach attributes""" def url_for(self, value): current = [i for i in self if i["name"] == value] if not current: return ValueError('No Menu item named "%s"' % value) else: return current[0]["url"] def setting(name, label, allowed=True): return {"name": name, "url": settings_url(instance, name), "label": label, "allowed": allowed} settings = Menu( [ {"name": "general", "url": h.instance.url(instance, member="settings"), "label": L_("General")}, setting("appearance", L_("Appearance")), setting("contents", L_("Contents")), setting("voting", L_("Votings")), setting("badges", L_("Badges")), setting( "members_import", L_("Members import"), allowed=(h.has_permission("global.admin") or can.instance.authenticated_edit(instance)), ), ] ) if current not in [i["name"] for i in settings]: raise ValueError('current ("%s") is no menu item' % current) for item in settings: item["class"] = "" if item.get("allowed") is None: item["allowed"] = True if current == item["name"]: item["active"] = True item["class"] = "active" settings.current = item c.active_subheader_nav = "settings" return settings
def _set_parent_categories(self, exclude=None): local_categories = CategoryBadge.all_q(instance=c.instance) if exclude is not None: local_categories = filter(lambda c: not(c.is_ancester(exclude)), local_categories) c.local_category_parents = sorted( [(b.id, b.get_key()) for b in local_categories], key=lambda x: x[1]) if h.has_permission('global.admin'): global_categories = CategoryBadge.all_q(instance=None) if exclude is not None: global_categories = filter( lambda c: not(c.is_ancester(exclude)), global_categories) c.global_category_parents = sorted( [(b.id, b.get_key()) for b in global_categories], key=lambda x: x[1])
def settings_general_update(self, id): c.page_instance = self._get_current_instance(id) require.instance.edit(c.page_instance) updated = update_attributes(c.page_instance, self.form_result, ['description', 'label', 'hidden']) if h.has_permission('global.admin'): auth_updated = update_attributes(c.page_instance, self.form_result, ['is_authenticated']) updated = updated or auth_updated if (self.form_result.get('default_group').code in model.Group.INSTANCE_GROUPS): updated = updated or update_attributes( c.page_instance, self.form_result, ['default_group']) locale = Locale(self.form_result.get("locale")) if locale and locale in i18n.LOCALES: if c.page_instance.locale != locale: c.page_instance.locale = locale updated = True return self.settings_result(updated, c.page_instance, 'general')
def settings_general_update(self, id): c.page_instance = self._get_current_instance(id) require.instance.edit(c.page_instance) updated = update_attributes(c.page_instance, self.form_result, ['description', 'label', 'hidden']) if h.has_permission('global.admin'): auth_updated = update_attributes(c.page_instance, self.form_result, ['is_authenticated']) updated = updated or auth_updated if (self.form_result.get('default_group').code in model.Group.INSTANCE_GROUPS): updated = updated or update_attributes(c.page_instance, self.form_result, ['default_group']) locale = Locale(self.form_result.get("locale")) if locale and locale in i18n.LOCALES: if c.page_instance.locale != locale: c.page_instance.locale = locale updated = True return self.settings_result(updated, c.page_instance, 'general')