Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add draft mode for contributions/timetable #4095

Merged
merged 9 commits into from Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion indico/modules/events/abstracts/__init__.py
Expand Up @@ -120,9 +120,11 @@ def _get_notification_placeholders(sender, **kwargs):
def _extend_event_menu(sender, **kwargs):
from indico.modules.events.abstracts.util import has_user_tracks
from indico.modules.events.layout.util import MenuEntryData
from indico.modules.events.contributions import contribution_settings

def _boa_visible(event):
return config.LATEX_ENABLED and event.has_feature('abstracts')
return (config.LATEX_ENABLED and event.has_feature('abstracts')
and contribution_settings.get(event, 'published'))

def _reviewing_area_visible(event):
if not session.user or not event.has_feature('abstracts'):
Expand Down
7 changes: 7 additions & 0 deletions indico/modules/events/abstracts/controllers/boa.py
Expand Up @@ -15,6 +15,7 @@
from indico.modules.events.abstracts.forms import BOASettingsForm
from indico.modules.events.abstracts.settings import boa_settings
from indico.modules.events.abstracts.util import clear_boa_cache, create_boa, create_boa_tex
from indico.modules.events.contributions import contribution_settings
from indico.util.i18n import _
from indico.web.flask.util import send_file
from indico.web.forms.base import FormDefaults
Expand All @@ -37,6 +38,12 @@ def _process(self):
class RHExportBOA(RHAbstractsBase):
"""Export the book of abstracts"""

def _check_access(self):
RHAbstractsBase._check_access(self)
published = contribution_settings.get(self.event, 'published')
if not published:
raise NotFound(_("The contributions of this event have not been published yet"))

def _process(self):
if not config.LATEX_ENABLED:
raise NotFound
Expand Down
16 changes: 13 additions & 3 deletions indico/modules/events/contributions/__init__.py
Expand Up @@ -18,6 +18,7 @@
from indico.modules.events.contributions.contrib_fields import get_contrib_field_types
from indico.modules.events.contributions.models.contributions import Contribution
from indico.modules.events.contributions.models.fields import ContributionField
from indico.modules.events.models.events import EventType
from indico.modules.events.settings import EventSettingsProxy
from indico.util.i18n import _, ngettext
from indico.web.flask.util import url_for
Expand Down Expand Up @@ -104,10 +105,12 @@ def _extend_event_menu(sender, **kwargs):
from indico.modules.events.layout.util import MenuEntryData

def _visible_my_contributions(event):
return session.user and has_contributions_with_user_as_submitter(event, session.user)
published = contribution_settings.get(event, 'published')
return session.user and published and has_contributions_with_user_as_submitter(event, session.user)

def _visible_list_of_contributions(event):
return Contribution.query.filter(Contribution.event == event).has_rows()
published = contribution_settings.get(event, 'published')
return published and Contribution.query.filter(Contribution.event == event).has_rows()

yield MenuEntryData(title=_("My Contributions"), name='my_contributions', visible=_visible_my_contributions,
endpoint='contributions.my_contributions', position=2, parent='my_conference')
Expand All @@ -119,8 +122,15 @@ def _visible_list_of_contributions(event):
position=6, is_enabled=False, static_site=True)


@signals.event.created.connect
def _event_created(event, **kwargs):
if event.type_ == EventType.conference:
contribution_settings.set(event, 'published', False)


contribution_settings = EventSettingsProxy('contributions', {
'default_duration': timedelta(minutes=20)
'default_duration': timedelta(minutes=20),
'published': True
}, converters={
'default_duration': TimedeltaConverter
})
4 changes: 4 additions & 0 deletions indico/modules/events/contributions/blueprint.py
Expand Up @@ -104,6 +104,10 @@
_bp.add_url_rule('/manage/contributions/duration', 'manage_default_duration',
management.RHManageDefaultContributionDuration, methods=('GET', 'POST'))

# Publish contribution
_bp.add_url_rule('/manage/contributions/published', 'manage_publication',
management.RHManageContributionPublicationREST, methods=('GET', 'PUT', 'DELETE'))

# Custom contribution fields
_bp.add_url_rule('/manage/contributions/fields/', 'manage_fields', management.RHManageContributionFields)
_bp.add_url_rule('/manage/contributions/fields/create/<field_type>', 'create_field',
Expand Down
15 changes: 15 additions & 0 deletions indico/modules/events/contributions/client/js/index.js
Expand Up @@ -8,9 +8,24 @@
/* global showUndoWarning:false, setupListGenerator:false, setupSearchBox:false */
/* global reloadManagementAttachmentInfoColumn:false */

import React from 'react';
import ReactDOM from 'react-dom';

import 'indico/modules/events/util/types_dialog';
import {PublicationSwitch} from 'indico/react/components';


(function(global) {
function setupPublicationButton() {
const element = document.querySelector('#pub-switch');
const component = React.createElement(PublicationSwitch, {eventId: element.dataset.eventId});
ReactDOM.render(component, element);
}

global.setupContributionConfig = function setupContributionConfig() {
setupPublicationButton();
};

function setupTableSorter(selector) {
$(selector).tablesorter({
cssAsc: 'header-sort-asc',
Expand Down
7 changes: 6 additions & 1 deletion indico/modules/events/contributions/controllers/common.py
Expand Up @@ -9,6 +9,8 @@

from flask import redirect

from indico.modules.events.contributions import contribution_settings, get_contrib_field_types


class ContributionListMixin:
"""Display list of contributions"""
Expand All @@ -22,4 +24,7 @@ def _process(self):
return self._render_template(**self.list_generator.get_list_kwargs())

def _render_template(self, selected_entry, **kwargs):
return self.view_class.render_template(self.template, self.event, selected_entry=selected_entry, **kwargs)
published = contribution_settings.get(self.event, 'published')
return self.view_class.render_template(self.template, self.event, selected_entry=selected_entry,
published=published, **kwargs)

9 changes: 9 additions & 0 deletions indico/modules/events/contributions/controllers/display.py
Expand Up @@ -15,6 +15,7 @@
from indico.core.db import db
from indico.legacy.pdfinterface.latex import ContribsToPDF, ContribToPDF
from indico.modules.events.abstracts.util import filter_field_values
from indico.modules.events.contributions import contribution_settings
from indico.modules.events.contributions.lists import ContributionDisplayListGenerator
from indico.modules.events.contributions.models.contributions import Contribution
from indico.modules.events.contributions.models.persons import AuthorType, ContributionPersonLink
Expand All @@ -26,6 +27,7 @@
from indico.modules.events.layout.util import is_menu_entry_enabled
from indico.modules.events.models.persons import EventPerson
from indico.modules.events.util import get_base_ical_parameters
from indico.util.i18n import _
from indico.web.flask.util import jsonify_data, send_file
from indico.web.rh import RH
from indico.web.util import jsonify_template
Expand Down Expand Up @@ -53,8 +55,11 @@ class RHContributionDisplayBase(RHDisplayEventBase):

def _check_access(self):
RHDisplayEventBase._check_access(self)
published = contribution_settings.get(self.event, 'published')
if not self.contrib.can_access(session.user):
raise Forbidden
if not published:
panagiotappl marked this conversation as resolved.
Show resolved Hide resolved
raise NotFound(_("The contributions of this event have not been published yet."))

def _process_args(self):
RHDisplayEventBase._process_args(self)
Expand All @@ -64,6 +69,10 @@ def _process_args(self):
class RHDisplayProtectionBase(RHDisplayEventBase):
def _check_access(self):
RHDisplayEventBase._check_access(self)
published = contribution_settings.get(self.event, 'published')
if not published:
raise NotFound(_("The contributions of this event have not been published yet."))

if not is_menu_entry_enabled(self.MENU_ENTRY_NAME, self.event):
self._forbidden_if_not_admin()

Expand Down
20 changes: 20 additions & 0 deletions indico/modules/events/contributions/controllers/management.py
Expand Up @@ -544,6 +544,26 @@ def _process(self):
return jsonify_form(form)


class RHManageContributionPublicationREST(RHManageContributionsBase):
"""Manage contribution publication setting"""

def _process_GET(self):
published = contribution_settings.get(self.event, 'published')
return jsonify(published=published)

def _process_PUT(self):
contribution_settings.set(self.event, 'published', True)
panagiotappl marked this conversation as resolved.
Show resolved Hide resolved
self.event.log(EventLogRealm.management, EventLogKind.positive, 'Contributions',
'Contributions published', session.user)
return '', 204

def _process_DELETE(self):
contribution_settings.set(self.event, 'published', False)
panagiotappl marked this conversation as resolved.
Show resolved Hide resolved
self.event.log(EventLogRealm.management, EventLogKind.negative, 'Contributions',
'Contributions unpublished', session.user)
return '', 204


class RHManageContributionTypeBase(RHManageContributionsBase):
"""Manage a contribution type of an event"""

Expand Down
Expand Up @@ -43,6 +43,7 @@
</li>
</ul>
{%- endif -%}
<div id="pub-switch" data-event-id="{{ event.id }}"></div>
{% endblock %}

{% block description %}
Expand Down Expand Up @@ -187,6 +188,7 @@
$('#search-input').val('#{{ selected_entry }}').trigger('change');
{% endif %}

setupContributionConfig();
setupContributionList({
createSessionURL: {{ url_for('sessions.create_session', event) | tojson }},
createTrackURL: {{ url_for('tracks.create_track', event) | tojson }},
Expand Down
7 changes: 6 additions & 1 deletion indico/modules/events/timetable/__init__.py
Expand Up @@ -25,8 +25,13 @@
@signals.event.sidemenu.connect
def _extend_event_menu(sender, **kwargs):
from indico.modules.events.layout.util import MenuEntryData
from indico.modules.events.contributions import contribution_settings

def _visible_timetable(event):
return contribution_settings.get(event, 'published')

yield MenuEntryData(title=_("Timetable"), name='timetable', endpoint='timetable.timetable', position=3,
static_site=True)
visible=_visible_timetable, static_site=True)


@signals.menu.items.connect_via('event-management-sidemenu')
Expand Down
25 changes: 17 additions & 8 deletions indico/modules/events/timetable/controllers/display.py
Expand Up @@ -10,9 +10,10 @@
from io import BytesIO

from flask import jsonify, request, session
from werkzeug.exceptions import Forbidden
from werkzeug.exceptions import Forbidden, NotFound

from indico.legacy.pdfinterface.conference import SimplifiedTimeTablePlain, TimetablePDFFormat, TimeTablePlain
from indico.modules.events.contributions import contribution_settings
from indico.modules.events.controllers.base import RHDisplayEventBase
from indico.modules.events.layout import layout_settings
from indico.modules.events.timetable.forms import TimetablePDFExportForm
Expand All @@ -26,12 +27,20 @@
from indico.web.util import jsonify_data, jsonify_template


class RHTimetable(RHDisplayEventBase):
class RHTimetableProtectionBase(RHDisplayEventBase):
def _check_access(self):
RHDisplayEventBase._check_access(self)
published = contribution_settings.get(self.event, 'published')
if not published:
raise NotFound(_("The contributions of this event have not been published yet"))


class RHTimetable(RHTimetableProtectionBase):
view_class = WPDisplayTimetable
view_class_simple = WPSimpleEventDisplay

def _process_args(self):
RHDisplayEventBase._process_args(self)
RHTimetableProtectionBase._process_args(self)
self.timetable_layout = request.args.get('layout') or request.args.get('ttLyt')
self.theme, self.theme_override = get_theme(self.event, request.args.get('view'))

Expand All @@ -48,15 +57,15 @@ def _process(self):
return self.view_class_simple(self, self.event, self.theme, self.theme_override).display()


class RHTimetableEntryInfo(RHDisplayEventBase):
class RHTimetableEntryInfo(RHTimetableProtectionBase):
"""Display timetable entry info balloon."""

def _process_args(self):
RHDisplayEventBase._process_args(self)
RHTimetableProtectionBase._process_args(self)
self.entry = self.event.timetable_entries.filter_by(id=request.view_args['entry_id']).first_or_404()

def _check_access(self):
RHDisplayEventBase._check_access(self)
RHTimetableProtectionBase._check_access(self)
if not self.entry.can_view(session.user):
raise Forbidden

Expand All @@ -65,7 +74,7 @@ def _process(self):
return jsonify(html=html)


class RHTimetableExportPDF(RHDisplayEventBase):
class RHTimetableExportPDF(RHTimetableProtectionBase):
def _process(self):
form = TimetablePDFExportForm(formdata=request.args, csrf_enabled=False)
if form.validate_on_submit():
Expand All @@ -92,7 +101,7 @@ def _process(self):
back_url=url_for('.timetable', self.event))


class RHTimetableExportDefaultPDF(RHDisplayEventBase):
class RHTimetableExportDefaultPDF(RHTimetableProtectionBase):
def _process(self):
pdf = get_timetable_offline_pdf_generator(self.event)
return send_file('timetable.pdf', BytesIO(pdf.getPDFBin()), 'application/pdf')