from __future__ import print_function from datetime import datetime import hashlib import logging import mimetypes import os from pprint import pprint import string import time from bs4 import BeautifulSoup from django.conf import settings from django.template import Context, Template from django.template.loader import get_template import onesie import ojssqla import phpserialize import pycountry import requests import shutil from .models import ArticleBadges, ArticleImage, ArticleAuthor, DataFile logger = logging.getLogger(__name__) def render_template_file(context, template_file): template = get_template(template_file) return template.render(Context(context)) def render_template_body(context, template_body): template = Template(template_body) return template.render(Context(context)) def hash_password(username, password): if settings.FEATURE_SETTINGS.get('ENC_TYPE', None) == 'MD5': return hashlib.md5( ("%s%s" % (username, password)).encode('utf-8') ).hexdigest() else: return hashlib.sha1( ("%s%s" % (username, password)).encode('utf-8') ).hexdigest() def send_confirmation_email(request, author, journal, journal_settings): html = get_template('author/email.html') context = Context({ 'request': request, 'author': author, 'journal': journal }) html_content = html.render(context) text = get_template('author/email.txt') text_content = text.render(context) if settings.DEBUG: pprint({ "from": "%s <%s@ubiquity.press>" % ( settings.JOURNAL_NAME, settings.JOURNAL_CODE ), "h:Reply-To": journal_settings.get( 'contactEmail', 'tech@ubiquitypress.com' ).get( 'setting_value', 'tech@ubiquitypress.com' ), "to": author.email, "subject": '[%s] Registration Confirmation' % journal_settings['initials'], "html": html_content, "text": text_content, }) resp = requests.Response() resp.status_code = 200 return resp else: try: return requests.post( settings.MAILGUN_API_URL, auth=("api", settings.MAILGUN_KEY), data={ "from": "%s <%s@ubiquity.press>" % ( settings.JOURNAL_NAME, settings.JOURNAL_CODE ), "h:Reply-To": journal_settings.get( 'contactEmail', 'tech@ubiquitypress.com' ).get( 'setting_value', 'tech@ubiquitypress.com' ), "to": author.email, "subject": '[%s] Registration Confirmation' % journal_settings['initials'], "html": html_content, "text": text_content, }) except: return requests.post( settings.MAILGUN_API_URL, auth=("api", settings.MAILGUN_KEY), data={ "from": "%s <%s@ubiquity.press>" % ( settings.JOURNAL_NAME, settings.JOURNAL_CODE, ), "h:Reply-To": "support@ubiquitypress.com", "to": author.email, "subject": '[%s] Registration Confirmation' % journal_settings['initials'], "html": html_content, "text": text_content, }) def send_reset_email(email, code, initials=settings.JOURNAL_CODE): html_content = ( '' 'You requested a password reset code. Please click this link to ' '' 'reset your password' '.

' 'If you did not request this please contact ' 'support@ubiquitypress.com immediately.' '' % ( settings.BASE_URL, code, ) ) text_content = ( 'You requested a password reset code. Please click this link to ' '%s/login/reset_password/code/%s/ ' 'reset your password' 'If you did not request this please contact ' 'support@ubiquitypress.com immediately.' % ( settings.BASE_URL, code, ) ) if settings.DEBUG: pprint({ "from": "%s <%s@ubiquity.press>" % ( settings.JOURNAL_NAME, settings.JOURNAL_CODE, ), "h:Reply-To": 'support@ubiquitypress.com', "to": email, "subject": '[%s] Password Reset' % initials, "html": html_content, "text": text_content, }) return True else: return requests.post( settings.MAILGUN_API_URL, auth=("api", settings.MAILGUN_KEY), data={ "from": "%s <%s@ubiquity.press>" % ( settings.JOURNAL_NAME, settings.JOURNAL_CODE, ), "h:Reply-To": 'support@ubiquitypress.com', "to": email, "subject": '[%s] Password Reset' % initials, "html": html_content, "text": text_content, }) def send_transfer_alert_email(author, journal_settings, journal): html = ( '' 'Author Number %s could not be transferred to OJS. Username: %s' '' % ( author.id, author.email ) ) text = 'Author Number %s could not be transferred to OJS. Username: %s' % ( author.id, author.email ) try: reply_to = journal_settings.get('contactEmail').get('setting_value') except AttributeError: reply_to = 'support@ubiquitypress.com' if settings.DEBUG: pprint( { "from": "%s <%s@ubiquity.press>" % ( settings.JOURNAL_NAME, settings.JOURNAL_CODE, ), "h:Reply-To": reply_to, "to": 'tech@ubiquitypress.com', "subject": '[%s] Transfer Issue' % journal_settings['initials'], "html": html, "text": text, } ) return True return requests.post( settings.MAILGUN_API_URL, auth=("api", settings.MAILGUN_KEY), data={ "from": "%s <%s@ubiquity.press>" % ( settings.JOURNAL_NAME, settings.JOURNAL_CODE, ), "h:Reply-To": reply_to, "to": 'tech@ubiquitypress.com', "subject": '[%s] Transfer Issue' % journal_settings['initials'], "html": html, "text": text, } ) def send_submission_ack_email(request, article, journal, journal_settings): jura_dict = onesie.get_gl_email( request.db_session, settings.JOURNAL_CODE, 1, ) body = jura_dict.get('body') html = Template( body ) soup = BeautifulSoup(body) text = Template( soup.get_text() ) author = article.correspondence_author context = Context({ 'request': request, 'author': author, 'article': article, 'journal': journal, 'href': '%s/jms/user/' % settings.BASE_URL, 'journal_signature': journal_settings.get('emailSignature', '') }) html_content = html.render(context) text_content = text.render(context) if settings.DEBUG: pprint({ "from": "%s <%s>" % ( settings.JOURNAL_NAME, jura_dict.get( 'from_address', settings.JOURNAL_CODE + "@ubiquity.press" ) ), "h:Reply-To": jura_dict.get( 'reply_address', journal_settings.get('contactEmail') ), "to": author.email, "subject": '[%s] Submission Acknowledgement - "%s"' % ( journal_settings['initials'], article.title ), "html": html_content, "text": text_content, }) return True else: try: return requests.post( settings.MAILGUN_API_URL, auth=("api", settings.MAILGUN_KEY), data={ "from": "%s <%s>" % ( settings.JOURNAL_NAME, jura_dict.get( 'from_address', settings.JOURNAL_CODE + "@ubiquity.press" ) ), "h:Reply-To": jura_dict.get( 'reply_address', journal_settings.get('contactEmail') ), "to": author.email, "subject": '[%s] Submission Acknowledgement - "%s"' % ( journal_settings['initials'], article.title ), "html": html_content, "text": text_content, }) except Exception as e: print(e) return requests.post( settings.MAILGUN_API_URL, auth=("api", settings.MAILGUN_KEY), data={ "from": "%s <%s@ubiquity.press>" % ( settings.JOURNAL_NAME, settings.JOURNAL_CODE, ), "h:Reply-To": "support@ubiquitypress.com", "to": author.email, "subject": '[%s] Submission Acknowledgement' % journal_settings['initials'], "html": html_content, "text": text_content, }) def send_new_submission_editor_email( request, article, journal, journal_settings ): html_content = render_template_body( { 'request': request, 'article': article, 'journal': journal, 'editor': journal_settings.get('contactName'), 'href': '{base_url}/jms/user/'.format( base_url=settings.BASE_URL ), }, onesie.get_gl_email( request.db_session, settings.JOURNAL_CODE, 2, ).get( 'body' ) ) soup = BeautifulSoup(html_content) text_content = soup.get_text() if settings.DEBUG: pprint({ 'from': '{name} <{code}@ubiquity.press>'.format( name=settings.JOURNAL_NAME, code=settings.JOURNAL_CODE, ), 'h:Reply-To': journal_settings.get( 'contactEmail' ), 'to': journal_settings.get( 'contactEmail', 'tech@ubiquitypress.com' ), 'subject': '[{code}] New submission - "{title}"'.format( code=journal_settings['initials'], title=article.title.encode('utf-8') ), 'html': html_content, 'text': text_content, }) return True else: requests.post( settings.MAILGUN_API_URL, auth=('api', settings.MAILGUN_KEY), data={ 'from': '{name} <{code}@ubiquity.press>'.format( name=settings.JOURNAL_NAME, code=settings.JOURNAL_CODE, ), 'h:Reply-To': journal_settings.get( 'contactEmail' ), 'to': journal_settings.get( 'contactEmail', 'tech@ubiquitypress.com' ), 'subject': '[{code}] New submission - "{title}"'.format( code=journal_settings['initials'], title=article.title.encode('utf-8') ), 'html': html_content, 'text': text_content, }) return requests.post( settings.MAILGUN_API_URL, auth=('api', settings.MAILGUN_KEY), data={ 'from': '{name} <{code}@ubiquity.press>'.format( name=settings.JOURNAL_NAME, code=settings.JOURNAL_CODE, ), 'h:Reply-To': journal_settings.get( 'copySubmissionAckAddress'), 'to': journal_settings.get( 'copySubmissionAckAddress', 'tech@ubiquitypress.com' ), 'subject': '[{code}] New submission '.format( code=journal_settings['initials'] ), 'html': html_content, 'text': text_content, }) def email_ithenticate_error( journal, article, message, _type, initials=settings.JOURNAL_CODE ): return requests.post( settings.MAILGUN_API_URL, auth=("api", settings.MAILGUN_KEY), data={ "from": "%s <%s@ubiquity.press>" % ( settings.JOURNAL_NAME, settings.JOURNAL_CODE, ), "h:Reply-To": "tech@ubiquitypress.com", "to": "tech@ubiquitypress.com", "subject": '[%s] iThenticate Failure' % initials, "html": '

There was a problem sending this %s ' 'to ithenticate

%s %s

' % ( article.title, message, _type, ) } ) def transfer_user(session, author, interests): date = datetime.now().strftime("%Y-%m-%d %H:%M:%S") ojs_user_dict = { 'username': author.email, 'password': author.password, 'first_name': author.first_name, 'middle_name': author.middle_name, 'last_name': author.last_name, 'salutation': author.salutation, 'email': author.email, 'country': author.country, 'date_registered': date, 'date_validated': date, 'date_last_login': date, 'must_change_password': 0, 'disabled': 0, 'inline_help': 0, } ojs_user_settings_dict = { 'biography': author.biography, 'affiliation': author.institution, 'twitter': author.twitter, 'linkedin': author.linkedin, 'impactstory': author.impactstory, 'orcid': author.orcid, 'osf_id': author.osf_id, 'profile_image': ( author.profile_image.url if author.profile_image else None ), 'gossip': '', 'signature': '', } # Check which roles can self register. reader = ojssqla.as_dict( ojssqla.non_localised_setting(session, 'allowRegReader') ) reviewer = ojssqla.as_dict( ojssqla.non_localised_setting(session, 'allowRegReviewer') ) author = ojssqla.as_dict( ojssqla.non_localised_setting(session, 'allowRegAuthor') ) roles = [] if reader.get('setting_value', None) == '1': roles.append('1048576') if reviewer.get('setting_value', None) == '1': roles.append('4096') if author.get('setting_value', None) == '1': roles.append('65536') user = ojssqla.transfer_user(session, ojs_user_dict, ojs_user_settings_dict) if user: ojssqla.insert_roles(session, user, roles) # Transferring review interests. for interest in interests: ojssqla.set_reviewing_interest(session, interest, user) return user def transfer_article(session, article, request): LOCALE = determine_article_language(request, article) JOURNAL_ID = 1 # Defaults that don't change for submissions. CITATIONS = '' STATUS = 1 SUBMISSION_PROGRESS = 0 CURRENT_ROUND = 1 FAST_TRACKED = 0 HIDE_AUTHOR = 0 COMMENT_STATUS = 0 SPONSOR = '' mimetypes.add_type( 'application/' 'vnd.openxmlformats-officedocument.wordprocessingml.document', '.docx' ) DATE = datetime.now().strftime("%Y-%m-%d %H:%M:%S") DATE_CREATED = datetime.now().strftime("%Y-%m-%d") # Build stage one and article settings. article_one = { 'locale': LOCALE, 'user_id': article.owner, 'journal_id': JOURNAL_ID, 'section_id': article.section_id, 'language': article.language, 'comments_to_ed': article.comments_editor, 'citations': CITATIONS, 'date_submitted': DATE, 'last_modified': DATE, 'date_status_modified': DATE, 'status': STATUS, 'submission_progress': SUBMISSION_PROGRESS, 'current_round': CURRENT_ROUND, 'fast_tracked': FAST_TRACKED, 'hide_author': HIDE_AUTHOR, 'comments_status': COMMENT_STATUS, } badges = ArticleBadges.objects.filter(article=article) article_settings = { 'abstract': article.abstract, 'cleanTitle': article.title, 'discipline': article.academic_disciplines, 'sponsor': SPONSOR, 'title': article.title, 'subject': article.keywords, 'coverageGeo': article.geospatial_coverage, 'coverageChron': article.chronological_coverage, 'coverageSample': article.research_sample, 'license': article.license_id, 'ithenticate_id': article.ithenticate_id, 'open_review': article.open_review, } if article.exclude_reviewers: article_settings['excluded_reviewers'] = article.exclude_reviewers if article.recommend_reviewers: article_settings['recommended_reviewers'] = article.recommend_reviewers all_article_settings = {} all_article_settings.update(article_settings) if badges: try: article_badges = badges[0] badge_settings = { 'open_data_claim': article_badges.open_data_claim, 'open_data_url': article_badges.open_data_url, 'open_data_disclosure': article_badges.open_data_disclosure, 'open_materials_claim': article_badges.open_materials_claim, 'open_materials_url': article_badges.open_materials_url, 'open_materials_disclosure': article_badges.open_materials_disclosure, 'preregistered_claim': article_badges.preregistered_claim, 'preregistered_url': article_badges.preregistered_url, 'preregistered_disclosure': article_badges.preregistered_disclosure, 'preregistered_plus': article_badges.preregistered_plus, } all_article_settings.update(badge_settings) except IndexError: pass # Send stage one to OJS. new_article_id = ojssqla.article_transfer_stage_one( session, article_one, all_article_settings, article.taxonomy, ) article.ojs_submission_id = new_article_id article.save() # Build files. REVISION = 1 ROUND = 1 file_move_list = [] # Build and transfer submission file and review file. file_name, file_extension = os.path.splitext(article.manuscript.name) file_name = os.path.split(article.manuscript.name)[1] _dict = { 'revision': REVISION, 'round': ROUND, 'article_id': article.ojs_submission_id, 'file_type': mimetypes.types_map.get(file_extension, ''), 'file_size': article.manuscript.size, 'original_file_name': file_name, 'file_stage': 1, 'date_uploaded': DATE, 'date_modified': DATE, 'file_name': file_name, } new_file = ojssqla.file_transfer( session, _dict, article.pk, 'manuscript', file_extension, ) if new_file: file_move_list.append(new_file) _dict = { 'revision': REVISION, 'round': ROUND, 'article_id': article.ojs_submission_id, 'file_type': mimetypes.types_map.get(file_extension, ''), 'file_size': article.manuscript.size, 'original_file_name': file_name, 'file_stage': 2, 'date_uploaded': DATE, 'date_modified': DATE, 'file_name': file_name, } new_file = ojssqla.file_transfer( session, _dict, article.pk, 'review', file_extension, ) if new_file: file_move_list.append(new_file) ojssqla.add_review_Reound(session, article.pk) # Build and transfer figures. for _file in ArticleImage.objects.filter(article=article).order_by( 'seq' ): file_name, file_extension = os.path.splitext(_file.image.name) file_name = os.path.split(_file.image.name)[1] _dict = { 'revision': REVISION, 'round': ROUND, 'article_id': article.ojs_submission_id, 'file_type': mimetypes.types_map.get(file_extension, ''), 'file_size': _file.image.size, 'original_file_name': file_name, 'file_stage': 6, 'date_uploaded': DATE, 'date_modified': DATE, 'file_name': file_name, } new_file = ojssqla.file_transfer( session, _dict, _file.pk, 'figure', file_extension, ) if new_file: file_move_list.append(new_file) # Build and transfer data files. for _file in DataFile.objects.filter(article=article): file_name, file_extension = os.path.splitext(_file.data_file.name) file_name = os.path.split(_file.data_file.name)[1] _dict = { 'revision': REVISION, 'round': ROUND, 'article_id': article.ojs_submission_id, 'file_type': mimetypes.types_map.get(file_extension, ''), 'file_size': _file.data_file.size, 'original_file_name': file_name, 'file_stage': 6, 'date_uploaded': DATE, 'date_modified': DATE, 'file_name': file_name, } new_file = ojssqla.file_transfer( session, _dict, _file.pk, 'data', file_extension, ) if new_file: file_move_list.append(new_file) # Build and add supplementary files seq = 0 for _file in file_move_list: if ( not _file['file_type'] == 'manuscript' and not _file['file_type'] == 'review' ): _dict = { 'file_id': _file['ojs_file_id'], 'article_id': article.ojs_submission_id, 'type': _file['file_type'], 'date_created': DATE_CREATED, 'show_reviewers': 1, 'date_submitted': DATE, 'seq': seq, } seq += 1 ojssqla.create_supp_record(session, _dict) # Build and add authors. authors = ArticleAuthor.objects.filter(article=article).order_by('seq') first_iteration = True for author in authors: article_author = { 'submission_id': article.ojs_submission_id, 'primary_contact': 1 if first_iteration else 0, 'seq': author.seq, 'first_name': author.first_name, 'middle_name': author.middle_name, 'last_name': author.last_name, 'country': author.country, 'email': author.email, } article_author_settings = { 'affiliation': author.institution, 'biography': author.biography, 'department': author.department, 'orcid': author.orcid, 'twitter': author.twitter, 'linkedin': author.linkedin, 'impactstory': author.impactstory, } ojssqla.insert_article_author( session, article_author, article_author_settings, ) first_iteration = False # Updated the article record for _file in file_move_list: if _file['file_type'] == 'manuscript': ojssqla.update_article_manuscript( session, article.ojs_submission_id, _file['ojs_file_id'], ) if _file['file_type'] == 'review': ojssqla.update_article_revision( session, article.ojs_submission_id, _file['ojs_file_id'], ) # Move the files into the correct folders. move_files_to_ojs(file_move_list, article) return article.ojs_submission_id def move_files_to_ojs(file_move_list, article): # prepare folder _dir = os.path.join( settings.BASE_DIR, 'journal_files', 'journals', '1', 'articles', str(article.ojs_submission_id), ) submission_dir = os.path.join(_dir, 'submission') supp_dir = os.path.join(_dir, 'supp') orig_dir = os.path.join(submission_dir, 'original') review_dir = os.path.join(submission_dir, 'review') if not os.path.exists(_dir): os.makedirs(_dir) if not os.path.exists(submission_dir): os.makedirs(submission_dir) if not os.path.exists(supp_dir): os.makedirs(supp_dir) if not os.path.exists(orig_dir): os.makedirs(orig_dir) if not os.path.exists(review_dir): os.makedirs(review_dir) for _file in file_move_list: if _file['file_type'] == 'manuscript': submission_file_loc = os.path.join( settings.BASE_DIR, 'journal_files', 'gl_uploads', article.manuscript.name, ) shutil.copy( submission_file_loc, os.path.join(orig_dir, _file['file_name']) ) if _file['file_type'] == 'review': submission_file_loc = os.path.join( settings.BASE_DIR, 'journal_files', 'gl_uploads', article.manuscript.name ) shutil.copy( submission_file_loc, os.path.join(review_dir, _file['file_name']) ) if _file['file_type'] == 'figure': article_image = ArticleImage.objects.get(pk=_file['file_id']) submission_file_loc = os.path.join( settings.BASE_DIR, 'journal_files', 'gl_uploads', article_image.image.name, ) shutil.copy( submission_file_loc, os.path.join(supp_dir, _file['file_name']) ) if _file['file_type'] == 'data': data_file = DataFile.objects.get(pk=_file['file_id']) submission_file_loc = os.path.join( settings.BASE_DIR, 'journal_files', 'gl_uploads', data_file.data_file.name ) shutil.copy( submission_file_loc, os.path.join(supp_dir, _file['file_name']) ) def assign_section_editors(session, article, submission_id, journal_settings): section_editors = get_section_editors( session, section_id=article.section_id, user_id=article.selected_editor ) for editor in section_editors: ojssqla.assign_section_editor(session, article, submission_id, editor) email_section_editor( session, article, submission_id, editor, journal_settings, ) return 'done!' def email_section_editor( session, article, submission_id, editor, journal_settings, ): ojs_email = ojssqla.get_email_template(session, 'EDITOR_ASSIGN') subject = ojs_email.get( 'subject' ).replace( '{$articleTitle}', article.title ) body = generate_body_section_editor( ojs_email.get('body'), article, submission_id, editor, journal_settings ) text = body html = ( '' '{body}' '' ).format( body=''.join( [ '

{line}

\n'.format( line=line ) for line in body.split('\n') if line ] ) ) if settings.DEBUG: pprint( { "from": "%s <%s>" % ( settings.JOURNAL_NAME, journal_settings.get('contactEmail') ), "h:Reply-To": journal_settings.get('contactEmail'), "to": editor['user'].get('email'), "subject": subject, 'html': html, "text": text, } ) return True else: return requests.post( settings.MAILGUN_API_URL, auth=("api", settings.MAILGUN_KEY), data={ "from": "%s <%s>" % ( settings.JOURNAL_NAME, journal_settings.get('contactEmail') ), "h:Reply-To": journal_settings.get('contactEmail'), "to": editor['user'].get('email'), "subject": subject, 'html': html, "text": text, }) def is_ascii(text): if isinstance(text, unicode): try: text.encode('ascii') except UnicodeEncodeError: return False else: try: text.decode('ascii') except UnicodeDecodeError: return False return True def generate_body_section_editor( body, article, submission_id, editor, journal_settings, ): replace_dict = { '{$articleTitle}': article.title, '{$journalName}': settings.JOURNAL_NAME, '{$submissionUrl}': '%s/jms/editor/submission/%s' % ( settings.BASE_URL, submission_id, ), '{$editorUsername}': editor['user'].get('username'), '{$editorialContactName}': '%s %s' % ( editor['user'].get('first_name'), editor['user'].get('last_name'), ), '{$editorialContactSignature}': journal_settings.get('contactName'), } body = filter(lambda x: x in string.printable, body) for k, v in replace_dict.iteritems(): body = body.replace( k, v if is_ascii(v) else v.encode('utf-8') if isinstance(v, unicode) else v.decode('utf-8', errors='replace') ) return body def get_login_user(session, username, password, unhashed_password): user = ojssqla.get_login_user( session, username, password, unhashed_password, ) if user and user.disabled == 0: return ojssqla.as_dict(user) return None def get_user_from_email(session, email): user = ojssqla.get_user_from_email(session, email) if user and user.disabled == 0: return ojssqla.as_dict(user) return None def set_password(session, user_id, password): ojssqla.set_password(session, user_id, password) def add_session_to_db(db_session, session_id, user, ip, user_agent): user_id_string = str(user.get('user_id')) username = user.get('username') serialised_data = 'userId|s:%s:"%s";username|s:%s:"%s";' % ( len(user_id_string), user_id_string, len(username), username, ) return ojssqla.add_session_to_db( db_session, session_id, user, serialised_data, ip, user_agent, int(time.time()) ) def get_user_settings(session, user): if user.get('user_id', None): user_settings = ojssqla.dict_ojs_settings_results( ojssqla.get_user_settings(session, user['user_id']) ) return user_settings else: return None def get_orcid_from_oauth(session, orcid): ojs_orcid = ojssqla.as_dict(ojssqla.get_orcid(session, orcid)) if ojs_orcid: return ojssqla.as_dict( ojssqla.get_user_from_id(session, ojs_orcid['user_id']) ) else: return None def get_article_types(session): article_types = ojssqla.all_as_dict(ojssqla.get_article_sections(session)) for at in article_types: at['settings'] = ojssqla.dict_ojs_settings_results( ojssqla.get_section_settings(session, at['section_id']) ) article_types = [ (section['section_id'], section['settings']['title']) for section in article_types ] return article_types def ojs_journal_setting(session, setting_name): """ Returns a journal setting value by given name. """ return ojssqla.as_dict(ojssqla.get_journal_setting(session, setting_name)) def ojs_journal_settings(session, locale=None): """ Returns the journal_settings table in format foo_setting:bar_value. """ settings = ojssqla.dict_ojs_settings_results( ojssqla.ojs_journal_settings(session, locale) ) return settings def get_taxonomies(session): return ojssqla.get_taxonomies(session) def has_role(session, user_id, role_id): return ojssqla.get_role(session, user_id, role_id) def journal_sections(session, journal_code, submissible=None, about=None): return onesie.all_as_dict( onesie.journal_sections( session, journal_code, submissible, about ).order_by( onesie.upcdn.MetricsSection.seq ) ) def journal_section( session, section_id, journal_code, submissible=None, about=None, ): return onesie.all_as_dict( onesie.journal_section( session, section_id, journal_code, submissible, about ) ) def get_submission_checklist(session, locale): submission_checklist = ojs_journal_settings(session, locale).get( 'submissionChecklist' ) if not submission_checklist: logger.error( 'OJS journal setting "submissionChecklist" not found.' ) raise RuntimeError( 'OJS journal setting "submissionChecklist" not found.' ) return phpserialize.loads(submission_checklist) def add_role_to_user(session, role, user_id): return ojssqla.add_role_to_user(session, role, user_id) def remove_role_from_user(session, user_id, role_id): return ojssqla.remove_role_from_user(session, user_id, role_id) def update_or_create_user_setting( session, user_id, setting_name, setting_value, ): return ojssqla.update_or_create_user_setting( session, user_id, setting_name, setting_value, ) def set_new_user_details(session, user_id, user_dict, settings_dict): return ojssqla.set_new_user_details( session, user_id, user_dict, settings_dict, ) def get_reviewer_message(session): return ojssqla.as_dict(ojssqla.get_journal_setting( session, setting_name='general::reviewer_message') ).get( 'setting_value', '

Peer review is an integral part of the scholarly publishing ' 'process. By registering as a reviewer, you are supporting the ' 'academic community by providing constructive feedback on new ' 'research, helping to ensure both the quality and integrity of ' 'published work in your field.

Once registered, you may be ' 'asked to undertake reviews of scholarly articles that match your ' 'research interests. Reviewers always have the option to decline an ' 'invitation to review and we take care not to overburden our reviewers ' 'with excessive requests.

' ) def get_section_editors(session, section_id=None, user_id=None): return ojssqla.get_section_editors(session, section_id, user_id) def author_role_checker(session, user_id): """ Checks if the user has the user role. If it doesn't, It will check the journal setting 'allowregauthor' and give the role or not based on that setting. """ if has_role(session, user_id, 65536): user_author_role = True elif ojs_journal_setting(session, 'allowRegAuthor').get( 'setting_value') == '1': add_role_to_user(session, 65536, user_id) user_author_role = True else: user_author_role = None return user_author_role def journal_licenses(session): licenses = ojssqla.all_as_dict(ojssqla.get_journal_licenses(session)) return [ (license.get('id'), license.get('pretty_name')) for license in licenses ] def determine_article_language(request, article): if request.settings_locales: try: language = pycountry.languages.get( iso639_3_code=request.user_language ).iso639_1_code supported = { lang.split('_')[0]: lang for lang in request.settings_locales } return supported.get(language, request.default_language) except Exception: return request.default_language return request.default_language def update_review_interests(session, interests, user): delete_review_interests(session, user.get('user_id')) for interest in interests: ojssqla.set_reviewing_interest( session, interest, user.get('user_id') ) def delete_review_interests(session, user_id): return ojssqla.delete_reviewing_interests(session, user_id) def ojs_user_interests(interests): interests_list = [] for interest in interests: [ interests_list.append(setting.setting_value) for setting in interest.get('controlled_vocab').settings ] return interests_list def is_abstract_required(ojs_id, db_session, submissible): section = journal_section( db_session, ojs_id, settings.JOURNAL_CODE, True, submissible, ) if section: if 'abstracts_not_required' in section: if section['abstracts_not_required']: return not section['abstracts_not_required'] return True return True return True