コード例 #1
0
    def test_is_station_owner(self, repository: Repository):
        """Tests if the ownership relation can be checked properly. The input data is defined in the db-data.psql file.
           Here it's copied for convenience: (1,1), (2,1), (3,1), (5,1), (4,2)"""
        cases = [[1, 1, True], [2, 2, False], [2, 1, True], [3, 1, True],
                 [4, 1, False], [5, 1, True], [4, 2, True]]

        for c in cases:
            # Checking if user {c[0]} owns the station {c[1]}, expected result {c[2]}
            self.assertEqual(repository.is_station_owner(c[0], c[1]), c[2])
コード例 #2
0
ファイル: obs.py プロジェクト: gut-space/svarog
def obs(obs_id: ObservationId = None, limit_and_offset=None):
    if obs_id is None:
        abort(300, description="ID is required")
        return

    repository = Repository()
    with repository.transaction():
        observation = repository.read_observation(obs_id)

        orbit = None

        if observation is None:
            abort(404, "Observation not found")

        files = repository.read_observation_files(observation["obs_id"],
                                                  **limit_and_offset)
        files_count = repository.count_observation_files(obs_id)
        satellite = repository.read_satellite(observation["sat_id"])

        orbit = observation
        if observation['tle'] is not None:
            # observation['tle'] is always an array of exactly 2 strings.
            orbit = parse_tle(*observation['tle'], satellite["sat_name"])

        station = repository.read_station(observation["station_id"])

    # Now tweak some observation parameters to make them more human readable
    observation = human_readable_obs(observation)

    # Now determine if there is a logged user and if there is, if this user is the owner of this
    # station. If he is, we should show the admin panel.
    user_id = 0
    owner = False
    if current_user.is_authenticated:
        user_id = current_user.get_id()

        # Check if the current user is the owner of the station.
        station_id = station['station_id']

        owner = repository.is_station_owner(user_id, station_id)

    return 'obs.html', dict(obs=observation,
                            files=files,
                            sat_name=satellite["sat_name"],
                            item_count=files_count,
                            orbit=orbit,
                            station=station,
                            is_owner=owner)
コード例 #3
0
ファイル: obs.py プロジェクト: gut-space/svarog
def obs_delete(obs_id: ObservationId = None):

    # First check if such an observation even exists.
    repository = Repository()
    observation = repository.read_observation(obs_id)
    if observation is None:
        return render_template('obs_delete.html',
                               status=["There is no observation %s" % obs_id],
                               obs_id=obs_id)

    # Second, check if the guy is logged in.
    if not current_user.is_authenticated:
        return render_template(
            'obs_delete.html',
            status=["You are not logged in, you can't delete anything."],
            obs_id=obs_id)

    # Ok, at least this guy is logged in. Let's check who he is.
    user_id = current_user.get_id()

    # Check if the current user is the owner of the station.
    station = repository.read_station(observation["station_id"])
    station_id = station['station_id']

    owner = repository.is_station_owner(user_id, station_id)

    if not owner:
        return render_template(
            'obs_delete.html',
            status=[
                "You are not the owner of station %s, you can't delete observation %s."
                % (station.name, obs_id)
            ],
            obs_id=obs_id)

    # If you got that far, this means the guy is logged in, he's the owner and is deleting his own observation.

    status = obs_delete_db_and_disk(repository, obs_id)
    return render_template('obs_delete.html', status=status, obs_id=obs_id)