コード例 #1
0
    def managedocfilesasync(self, req, form):
        "Upload file and returns upload interface"

        argd = wash_urlargd(
            form, {"ln": (str, ""), "recid": (int, 1), "doctype": (str, ""), "access": (str, ""), "indir": (str, "")}
        )

        user_info = collect_user_info(req)
        include_headers = False
        # User submitted either through WebSubmit, or admin interface.
        if form.has_key("doctype") and form.has_key("indir") and form.has_key("access"):
            # Submitted through WebSubmit. Check rights
            include_headers = True
            working_dir = os.path.join(CFG_WEBSUBMIT_STORAGEDIR, argd["indir"], argd["doctype"], argd["access"])
            try:
                assert working_dir == os.path.abspath(working_dir)
            except AssertionError:
                return apache.HTTP_UNAUTHORIZED
            try:
                # Retrieve recid from working_dir, safer.
                recid_fd = file(os.path.join(working_dir, "SN"))
                recid = int(recid_fd.read())
                recid_fd.close()
            except:
                recid = ""
            try:
                act_fd = file(os.path.join(working_dir, "act"))
                action = act_fd.read()
                act_fd.close()
            except:
                action = ""

            # Is user authorized to perform this action?
            (auth_code, auth_msg) = acc_authorize_action(user_info, "submit", doctype=argd["doctype"], act=action)
            if not acc_is_role("submit", doctype=argd["doctype"], act=action):
                # There is NO authorization plugged. User should have access
                auth_code = 0
        else:
            # User must be allowed to attach files
            (auth_code, auth_msg) = acc_authorize_action(user_info, "runbibdocfile")
            recid = argd["recid"]

        if auth_code:
            return apache.HTTP_UNAUTHORIZED

        return create_file_upload_interface(
            recid=recid,
            ln=argd["ln"],
            print_outside_form_tag=False,
            print_envelope=False,
            form=form,
            include_headers=include_headers,
            sbm_indir=argd["indir"],
            sbm_access=argd["access"],
            sbm_doctype=argd["doctype"],
            uid=user_info["uid"],
        )[1]
コード例 #2
0
def Create_Upload_Files_Interface(parameters, curdir, form, user_info=None):
    """
    List files for revisions.

    You should use Move_Uploaded_Files_to_Storage.py function in your
    submission to apply the changes performed by users with this
    interface.

    @param parameters:(dictionary) - must contain:

      + maxsize: the max size allowed for uploaded files

      + minsize: the max size allowed for uploaded files

      + doctypes: the list of doctypes (like 'Main' or 'Additional')
                  and their description that users can choose from
                  when adding new files.
                   - When no value is provided, users cannot add new
                     file (they can only revise/delete/add format)
                   - When a single value is given, it is used as
                     default doctype for all new documents
                  Eg:
                    main=Main document|additional=Figure, schema. etc
                  ('=' separates doctype and description
                   '|' separates each doctype/description group)

      + restrictions: the list of restrictions (like 'Restricted' or
                      'No Restriction') and their description that
                      users can choose from when adding/revising
                      files. Restrictions can then be configured at
                      the level of WebAccess.
                      - When no value is provided, no restriction is
                        applied
                      - When a single value is given, it is used as
                        default resctriction for all documents.
                      - The first value of the list is used as default
                        restriction if the user if not given the
                        choice of the restriction. CHOOSE THE ORDER!
                      Eg:
                        =No restriction|restr=Restricted
                      ('=' separates restriction and description
                      '|' separates each restriction/description group)

      + canDeleteDoctypes: the list of doctypes that users are
                           allowed to delete.
                           Eg:
                             Main|Additional
                           ('|' separated values)
                           Use '*' for all doctypes

      + canReviseDoctypes: the list of doctypes that users are
                           allowed to revise
                           Eg:
                             Main|Additional
                           ('|' separated values)
                           Use '*' for all doctypes

      + canDescribeDoctypes: the list of doctypes that users are
                            allowed to describe
                            Eg:
                              Main|Additional
                            ('|' separated values)
                            Use '*' for all doctypes

      + canCommentDoctypes: the list of doctypes that users are
                            allowed to comment
                            Eg:
                              Main|Additional
                            ('|' separated values)
                            Use '*' for all doctypes

      + canKeepDoctypes: the list of doctypes for which users can
                         choose to keep previous versions visible when
                         revising a file (i.e. 'Keep previous version'
                         checkbox). See also parameter 'keepDefault'.
                         Note that this parameter is ~ignored when
                         revising the attributes of a file (comment,
                         description) without uploading a new
                         file. See also parameter
                         Move_Uploaded_Files_to_Storage.forceFileRevision
                         Eg:
                           Main|Additional
                         ('|' separated values)
                         Use '*' for all doctypes


      + canAddFormatDoctypes: the list of doctypes for which users can
                              add new formats. If there is no value,
                              then no 'add format' link nor warning
                              about losing old formats are displayed.
                              Eg:
                                Main|Additional
                              ('|' separated values)
                              Use '*' for all doctypes

      + canRestrictDoctypes: the list of doctypes for which users can
                             choose the access restrictions when adding or
                             revising a file. If no value is given:
                             - no restriction is applied if none is defined
                               in the 'restrictions' parameter.
                             - else the *first* value of the 'restrictions'
                               parameter is used as default restriction.
                             Eg:
                               Main|Additional
                             ('|' separated values)
                             Use '*' for all doctypes

      + canRenameDoctypes: the list of doctypes that users are allowed
                           to rename (when revising)
                           Eg:
                             Main|Additional
                           ('|' separated values)
                           Use '*' for all doctypes

      + canNameNewFiles: if user can choose the name of the files they
                         upload (1) or not (0)

      + defaultFilenameDoctypes: Rename uploaded files to admin-chosen
                                 values. List here the the files in
                                 current submission directory that
                                 contain the names to use for each doctype.
                                 Eg:
                                 Main=RN|Additional=additional_filename
                                 ('=' separates doctype and file in curdir
                                 '|' separates each doctype/file group).

                                 If the same doctype is submitted
                                 several times, a"-%i" suffix is added
                                 to the name defined in the file.

                                 The default filenames are overriden
                                 by user-chosen names if you allow
                                 'canNameNewFiles' or
                                 'canRenameDoctypes'.

      + maxFilesDoctypes: the maximum number of files that users can
                          upload for each doctype.
                          Eg:
                            Main=1|Additional=2
                          ('|' separated values)

                          Do not specify the doctype here to have an
                          unlimited number of files for a given
                          doctype.

      + createRelatedFormats: if uploaded files get converted to
                              whatever format we can (1) or not (0)

      + keepDefault: the default behaviour for keeping or not previous
                     version of files when users cannot choose (no
                     value in canKeepDoctypes): keep (1) or not (0)
                     Note that this parameter is ignored when revising
                     the attributes of a file (comment, description)
                     without uploading a new file. See also parameter
                     Move_Uploaded_Files_to_Storage.forceFileRevision

      + showLinks: if we display links to files (1) when possible or
                   not (0)

      + fileLabel: the label for the file field

      + filenameLabel: the label for the file name field

      + descriptionLabel: the label for the description field

      + commentLabel: the label for the comments field

      + restrictionLabel: the label in front of the restrictions list

      + startDoc: the name of a file in curdir that contains some
                  text/markup to be printed *before* the file revision
                  box

      + endDoc: the name of a file in curdir that contains some
                text/markup to be printed *after* the file revision
                box

    """
    global sysno
    ln = wash_language(form['ln'])
    _ = gettext_set_language(ln)
    out = ''

    ## Fetch parameters defined for this function
    (minsize, maxsize, doctypes_and_desc, doctypes,
     can_delete_doctypes, can_revise_doctypes, can_describe_doctypes,
     can_comment_doctypes, can_keep_doctypes, can_rename_doctypes,
     can_add_format_to_doctypes, createRelatedFormats_p,
     can_name_new_files, keep_default, show_links, file_label,
     filename_label, description_label, comment_label, startDoc,
     endDoc, restrictions_and_desc, can_restrict_doctypes,
     restriction_label, doctypes_to_default_filename,
     max_files_for_doctype) = \
     wash_function_parameters(parameters, curdir, ln)


    try:
        recid = int(sysno)
    except:
        recid = None

    out += '<center>'
    out += startDoc
    out += create_file_upload_interface(recid,
                                        form=form,
                                        print_outside_form_tag=True,
                                        print_envelope=True,
                                        include_headers=True,
                                        ln=ln,
                                        minsize=minsize, maxsize=maxsize,
                                        doctypes_and_desc=doctypes_and_desc,
                                        can_delete_doctypes=can_delete_doctypes,
                                        can_revise_doctypes=can_revise_doctypes,
                                        can_describe_doctypes=can_describe_doctypes,
                                        can_comment_doctypes=can_comment_doctypes,
                                        can_keep_doctypes=can_keep_doctypes,
                                        can_rename_doctypes=can_rename_doctypes,
                                        can_add_format_to_doctypes=can_add_format_to_doctypes,
                                        create_related_formats=createRelatedFormats_p,
                                        can_name_new_files=can_name_new_files,
                                        keep_default=keep_default, show_links=show_links,
                                        file_label=file_label, filename_label=filename_label,
                                        description_label=description_label, comment_label=comment_label,
                                        restrictions_and_desc=restrictions_and_desc,
                                        can_restrict_doctypes=can_restrict_doctypes,
                                        restriction_label=restriction_label,
                                        doctypes_to_default_filename=doctypes_to_default_filename,
                                        max_files_for_doctype=max_files_for_doctype,
                                        sbm_indir=None, sbm_doctype=None, sbm_access=None,
                                        uid=None, sbm_curdir=curdir)[1]
    out += endDoc
    out += '</center>'


    return out
コード例 #3
0
    def managedocfiles(self, req, form):
        """
        Display admin interface to manage files of a record
        """
        argd = wash_urlargd(
            form, {"ln": (str, ""), "access": (str, ""), "recid": (int, None), "do": (int, 0), "cancel": (str, None)}
        )

        _ = gettext_set_language(argd["ln"])
        uid = getUid(req)
        user_info = collect_user_info(req)
        # Check authorization
        (auth_code, auth_msg) = acc_authorize_action(req, "runbibdocfile")
        if auth_code and user_info["email"] == "guest":
            # Ask to login
            target = "/youraccount/login" + make_canonical_urlargd(
                {"ln": argd["ln"], "referer": CFG_SITE_URL + user_info["uri"]}, {}
            )
            return redirect_to_url(req, target)
        elif auth_code:
            return page_not_authorized(
                req, referer="/submit/managedocfiles", uid=uid, text=auth_msg, ln=argd["ln"], navmenuid="admin"
            )

        # Prepare navtrail
        navtrail = """<a class="navtrail" href="%(CFG_SITE_URL)s/help/admin">Admin Area</a> &gt; %(manage_files)s""" % {
            "CFG_SITE_URL": CFG_SITE_URL,
            "manage_files": _("Manage Document Files"),
        }

        body = ""
        if argd["do"] != 0 and not argd["cancel"]:
            # Apply modifications
            working_dir = os.path.join(CFG_TMPDIR, "websubmit_upload_interface_config_" + str(uid), argd["access"])
            move_uploaded_files_to_storage(
                working_dir=working_dir,
                recid=argd["recid"],
                icon_sizes=["180>", "700>"],
                create_icon_doctypes=["*"],
                force_file_revision=False,
            )
            # Clean temporary directory
            shutil.rmtree(working_dir)

            # Confirm modifications
            body += '<p style="color:#0f0">%s</p>' % (
                _("Your modifications to record #%i have been submitted") % argd["recid"]
            )
        elif argd["cancel"]:
            # Clean temporary directory
            working_dir = os.path.join(CFG_TMPDIR, "websubmit_upload_interface_config_" + str(uid), argd["access"])
            shutil.rmtree(working_dir)
            body += '<p style="color:#c00">%s</p>' % (
                _("Your modifications to record #%i have been cancelled") % argd["recid"]
            )

        if not argd["recid"] or argd["do"] != 0:
            body += """
        <form method="post" action="%(CFG_SITE_URL)s/submit/managedocfiles">
        <label for="recid">%(edit_record)s:</label>
        <input type="text" name="recid" id="recid" />
        <input type="submit" value="%(edit)s" class="adminbutton" />
        </form>
        """ % {
                "edit": _("Edit"),
                "edit_record": _("Edit record"),
                "CFG_SITE_URL": CFG_SITE_URL,
            }

        access = time.strftime("%Y%m%d_%H%M%S")
        if argd["recid"] and argd["do"] == 0:
            # Displaying interface to manage files
            # Prepare navtrail
            title, description, keywords = websearch_templates.tmpl_record_page_header_content(
                req, argd["recid"], argd["ln"]
            )
            navtrail = """<a class="navtrail" href="%(CFG_SITE_URL)s/help/admin">Admin Area</a> &gt;
        <a class="navtrail" href="%(CFG_SITE_URL)s/submit/managedocfiles">%(manage_files)s</a> &gt;
        %(record)s: %(title)s
        """ % {
                "CFG_SITE_URL": CFG_SITE_URL,
                "title": title,
                "manage_files": _("Document File Manager"),
                "record": _("Record #%i") % argd["recid"],
            }

            # FIXME: add parameters to `runbibdocfile' in order to
            # configure the file editor based on role, or at least
            # move configuration below to some config file.
            body += create_file_upload_interface(
                recid=argd["recid"],
                ln=argd["ln"],
                doctypes_and_desc=[
                    ("main", "Main document"),
                    ("latex", "LaTeX"),
                    ("source", "Source"),
                    ("additional", "Additional File"),
                    ("audio", "Audio file"),
                    ("video", "Video file"),
                    ("script", "Script"),
                    ("data", "Data"),
                    ("figure", "Figure"),
                    ("schema", "Schema"),
                    ("graph", "Graph"),
                    ("image", "Image"),
                    ("drawing", "Drawing"),
                    ("slides", "Slides"),
                ],
                can_revise_doctypes=["*"],
                can_comment_doctypes=["*"],
                can_describe_doctypes=["*"],
                can_delete_doctypes=["*"],
                can_keep_doctypes=["*"],
                can_rename_doctypes=["*"],
                can_add_format_to_doctypes=["*"],
                can_restrict_doctypes=["*"],
                restrictions_and_desc=[("", "Public"), ("restricted", "Restricted")],
                uid=uid,
                sbm_access=access,
                display_hidden_files=True,
            )[1]

            body += """<br />
            <form method="post" action="%(CFG_SITE_URL)s/submit/managedocfiles">
            <input type="hidden" name="recid" value="%(recid)s" />
            <input type="hidden" name="do" value="1" />
            <input type="hidden" name="access" value="%(access)s" />
            <input type="hidden" name="ln" value="%(ln)s" />
            <div style="font-size:small">
    <input type="submit" name="cancel" value="%(cancel_changes)s" />
    <input type="submit" onclick="user_must_confirm_before_leaving_page=false;return true;" class="adminbutton" name="submit" id="applyChanges" value="%(apply_changes)s" />
    </div></form>""" % {
                "apply_changes": _("Apply changes"),
                "cancel_changes": _("Cancel all changes"),
                "recid": argd["recid"],
                "access": access,
                "ln": argd["ln"],
                "CFG_SITE_URL": CFG_SITE_URL,
            }

            body += websubmit_templates.tmpl_page_do_not_leave_submission_js(argd["ln"], enabled=True)

        return page(
            title=_("Document File Manager") + (argd["recid"] and (": " + _("Record #%i") % argd["recid"]) or ""),
            navtrail=navtrail,
            navtrail_append_title_p=0,
            metaheaderadd=get_upload_file_interface_javascript(form_url_params="?access=" + access)
            + get_upload_file_interface_css(),
            body=body,
            uid=uid,
            language=argd["ln"],
            req=req,
            navmenuid="admin",
        )
コード例 #4
0
def Create_Upload_Files_Interface(parameters, curdir, form, user_info=None):
    """
    List files for revisions.

    You should use Move_Uploaded_Files_to_Storage.py function in your
    submission to apply the changes performed by users with this
    interface.

    @param parameters:(dictionary) - must contain:

      + maxsize: the max size allowed for uploaded files

      + minsize: the max size allowed for uploaded files

      + doctypes: the list of doctypes (like 'Main' or 'Additional')
                  and their description that users can choose from
                  when adding new files.
                   - When no value is provided, users cannot add new
                     file (they can only revise/delete/add format)
                   - When a single value is given, it is used as
                     default doctype for all new documents
                  Eg:
                    main=Main document|additional=Figure, schema. etc
                  ('=' separates doctype and description
                   '|' separates each doctype/description group)

      + restrictions: the list of restrictions (like 'Restricted' or
                      'No Restriction') and their description that
                      users can choose from when adding/revising
                      files. Restrictions can then be configured at
                      the level of WebAccess.
                      - When no value is provided, no restriction is
                        applied
                      - When a single value is given, it is used as
                        default resctriction for all documents.
                      - The first value of the list is used as default
                        restriction if the user if not given the
                        choice of the restriction. CHOOSE THE ORDER!
                      Eg:
                        =No restriction|restr=Restricted
                      ('=' separates restriction and description
                      '|' separates each restriction/description group)

      + canDeleteDoctypes: the list of doctypes that users are
                           allowed to delete.
                           Eg:
                             Main|Additional
                           ('|' separated values)
                           Use '*' for all doctypes

      + canReviseDoctypes: the list of doctypes that users are
                           allowed to revise
                           Eg:
                             Main|Additional
                           ('|' separated values)
                           Use '*' for all doctypes

      + canDescribeDoctypes: the list of doctypes that users are
                            allowed to describe
                            Eg:
                              Main|Additional
                            ('|' separated values)
                            Use '*' for all doctypes

      + canCommentDoctypes: the list of doctypes that users are
                            allowed to comment
                            Eg:
                              Main|Additional
                            ('|' separated values)
                            Use '*' for all doctypes

      + canKeepDoctypes: the list of doctypes for which users can
                         choose to keep previous versions visible when
                         revising a file (i.e. 'Keep previous version'
                         checkbox). See also parameter 'keepDefault'.
                         Note that this parameter is ~ignored when
                         revising the attributes of a file (comment,
                         description) without uploading a new
                         file. See also parameter
                         Move_Uploaded_Files_to_Storage.forceFileRevision
                         Eg:
                           Main|Additional
                         ('|' separated values)
                         Use '*' for all doctypes


      + canAddFormatDoctypes: the list of doctypes for which users can
                              add new formats. If there is no value,
                              then no 'add format' link nor warning
                              about losing old formats are displayed.
                              Eg:
                                Main|Additional
                              ('|' separated values)
                              Use '*' for all doctypes

      + canRestrictDoctypes: the list of doctypes for which users can
                             choose the access restrictions when adding or
                             revising a file. If no value is given:
                             - no restriction is applied if none is defined
                               in the 'restrictions' parameter.
                             - else the *first* value of the 'restrictions'
                               parameter is used as default restriction.
                             Eg:
                               Main|Additional
                             ('|' separated values)
                             Use '*' for all doctypes

      + canRenameDoctypes: the list of doctypes that users are allowed
                           to rename (when revising)
                           Eg:
                             Main|Additional
                           ('|' separated values)
                           Use '*' for all doctypes

      + canNameNewFiles: if user can choose the name of the files they
                         upload (1) or not (0)

      + defaultFilenameDoctypes: Rename uploaded files to admin-chosen
                                 values. List here the the files in
                                 current submission directory that
                                 contain the names to use for each doctype.
                                 Eg:
                                 Main=RN|Additional=additional_filename
                                 ('=' separates doctype and file in curdir
                                 '|' separates each doctype/file group).

                                 If the same doctype is submitted
                                 several times, a"-%i" suffix is added
                                 to the name defined in the file.

                                 The default filenames are overriden
                                 by user-chosen names if you allow
                                 'canNameNewFiles' or
                                 'canRenameDoctypes'.

      + maxFilesDoctypes: the maximum number of files that users can
                          upload for each doctype.
                          Eg:
                            Main=1|Additional=2
                          ('|' separated values)

                          Do not specify the doctype here to have an
                          unlimited number of files for a given
                          doctype.

      + createRelatedFormats: if uploaded files get converted to
                              whatever format we can (1) or not (0)

      + keepDefault: the default behaviour for keeping or not previous
                     version of files when users cannot choose (no
                     value in canKeepDoctypes): keep (1) or not (0)
                     Note that this parameter is ignored when revising
                     the attributes of a file (comment, description)
                     without uploading a new file. See also parameter
                     Move_Uploaded_Files_to_Storage.forceFileRevision

      + showLinks: if we display links to files (1) when possible or
                   not (0)

      + fileLabel: the label for the file field

      + filenameLabel: the label for the file name field

      + descriptionLabel: the label for the description field

      + commentLabel: the label for the comments field

      + restrictionLabel: the label in front of the restrictions list

      + startDoc: the name of a file in curdir that contains some
                  text/markup to be printed *before* the file revision
                  box

      + endDoc: the name of a file in curdir that contains some
                text/markup to be printed *after* the file revision
                box

    """
    global sysno
    ln = wash_language(form['ln'])
    _ = gettext_set_language(ln)
    out = ''

    ## Fetch parameters defined for this function
    (minsize, maxsize, doctypes_and_desc, doctypes,
     can_delete_doctypes, can_revise_doctypes, can_describe_doctypes,
     can_comment_doctypes, can_keep_doctypes, can_rename_doctypes,
     can_add_format_to_doctypes, createRelatedFormats_p,
     can_name_new_files, keep_default, show_links, file_label,
     filename_label, description_label, comment_label, startDoc,
     endDoc, restrictions_and_desc, can_restrict_doctypes,
     restriction_label, doctypes_to_default_filename,
     max_files_for_doctype) = \
     wash_function_parameters(parameters, curdir, ln)


    try:
        recid = int(sysno)
    except:
        recid = None

    out += '<center>'
    out += startDoc
    out += create_file_upload_interface(recid,
                                        form=form,
                                        print_outside_form_tag=True,
                                        print_envelope=True,
                                        include_headers=True,
                                        ln=ln,
                                        minsize=minsize, maxsize=maxsize,
                                        doctypes_and_desc=doctypes_and_desc,
                                        can_delete_doctypes=can_delete_doctypes,
                                        can_revise_doctypes=can_revise_doctypes,
                                        can_describe_doctypes=can_describe_doctypes,
                                        can_comment_doctypes=can_comment_doctypes,
                                        can_keep_doctypes=can_keep_doctypes,
                                        can_rename_doctypes=can_rename_doctypes,
                                        can_add_format_to_doctypes=can_add_format_to_doctypes,
                                        create_related_formats=createRelatedFormats_p,
                                        can_name_new_files=can_name_new_files,
                                        keep_default=keep_default, show_links=show_links,
                                        file_label=file_label, filename_label=filename_label,
                                        description_label=description_label, comment_label=comment_label,
                                        restrictions_and_desc=restrictions_and_desc,
                                        can_restrict_doctypes=can_restrict_doctypes,
                                        restriction_label=restriction_label,
                                        doctypes_to_default_filename=doctypes_to_default_filename,
                                        max_files_for_doctype=max_files_for_doctype,
                                        sbm_indir=None, sbm_doctype=None, sbm_access=None,
                                        uid=None, sbm_curdir=curdir)[1]
    out += endDoc
    out += '</center>'


    return out