示例#1
0
    def register_panel(self, panel: Any) -> None:
        if self.app:
            raise ValueError(
                "Extension already initialized for app, cannot add more" " panel"
            )

        self.panels.append(panel)
        panel.admin = self
        rule = "/" + panel.id
        endpoint = nav_id = panel.id
        abs_endpoint = f"admin.{endpoint}"

        if hasattr(panel, "get"):
            self.blueprint.add_url_rule(rule, endpoint, panel.get)
            self._panels_endpoints[abs_endpoint] = panel
        if hasattr(panel, "post"):
            post_endpoint = endpoint + "_post"
            self.blueprint.add_url_rule(
                rule, post_endpoint, panel.post, methods=["POST"]
            )
            self._panels_endpoints["admin." + post_endpoint] = panel

        panel.install_additional_rules(
            self.get_panel_url_rule_adder(panel, rule, endpoint)
        )

        nav = NavItem(
            "admin:panel",
            nav_id,
            title=panel.label,
            icon=panel.icon,
            endpoint=abs_endpoint,
        )
        self.nav_root.append(nav)
        self.nav_paths[abs_endpoint] = nav.path
        self.breadcrumb_items[panel] = BreadcrumbItem(
            label=panel.label, icon=panel.icon, url=Endpoint(abs_endpoint)
        )
示例#2
0
    def register_panel(self, panel):
        if self.app:
            raise ValueError(
                'Extension already initialized for app, cannot add more'
                ' panel')

        self.panels.append(panel)
        panel.admin = self
        rule = "/" + panel.id
        endpoint = nav_id = panel.id
        abs_endpoint = 'admin.{}'.format(endpoint)

        if hasattr(panel, 'get'):
            self.blueprint.add_url_rule(rule, endpoint, panel.get)
            self._panels_endpoints[abs_endpoint] = panel
        if hasattr(panel, 'post'):
            post_endpoint = endpoint + "_post"
            self.blueprint.add_url_rule(rule,
                                        post_endpoint,
                                        panel.post,
                                        methods=['POST'])
            self._panels_endpoints['admin.' + post_endpoint] = panel

        panel.install_additional_rules(
            self.get_panel_url_rule_adder(panel, rule, endpoint))

        nav = NavItem('admin:panel',
                      nav_id,
                      title=panel.label,
                      icon=panel.icon,
                      divider=False,
                      endpoint=abs_endpoint)
        self.nav_root.append(nav)
        self.nav_paths[abs_endpoint] = nav.path
        self.breadcrumb_items[panel] = BreadcrumbItem(
            label=panel.label, icon=panel.icon, url=Endpoint(abs_endpoint))
示例#3
0
        endpoint = self.endpoint
        if endpoint:
            return endpoint
        else:
            return url_for("%s.index" % self.name)

    def is_current(self):
        return g.current_tab == self.name


_actions = (
    # Navigation
    NavItem(
        "section",
        "communities",
        title=_l("Communities"),
        url=lambda context: url_for_orig("communities.index"),
        condition=lambda ctx: current_user.is_authenticated,
    ),
    # Tabs
    CommunityTabAction("communities:tabs", "wall", _l("Activities")),
    CommunityTabAction(
        "communities:tabs",
        "documents",
        _l("Documents"),
        condition=lambda ctx: g.community.has_documents,
    ),
    CommunityTabAction(
        "communities:tabs",
        "wiki",
        _l("Wiki"),
示例#4
0
from werkzeug.exceptions import InternalServerError

from abilian.core import signals
from abilian.core.extensions import db
from abilian.i18n import _, _l
from abilian.services.auth.service import user_menu
from abilian.services.base import Service, ServiceState
from abilian.web.action import Endpoint
from abilian.web.nav import BreadcrumbItem, NavItem

from .models import UserPreference

_PREF_NAV_ITEM = NavItem(
    'user',
    'preferences',
    title=_l('Preferences'),
    icon='cog',
    url=lambda context: request.url_root + 'preferences',
    condition=lambda context: not current_user.is_anonymous,
)

user_menu.insert(0, _PREF_NAV_ITEM)


class PreferenceState(ServiceState):
    panels = None
    blueprint = None
    blueprint_registered = False

    def __init__(self, *args, **kwargs):
        ServiceState.__init__(self, *args, **kwargs)
        self.panels = []
示例#5
0
user_menu = NavGroup(
    "user",
    "authenticated",
    title=lambda c: current_user.name,
    icon=DynamicIcon(
        endpoint=_user_photo_endpoint,
        css="avatar",
        size=20,
        url_args=_user_photo_icon_args,
    ),
    condition=is_authenticated,
    # pyre-fixme[6]: Expected `Tuple[]` for 6th param but got `Tuple[NavItem]`.
    items=(NavItem(
        "user",
        "logout",
        title=_l("Logout"),
        icon="log-out",
        url=lambda context: url_for("login.logout"),
        divider=True,
    ), ),
)

_ACTIONS = (
    NavItem(
        "user",
        "login",
        title=_l("Login"),
        icon="log-in",
        url=lambda context: url_for("login.login_form"),
        condition=is_anonymous,
    ),
    user_menu,
示例#6
0
    from abilian.web.views import images  # late import avoid circular import
    return images.user_url_args(current_user, max(icon.width, icon.height))[1]


user_menu = NavGroup('user',
                     'authenticated',
                     title=lambda c: current_user.name,
                     icon=DynamicIcon(endpoint=_user_photo_endpoint,
                                      css='avatar',
                                      size=20,
                                      url_args=_user_photo_icon_args),
                     condition=is_authenticated,
                     items=(NavItem(
                         'user',
                         'logout',
                         title=_l(u'Logout'),
                         icon='log-out',
                         url=lambda context: url_for('login.logout'),
                         divider=True), ))

_ACTIONS = (
    NavItem('user',
            'login',
            title=_l(u'Login'),
            icon='log-in',
            url=lambda context: url_for('login.login_form'),
            condition=is_anonymous),
    user_menu,
)

示例#7
0
from abilian.core.extensions import csrf
from abilian.i18n import _l
from abilian.sbe.apps.social.views.social import social
from abilian.sbe.extension import sbe
from abilian.web.action import actions
from abilian.web.nav import NavItem
from abilian.web.util import url_for

# from abilian.cli import *  # noqa

__all__ = ["create_app"]

logger = logging.getLogger(__name__)

HOME_ACTION = NavItem("section",
                      "home",
                      title=_l("Home"),
                      endpoint="social.home")


class Config(metaclass=MetaFlaskEnv):
    ENV_PREFIX = "FLASK_"

    MAIL_ASCII_ATTACHMENTS = True
    # False: it's ok if antivirus task was run but service
    # couldn't get a result
    ANTIVIRUS_CHECK_REQUIRED = True
    BABEL_ACCEPT_LANGUAGES = ("fr", "en")

    CONTENT_SECURITY_POLICY = {
        "default-src":
        "'self'",
示例#8
0
from abilian.i18n import _, _l
from abilian.services.auth.service import user_menu
from abilian.services.base import Service, ServiceState
from abilian.services.preferences.panel import PreferencePanel
from abilian.web.action import Endpoint
from abilian.web.nav import BreadcrumbItem, NavItem

from .models import UserPreference

if TYPE_CHECKING:
    from abilian.app import Application

_PREF_NAV_ITEM = NavItem(
    "user",
    "preferences",
    title=_l("Preferences"),
    icon="cog",
    url=lambda context: request.url_root + "preferences",
    condition=lambda context: not current_user.is_anonymous,
)

user_menu.insert(0, _PREF_NAV_ITEM)


class PreferenceState(ServiceState):
    panels: List["PreferencePanel"]
    blueprint: Blueprint
    blueprint_registered: bool

    def __init__(self, service: "PreferenceService", *args: Any, **kwargs: Any) -> None:
        super().__init__(service, *args, **kwargs)
        self.panels = []
示例#9
0
        endpoint = self.endpoint
        if endpoint:
            return endpoint
        else:
            return url_for("%s.index" % self.name)

    def is_current(self):
        return g.current_tab == self.name


_actions = (
    # Navigation
    NavItem('section',
            'communities',
            title=_l(u'Communities'),
            url=lambda context: url_for_orig('communities.index'),
            condition=lambda ctx: current_user.is_authenticated),
    # Tabs
    CommunityTabAction('communities:tabs', 'wall', _l(u'Activities')),
    CommunityTabAction('communities:tabs',
                       'documents',
                       _l(u'Documents'),
                       condition=lambda ctx: g.community.has_documents),
    CommunityTabAction('communities:tabs',
                       'wiki',
                       _l(u'Wiki'),
                       condition=lambda ctx: g.community.has_wiki),
    CommunityTabAction('communities:tabs',
                       'forum',
                       _l(u'Conversations'),