Exemple #1
0
def delete_group(group_name):
    """
    Deletes a group.

    :status 204: Group was successfully deleted.
    :status 400: Group cannot be deleted because it is a predefined group, or
      because it has associated jobs.
    """
    group = _get_group_by_name(group_name)
    if not group.can_edit(identity.current.user):
        raise Forbidden403('Cannot edit group')
    if group.is_protected_group():
        raise BadRequest400("Group '%s' is predefined and cannot be deleted" %
                            group.group_name)
    if group.jobs:
        raise BadRequest400('Cannot delete a group which has associated jobs')
    # Record the access policy rules that will be removed
    for rule in group.system_access_policy_rules:
        rule.record_deletion()
    # For any system pool owned by this group, unset owning_group
    # and set owning_user to the user deleting this group
    pools = SystemPool.query.filter_by(owning_group=group)
    for pool in pools:
        pool.change_owner(user=identity.current.user, service=u'HTTP')
    session.delete(group)
    activity = Activity(identity.current.user, u'HTTP', u'Removed', u'Group',
                        group.display_name)
    session.add(activity)
    return '', 204
Exemple #2
0
def delete_pool(pool_name):
    """
    Deletes a system pool

    :param pool_name: System pool's name

    """
    pool = _get_pool_by_name(pool_name, lockmode='update')
    u = identity.current.user
    if not pool.can_edit(u):
        raise Forbidden403('Cannot delete pool %s' % pool_name)

    systems = System.query.filter(System.pools.contains(pool))
    System.record_bulk_activity(systems, user=identity.current.user,
                                service=u'HTTP', action=u'Removed',
                                field=u'Pool',
                                old=unicode(pool),
                                new=None)
    # Since we are deleting the pool, we will have to change the active
    # access policy for all systems using the pool's policy to their
    # custom policy
    systems = System.query.filter(System.active_access_policy == pool.access_policy)
    for system in systems:
        system.active_access_policy = system.custom_access_policy
    System.record_bulk_activity(systems, user=identity.current.user,
                                service=u'HTTP',
                                field=u'Active Access Policy', action=u'Changed',
                                old = 'Pool policy: %s' % pool_name,
                                new = 'Custom access policy')
    session.delete(pool)
    activity = Activity(u, u'HTTP', u'Deleted', u'Pool', pool_name)
    session.add(activity)
    return '', 204
Exemple #3
0
 def index(self, **kw):
     activities = Activity.all()
     activity_search = search_utility.Activity.search
     search_bar = SearchBar(activity_search.create_complete_search_table(),
                            name='activitysearch',)
     return self._activities_grid(activities, search_bar, '.',
         search_utility.Activity, **kw)
Exemple #4
0
def delete_powertype(id):
    """
    Deletes a power type by the given id.

    :param id: The id of the power type to be deleted.
    :status 204: Power type successfully deleted.
    :status 400: Power type is referenced by systems.
    :status 404: Power type can not be found.
    """
    try:
        powertype = PowerType.by_id(id)
    except NoResultFound:
        raise NotFound404('Power type: %s does not exist' % id)

    systems_referenced = System.query.join(
        System.power).filter(Power.power_type == powertype).count()
    if systems_referenced:
        raise BadRequest400('Power type %s still referenced by %i systems' %
                            (powertype.name, systems_referenced))

    session.delete(powertype)

    activity = Activity(identity.current.user, u'HTTP', u'Deleted',
                        u'PowerType', powertype.name)
    session.add(activity)

    return '', 204
Exemple #5
0
def create_powertype():
    """
    Creates a new power type. The request must be :mimetype:`application/json`.

    :jsonparam string name: Name for the power type.
    :status 201: The power type was successfully created.
    """
    data = read_json_request(request)
    with convert_internal_errors():
        if PowerType.query.filter_by(**data).count():
            raise Conflict409('Power type %s already exists' % data['name'])
        powertype = PowerType(**data)
        activity = Activity(identity.current.user, u'HTTP', u'Created',
                            u'PowerType', powertype.name)
        session.add_all([powertype, activity])

    response = jsonify(powertype.__json__())
    response.status_code = 201
    return response
Exemple #6
0
    def remove(self, **kw):
        try:
            group = Group.by_id(kw['group_id'])
        except DatabaseLookupError:
            flash(unicode('Invalid group or already removed'))
            redirect('../groups/mine')

        if not group.can_edit(identity.current.user):
            flash(_(u'You are not an owner of group %s' % group))
            redirect('../groups/mine')

        if group.is_protected_group():
            flash(
                _(u'This group %s is predefined and cannot be deleted' %
                  group))
            redirect('../groups/mine')

        if group.jobs:
            flash(_(u'Cannot delete a group which has associated jobs'))
            redirect('../groups/mine')

        # Record the access policy rules that will be removed
        # before deleting the group
        for rule in group.system_access_policy_rules:
            rule.record_deletion()

        session.delete(group)
        activity = Activity(identity.current.user, u'WEBUI', u'Removed',
                            u'Group', group.display_name, u"")
        session.add(activity)
        for system in group.systems:
            session.add(
                SystemActivity(identity.current.user,
                               u'WEBUI',
                               u'Removed',
                               u'Group',
                               group.display_name,
                               u"",
                               object=system))
        flash(_(u"%s deleted") % group.display_name)
        raise redirect(".")
Exemple #7
0
    def remove(self, **kw):
        u = identity.current.user
        try:
            group = Group.by_id(kw['group_id'])
        except DatabaseLookupError:
            flash(unicode('Invalid group or already removed'))
            redirect('../groups/mine')

        if not group.can_edit(u):
            flash(_(u'You are not an owner of group %s' % group))
            redirect('../groups/mine')

        if group.is_protected_group():
            flash(
                _(u'This group %s is predefined and cannot be deleted' %
                  group))
            redirect('../groups/mine')

        if group.jobs:
            flash(_(u'Cannot delete a group which has associated jobs'))
            redirect('../groups/mine')

        # Record the access policy rules that will be removed
        # before deleting the group
        for rule in group.system_access_policy_rules:
            rule.record_deletion()

        # For any system pool owned by this group, unset owning_group
        # and set owning_user to the user deleting this group
        pools = SystemPool.query.filter_by(owning_group_id=group.group_id)
        for pool in pools:
            pool.change_owner(user=u, service='WEBUI')
        session.delete(group)
        activity = Activity(u, u'WEBUI', u'Removed', u'Group',
                            group.display_name, u"")
        session.add(activity)
        flash(_(u"%s deleted") % group.display_name)
        raise redirect(".")