Esempio n. 1
0
def has_experiment_download_access(request, experiment_id):
    if Experiment.safe.owned_and_shared(request) \
                      .filter(id=experiment_id) \
                      .exists():
        return True
    else:
        exp = Experiment.objects.get(id=experiment_id)
        return Experiment.public_access_implies_distribution(exp.public_access)
Esempio n. 2
0
def has_experiment_download_access(request, experiment_id):
    if Experiment.safe.owned_and_shared(request) \
                      .filter(id=experiment_id) \
                      .exists():
        return True
    else:
        exp = Experiment.objects.get(id=experiment_id)
        return Experiment.public_access_implies_distribution(exp.public_access)
Esempio n. 3
0
    def clean(self):
        cleaned_data = super(RightsForm, self).clean()
        public_access = cleaned_data.get("public_access")
        license_ = cleaned_data.get("license")

        if license_ is None:
            # Only data which is not distributed can have no explicit licence
            suitable = not Experiment.public_access_implies_distribution(public_access)
        else:
            suitable = license_ in License.get_suitable_licenses(public_access)

        if not suitable:
            raise forms.ValidationError("Selected license it not suitable " + "for public access level.")

        return cleaned_data
Esempio n. 4
0
    def clean(self):
        cleaned_data = super(RightsForm, self).clean()
        public_access = cleaned_data.get("public_access")
        license_ = cleaned_data.get("license")

        if license_ is None:
            # Only data which is not distributed can have no explicit licence
            suitable = not \
                Experiment.public_access_implies_distribution(public_access)
        else:
            suitable = license_ in License.get_suitable_licenses(public_access)

        if not suitable:
            raise forms.ValidationError("Selected license it not suitable " +
                                        "for public access level.")

        return cleaned_data
Esempio n. 5
0
def run():
    if getpass.getuser() != "mytardis" or "SUDO_USER" not in os.environ:
        print "Usage: sudo -u mytardis _datafiledescriptord " + \
            "mytardis_install_dir auth_provider " + \
            "socket_path exp_id datafile_id"
        sys.exit(1)

    if len(sys.argv) < 6:
        print "Usage: sudo -u mytardis _datafiledescriptord " + \
            "mytardis_install_dir auth_provider " + \
            "socket_path exp_id datafile_id"
        sys.exit(1)

    _mytardis_install_dir = sys.argv[1].strip('"')
    _auth_provider = sys.argv[2]
    _socket_path = sys.argv[3]
    _experiment_id = int(sys.argv[4])
    _datafile_id = int(sys.argv[5])

    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    try:
        os.remove(_socket_path)
    except OSError:
        pass
    sock.bind(_socket_path)
    os.chmod(_socket_path, 0666)
    sock.listen(1)
    conn, addr = sock.accept()

    utils.setup_mytardis_paths(_mytardis_install_dir)

    from tardis.tardis_portal.models import Dataset_File, Experiment

    found_user = False
    mytardis_user = None
    exp_public = False
    exp_owned_or_shared = False
    staff_or_superuser = False
    found_datafile_in_experiment = False
    try:
        mytardis_user = utils.get_user(os.environ['SUDO_USER'], _auth_provider)
        # logger.debug("Primary MyTardis username: "******"Success"
        elif not found_datafile_in_experiment:
            fds = []
            message = "Datafile (ID %s) does not belong " + \
                "to experiment (ID %s)." % \
                (str(_datafile_id), str(_experiment_id))
        else:
            fds = []
            # message = "Access to datafile %s denied for user %s." %
            # (str(_datafile_id),os.environ['SUDO_USER'])
            message = "Access denied for user " + \
                os.environ['SUDO_USER'] + " " + \
                str(sys.argv)
        fdsend.sendfds(conn, message, fds=fds)
    except ObjectDoesNotExist:
        message = "User " + os.environ['SUDO_USER'] + \
            " was not found in MyTardis."
        fdsend.sendfds(conn, message, fds=[])
    except:
        message = traceback.format_exc()
        fdsend.sendfds(conn, message, fds=[])

    conn.close()

    try:
        os.remove(_socket_path)
    except OSError:
        pass
Esempio n. 6
0
def run():
    if getpass.getuser() != "mytardis" or "SUDO_USER" not in os.environ:
        print "Usage: sudo -u mytardis _datafiledescriptord " + \
            "mytardis_install_dir auth_provider " + \
            "socket_path exp_id datafile_id"
        sys.exit(1)

    if len(sys.argv) < 6:
        print "Usage: sudo -u mytardis _datafiledescriptord " + \
            "mytardis_install_dir auth_provider " + \
            "socket_path exp_id datafile_id"
        sys.exit(1)

    _mytardis_install_dir = sys.argv[1].strip('"')
    _auth_provider = sys.argv[2]
    _socket_path = sys.argv[3]
    _experiment_id = int(sys.argv[4])
    _datafile_id = int(sys.argv[5])

    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    try:
        os.remove(_socket_path)
    except OSError:
        pass
    sock.bind(_socket_path)
    os.chmod(_socket_path, 0666)
    sock.listen(1)
    conn, addr = sock.accept()

    sys.path.append(_mytardis_install_dir)
    for egg in os.listdir(os.path.join(_mytardis_install_dir, "eggs")):
        sys.path.append(os.path.join(_mytardis_install_dir, "eggs", egg))

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'tardis.settings')

    from tardis.tardis_portal.models import DataFile, Experiment
    from tardis.tardis_portal.models import UserAuthentication

    found_user = False
    mytardis_user = None
    exp_public = False
    exp_owned_or_shared = False
    staff_or_superuser = False
    found_datafile_in_experiment = False
    try:
        user_auth = UserAuthentication.objects\
            .get(username=os.environ['SUDO_USER'],
                 authenticationMethod=_auth_provider)
        mytardis_user = user_auth.userProfile.user
        # logger.debug("Primary MyTardis username: "******"Success"
        elif not found_datafile_in_experiment:
            fds = []
            message = "Datafile (ID %s) does not belong " + \
                "to experiment (ID %s)." % \
                (str(_datafile_id), str(_experiment_id))
        else:
            fds = []
            # message = "Access to datafile %s denied for user %s." %
            # (str(_datafile_id),os.environ['SUDO_USER'])
            message = "Access denied for user " + \
                os.environ['SUDO_USER'] + " " + \
                str(sys.argv)
        fdsend.sendfds(conn, message, fds=fds)
    except ObjectDoesNotExist:
        # FIXME: It could actually be the datafile which
        # is not found.
        message = "User " + os.environ['SUDO_USER'] + \
            " was not found in MyTardis " \
            "for authentication method " + _auth_provider
        fdsend.sendfds(conn, message, fds=[])
    except:
        message = traceback.format_exc()
        fdsend.sendfds(conn, message, fds=[])

    conn.close()

    try:
        os.remove(_socket_path)
    except OSError:
        pass