Beispiel #1
0
def init_search(endpoint, values):
    q = request.args.get("q")
    try:
        page = max(int(request.args.get('page', 1), 1))
    except:
        page = 1

    g.breadcrumb.append(
        BreadcrumbItem(label='"{}"'.format(q),
                       icon="search",
                       url=Endpoint('search.search_main', q=q)))

    page_kw = OrderedDict(q=q)
    object_types = request.args.getlist('object_type')

    if object_types:
        page_kw['object_type'] = object_types
        g.breadcrumb.append(
            BreadcrumbItem(label=' | '.join(
                friendly_fqcn(name) for name in object_types),
                           url=Endpoint('search.search_main', **page_kw)))

    if page > 1:
        g.breadcrumb.append(
            BreadcrumbItem(label=text_type(page),
                           url=Endpoint('search.search_main',
                                        page=page,
                                        **page_kw)))

    values['q'] = q
    values['page'] = page
Beispiel #2
0
def init_search(endpoint, values):
    q = request.args.get("q", "")
    try:
        page = max(int(request.args.get("page", 1)), 1)
    except Exception:
        page = 1

    g.breadcrumb.append(
        BreadcrumbItem(label=f'"{q}"',
                       icon="search",
                       url=Endpoint("search.search_main", q=q)))

    page_kw = OrderedDict(q=q)
    object_types = request.args.getlist("object_type")

    if object_types:
        page_kw["object_type"] = object_types
        g.breadcrumb.append(
            BreadcrumbItem(
                label=" | ".join(friendly_fqcn(name) for name in object_types),
                url=Endpoint("search.search_main", **page_kw),
            ))

    if page > 1:
        g.breadcrumb.append(
            BreadcrumbItem(
                label=str(page),
                url=Endpoint("search.search_main", page=page, **page_kw),
            ))

    values["q"] = q
    values["page"] = page
Beispiel #3
0
def init_wiki_values(endpoint, values):
    g.current_tab = "wiki"

    endpoint = Endpoint("wiki.index", community_id=g.community.slug)
    g.breadcrumb.append(BreadcrumbItem(label=_l("Wiki"), url=endpoint))

    title = request.args.get("title", "").strip()
    if title and title != "Home":
        url = Endpoint("wiki.page", community_id=g.community.slug, title=title)
        g.breadcrumb.append(BreadcrumbItem(label=title, url=url))
Beispiel #4
0
def init_wiki_values(endpoint, values):
    g.current_tab = 'wiki'

    endpoint = Endpoint('wiki.index', community_id=g.community.slug)
    g.breadcrumb.append(BreadcrumbItem(label=_l(u'Wiki'), url=endpoint))

    title = request.args.get('title', u'').strip()
    if title and title != 'Home':
        g.breadcrumb.append(
            BreadcrumbItem(label=title,
                           url=Endpoint('wiki.page',
                                        community_id=g.community.slug,
                                        title=title)))
Beispiel #5
0
def init_forum_values(endpoint, values):
    g.current_tab = 'forum'

    g.breadcrumb.append(
        BreadcrumbItem(label=_l(u'Conversations'),
                       url=Endpoint('forum.index',
                                    community_id=g.community.slug)))
Beispiel #6
0
def wizard_new_accounts():
    """Complete new emails information."""
    if request.method == "GET":
        return redirect(url_for(".members", community_id=g.community.slug))

    g.breadcrumb.append(
        BreadcrumbItem(
            label=_("Members"),
            url=Endpoint("communities.members", community_id=g.community.slug),
        )
    )

    wizard_emails = request.form.get("wizard-emails")
    wizard_accounts = json.loads(wizard_emails)

    wizard_existing_account = {}
    new_accounts = []

    for user in wizard_accounts:
        if user["status"] == "existing":
            wizard_existing_account[user["email"]] = user["role"]

        elif user["status"] == "new":
            new_accounts.append(user)

    existing_account = json.dumps(wizard_existing_account)

    return render_template(
        "community/wizard_new_accounts.html",
        existing_account=existing_account,
        new_accounts=new_accounts,
    )
Beispiel #7
0
    def register_panel(self, panel, app=None):
        state = self.app_state if app is None else app.extensions[self.name]
        if state.blueprint_registered:
            raise ValueError(
                "Extension already initialized for app, "
                "cannot add more panel", )

        state.panels.append(panel)
        panel.preferences = self
        rule = "/" + getattr(panel, 'path', panel.id)
        endpoint = panel.id
        abs_endpoint = 'preferences.{}'.format(endpoint)

        if hasattr(panel, 'get'):
            state.blueprint.add_url_rule(rule, endpoint, panel.get)
        if hasattr(panel, 'post'):
            endpoint += "_post"
            state.blueprint.add_url_rule(
                rule,
                endpoint,
                panel.post,
                methods=['POST'],
            )

        state.breadcrumb_items[abs_endpoint] = BreadcrumbItem(
            label=panel.label,
            icon=None,
            url=Endpoint(abs_endpoint),
        )
Beispiel #8
0
def init_document_values(endpoint, values):
    g.current_tab = 'documents'

    g.breadcrumb.append(
        BreadcrumbItem(label=_l(u'Documents'),
                       url=Endpoint('documents.index',
                                    community_id=g.community.slug)))
Beispiel #9
0
def init_forum_values(endpoint, values):
    g.current_tab = "forum"

    g.breadcrumb.append(
        BreadcrumbItem(
            label=_l("Conversations"),
            url=Endpoint("forum.index", community_id=g.community.slug),
        ))
Beispiel #10
0
def init_document_values(endpoint, values):
    g.current_tab = "documents"
    g.is_manager = is_manager()

    g.breadcrumb.append(
        BreadcrumbItem(
            label=_l("Documents"),
            url=Endpoint("documents.index", community_id=g.community.slug),
        ))
Beispiel #11
0
def pull_community(endpoint, values):
    """url_value_preprocessor function."""
    g.nav["active"] = "section:communities"
    g.breadcrumb.append(
        BreadcrumbItem(label=_l("Communities"), url=Endpoint("communities.index"))
    )

    try:
        slug = values.pop("community_id")
        community = Community.query.filter(Community.slug == slug).first()
        if community:
            g.community = CommunityPresenter(community)
            wall_url = Endpoint("wall.index", community_id=community.slug)
            breadcrumb_item = BreadcrumbItem(label=community.name, url=wall_url)
            g.breadcrumb.append(breadcrumb_item)
        else:
            raise NotFound()
    except KeyError:
        pass
Beispiel #12
0
def wizard_data_insertion():
    """Insert new members data into the community via emails or CSV file."""
    g.breadcrumb.append(
        BreadcrumbItem(
            label=_("Members"),
            url=Endpoint("communities.members", community_id=g.community.slug),
        )
    )

    return render_template("community/wizard_add_emails.html")
Beispiel #13
0
def members():
    g.breadcrumb.append(
        BreadcrumbItem(label=_(u'Members'),
                       url=Endpoint('communities.members',
                                    community_id=g.community.slug)))
    memberships = _members_query().all()

    return render_template("community/members.html",
                           seconds_since_epoch=seconds_since_epoch,
                           memberships=memberships,
                           csrf_token=csrf.field())
Beispiel #14
0
    def setup_blueprint(self, app):
        bp = self.app_state.blueprint = Blueprint(
            "preferences",
            __name__,
            template_folder='templates',
            url_prefix="/preferences",
        )

        # we need to delay blueprint registration to allow adding more panels during
        # initialization
        @signals.components_registered.connect_via(app)
        def register_bp(app):
            app.register_blueprint(bp)
            app.extensions[self.name].blueprint_registered = True

        self.app_state.root_breadcrumb_item = BreadcrumbItem(
            label=_('Preferences'),
            url=Endpoint('preferences.index'),
        )

        bp.url_value_preprocessor(self.build_breadcrumbs)

        @bp.context_processor
        def inject_menu():
            menu = []
            for panel in self.app_state.panels:
                if not panel.is_accessible():
                    continue
                endpoint = 'preferences.' + panel.id
                active = endpoint == request.endpoint
                entry = {
                    'endpoint': endpoint,
                    'label': panel.label,
                    'url': url_for(endpoint),
                    'active': active,
                }
                menu.append(entry)
            return dict(menu=menu)

        @bp.route("/")
        def index():
            """Index redirects to the first accessible panel."""

            # Work around unit test failure. FIXME.
            if current_user.is_anonymous:
                return "OK"

            for panel in self.app_state.panels:
                if panel.is_accessible():
                    return redirect(url_for("preferences." + panel.id))
            else:
                # Should not happen.
                raise InternalServerError()
Beispiel #15
0
    def setup_blueprint(self, app: Flask) -> None:
        bp = self.app_state.blueprint = Blueprint(
            "preferences",
            __name__,
            template_folder="templates",
            url_prefix="/preferences",
        )

        # we need to delay blueprint registration to allow adding more panels during
        # initialization
        @signals.components_registered.connect_via(app)
        def register_bp(app: Flask) -> None:
            app.register_blueprint(bp)
            app.extensions[self.name].blueprint_registered = True

        self.app_state.root_breadcrumb_item = BreadcrumbItem(
            label=_("Preferences"), url=Endpoint("preferences.index")
        )

        bp.url_value_preprocessor(self.build_breadcrumbs)

        @bp.context_processor
        def inject_menu() -> Dict[str, List[Dict[str, Any]]]:
            menu = []
            for panel in self.app_state.panels:
                if not panel.is_accessible():
                    continue
                endpoint = "preferences." + panel.id
                active = endpoint == request.endpoint
                entry = {
                    "endpoint": endpoint,
                    "label": panel.label,
                    "url": url_for(endpoint),
                    "active": active,
                }
                menu.append(entry)
            return {"menu": menu}

        @bp.route("/")
        def index():
            """Index redirects to the first accessible panel."""

            # Work around unit test failure. FIXME.
            if current_user.is_anonymous:
                return "OK"

            for panel in self.app_state.panels:
                if panel.is_accessible():
                    return redirect(url_for("preferences." + panel.id))

            # Should not happen.
            raise InternalServerError()
Beispiel #16
0
class DefaultConfig:
    # Seriously: this need to be changed in production
    SECRET_KEY = "CHANGEME"

    # Need to be explicitly defined in production configs
    PRODUCTION = False

    # Security (see
    # https://blog.miguelgrinberg.com/post/cookie-security-for-flask-applications)
    # NB: SESSION_COOKIE_* are now set up by Talisman
    WTF_CSRF_ENABLED = True

    # Babel
    BABEL_ACCEPT_LANGUAGES = ["en"]
    DEFAULT_COUNTRY = None

    # Celery
    CELERYD_MAX_TASKS_PER_CHILD = 1000
    CELERY_ACCEPT_CONTENT = ["pickle", "json", "msgpack", "yaml"]
    CELERY_TIMEZONE = LOCALTZ

    # Sentry
    SENTRY_SDK_URL = "https://browser.sentry-cdn.com/4.5.3/bundle.min.js"

    # SQLAlchemy
    SQLALCHEMY_POOL_RECYCLE = 1800  # 30min. default value in flask_sa is None
    SQLALCHEMY_TRACK_MODIFICATIONS = False

    # Debug settings (override default)
    DEBUG_TB_INTERCEPT_REDIRECTS = False

    # Abilian-specific
    PRIVATE_SITE = False
    PLUGINS = ()
    ADMIN_PANELS = (
        "abilian.web.admin.panels.dashboard.DashboardPanel",
        "abilian.web.admin.panels.audit.AuditPanel",
        "abilian.web.admin.panels.login_sessions.LoginSessionsPanel",
        "abilian.web.admin.panels.settings.SettingsPanel",
        "abilian.web.admin.panels.users.UsersPanel",
        "abilian.web.admin.panels.groups.GroupsPanel",
        "abilian.web.admin.panels.sysinfo.SysinfoPanel",
        "abilian.web.admin.panels.impersonate.ImpersonatePanel",
        "abilian.services.vocabularies.admin.VocabularyPanel",
        "abilian.web.tags.admin.TagPanel",
    )
    LOGO_URL = Endpoint("abilian_static",
                        filename="img/logo-abilian-32x32.png")
    ABILIAN_UPSTREAM_INFO_ENABLED = False  # upstream info extension
    TRACKING_CODE = ""  # tracking code for web analytics to insert before </body>
    MAIL_ADDRESS_TAG_CHAR = None
Beispiel #17
0
def wizard_check_data():
    """Filter and detect existing members, existing accounts and new emails."""
    if request.method == "GET":
        return redirect(url_for(".members", community_id=g.community.slug))

    g.breadcrumb.append(
        BreadcrumbItem(
            label=_("Members"),
            url=Endpoint("communities.members", community_id=g.community.slug),
        )
    )

    is_csv = False
    if request.form.get("wizard-emails"):
        wizard_emails = request.form.get("wizard-emails").split(",")
        existing_accounts_object, existing_members_objects, final_email_list = wizard_extract_data(
            wizard_emails
        )
        final_email_list_json = json.dumps(final_email_list)
    else:
        is_csv = True
        accounts_data = wizard_read_csv(request.files["csv_file"])
        if not accounts_data:
            flash(_("To add new members, please follow the CSV file model."), "warning")
            return redirect(
                url_for(".wizard_data_insertion", community_id=g.community.slug)
            )

        existing_accounts, existing_members_objects, final_email_list = wizard_extract_data(
            accounts_data, is_csv=True
        )
        existing_accounts_object = existing_accounts["account_objects"]
        existing_accounts_csv_roles = existing_accounts["csv_roles"]
        final_email_list_json = json.dumps(final_email_list)

    if not final_email_list:
        flash(_("No new members were found"), "warning")
        return redirect(
            url_for(".wizard_data_insertion", community_id=g.community.slug)
        )

    ctx = {
        "existing_accounts_object": existing_accounts_object,
        "csv_roles": existing_accounts_csv_roles if is_csv else False,
        "wizard_emails": final_email_list_json,
        "existing_members_objects": existing_members_objects,
    }
    return render_template("community/wizard_check_members.html", **ctx)
Beispiel #18
0
def members():
    g.breadcrumb.append(
        BreadcrumbItem(
            label=_("Members"),
            url=Endpoint("communities.members", community_id=g.community.slug),
        )
    )
    memberships = _members_query().all()
    community_threads_users = [thread.creator for thread in g.community.threads]
    threads_count = Counter(community_threads_users)

    ctx = {
        "seconds_since_epoch": seconds_since_epoch,
        "is_manager": is_manager(user=current_user),
        "memberships": memberships,
        "threads_count": threads_count,
    }
    return render_template("community/members.html", **ctx)
Beispiel #19
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)
        )
Beispiel #20
0
    def register_panel(
        self, panel: PreferencePanel, app: Optional[Flask] = None
    ) -> None:
        state = self.app_state if app is None else app.extensions[self.name]
        if state.blueprint_registered:
            raise ValueError(
                "Extension already initialized for app, " "cannot add more panel"
            )

        state.panels.append(panel)
        panel.preferences = self
        rule = "/" + getattr(panel, "path", panel.id)
        endpoint = panel.id
        abs_endpoint = f"preferences.{endpoint}"

        if hasattr(panel, "get"):
            state.blueprint.add_url_rule(rule, endpoint, panel.get)
        if hasattr(panel, "post"):
            endpoint += "_post"
            state.blueprint.add_url_rule(rule, endpoint, panel.post, methods=["POST"])

        state.breadcrumb_items[abs_endpoint] = BreadcrumbItem(
            label=panel.label, icon=None, url=Endpoint(abs_endpoint)
        )
Beispiel #21
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))
Beispiel #22
0
                  'abilian.web.admin.panels.sysinfo.SysinfoPanel',
                  'abilian.services.vocabularies.admin.VocabularyPanel',
                  'abilian.web.tags.admin.TagPanel'),
    CELERYD_MAX_TASKS_PER_CHILD=1000,
    CELERY_ACCEPT_CONTENT=['pickle', 'json', 'msgpack', 'yaml'],
    CELERY_TIMEZONE=LOCALTZ,
    SENTRY_USER_ATTRS=('email', 'first_name', 'last_name'),
    SENTRY_INSTALL_CLIENT_JS=True,  # also install client JS
    # TODO: upgrade to SENTRY_JS_VERSION='3.5.1',
    SENTRY_JS_VERSION='1.1.22',
    # TODO: remove, not needed for recent sentry-js
    SENTRY_JS_PLUGINS=('console', 'jquery', 'native', 'require'),
    SESSION_COOKIE_NAME=None,
    SQLALCHEMY_POOL_RECYCLE=1800,  # 30min. default value in flask_sa is None
    SQLALCHEMY_TRACK_MODIFICATIONS=False,
    LOGO_URL=Endpoint('abilian_static', filename='img/logo-abilian-32x32.png'),
    ABILIAN_UPSTREAM_INFO_ENABLED=False,  # upstream info extension
    TRACKING_CODE_SNIPPET='',  # tracking code to insert before </body>
    MAIL_ADDRESS_TAG_CHAR=None)
default_config = ImmutableDict(default_config)


class Application(Flask, ServiceManager, PluginManager):
    """Base application class. Extend it in your own app.
    """
    default_config = default_config

    #: Custom apps may want to always load some plugins: list them here.
    APP_PLUGINS = ('abilian.web.search', 'abilian.web.tags',
                   'abilian.web.comments', 'abilian.web.uploads',
                   'abilian.web.attachments')
Beispiel #23
0
class DefaultConfig:
    NAME = "DEFAULT"
    PRODUCTION = False

    # FIXME later
    WTF_CSRF_ENABLED = False

    CONTENT_SECURITY_POLICY = CONTENT_SECURITY_POLICY

    # Flask config
    PERMANENT_SESSION_LIFETIME = timedelta(days=1)
    SECRET_KEY = "tototiti"

    # abilian-core config
    SITE_NAME = "Lab&Co Sorbonne Université"
    PRIVATE_SITE = False
    MAIL_ASCII_ATTACHMENTS = True
    ANTIVIRUS_CHECK_REQUIRED = True
    LOGO_URL = Endpoint("static", filename="img/logo_carre_32px.jpg")
    FAVICO_URL = Endpoint("static", filename="img/logo-su-square.png")

    MAIL_SENDER = "*****@*****.**"
    MAIL_SUPPRESS_SEND = True

    CELERYBEAT_SCHEDULE: dict[Any, Any] = {}
    #     # Executes every day at 6 A.M
    #     "add-every-monday-morning": {
    #         "task": "tasks.add",
    #         "schedule": crontab(hour=6, minute=0),
    #     }
    # }

    # Babel config
    BABEL_ACCEPT_LANGUAGES = ("fr", )
    BABEL_DEFAULT_TIMEZONE = "Europe/Paris"

    # Celery config
    REDIS_URI = "redis://localhost:6379/1"
    BROKER_URL = "redis://localhost:6379/0"
    CELERYD_PREFETCH_MULTIPLIER = 1
    CELERY_ALWAYS_EAGER = True
    CELERY_EAGER_PROPAGATES_EXCEPTIONS = True
    CELERY_RESULT_BACKEND = "redis://localhost:6379/0"

    # Persistence
    SQLALCHEMY_DATABASE_URI = "postgresql+psycopg2://localhost/labster"

    MAIL_SERVER = "localhost"

    # APISPEC_SWAGGER_URL = "/labster-api"
    # APISPEC_SWAGGER_UI_URL = "/labster-api-ui"
    OPENAPI_VERSION = "3.0.2"

    # Auth
    CAS_SERVER = "https://auth.sorbonne-universite.fr/cas/"
    ALLOW_BACKDOOR = False

    RESTHEART_URL = "http://localhost:18080/db"
    RESTHEART_AUTH = ("admin", "DfgV0UYgwdMM")

    # Logs
    LOG_DB = "data/log.db"
Beispiel #24
0
 def breadcrumb(self):
     return BreadcrumbItem(
         label=_("Settings"),
         icon="cog",
         url=Endpoint("communities.settings", community_id=g.community.slug),
     )
Beispiel #25
0
        "abilian.web.admin.panels.impersonate.ImpersonatePanel",
        "abilian.services.vocabularies.admin.VocabularyPanel",
        "abilian.web.tags.admin.TagPanel",
    ),
    CELERYD_MAX_TASKS_PER_CHILD=1000,
    CELERY_ACCEPT_CONTENT=["pickle", "json", "msgpack", "yaml"],
    CELERY_TIMEZONE=LOCALTZ,
    SENTRY_USER_ATTRS=("email", "first_name", "last_name"),
    SENTRY_INSTALL_CLIENT_JS=True,  # also install client JS
    SENTRY_JS_VERSION="1.1.22",
    # TODO: remove, not needed for recent sentry-js
    SENTRY_JS_PLUGINS=("console", "jquery", "native", "require"),
    SESSION_COOKIE_NAME=None,
    SQLALCHEMY_POOL_RECYCLE=1800,  # 30min. default value in flask_sa is None
    SQLALCHEMY_TRACK_MODIFICATIONS=False,
    LOGO_URL=Endpoint("abilian_static", filename="img/logo-abilian-32x32.png"),
    ABILIAN_UPSTREAM_INFO_ENABLED=False,  # upstream info extension
    TRACKING_CODE_SNIPPET="",  # tracking code to insert before </body>
    MAIL_ADDRESS_TAG_CHAR=None,
)
default_config = ImmutableDict(default_config)

# def configure_redis(app):
#     redis.init_app(app)
#
#
# def configure_queue(app):
#     queue.init_app(app, db, sentry)
#
#
# def configure_sentry(app):
Beispiel #26
0
 def breadcrumb(self):
     return BreadcrumbItem(label=_(u'Settings'),
                           icon='cog',
                           url=Endpoint('communities.settings',
                                        community_id=g.community.slug))