Blame action/sslcert.py

Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
import exception
Ivan Mahonin 9e1462
from action.action import Action
Ivan Mahonin 9e1462
from action.user import UserBase
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
class SslcertCreate(UserBase):
Ivan Mahonin 9e1462
  def process(self, request):
Ivan Mahonin 9e1462
    user_id = self.parse_user_id(request)
Ivan Mahonin 9e1462
    data = request.model.sslcerts.extract_data( str(request.postvars.get('data', '')) )
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
    user = request.model.users.get_by_id(user_id)
Ivan Mahonin 9e1462
    if not user:
Ivan Mahonin 9e1462
      raise exception.ActionError( request.t('User not found') )
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
    sslcert = None
Ivan Mahonin 9e1462
    try:
Ivan Mahonin 9e1462
      sslcert = request.model.sslcerts.create(user, data)
Ivan Mahonin 9e1462
    except Exception as e:
Ivan Mahonin 9e1462
      self.propagate_exception(e)
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
    request.connection.commit()
Ivan Mahonin 9e1462
    return self.redirect_to_user(request, user, ['edit'])
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
class SslcertDelete(UserBase):
Ivan Mahonin 9e1462
  def process(self, request):
Ivan Mahonin 9e1462
    sslcert_id = 0
Ivan Mahonin 9e1462
    try:
Ivan Mahonin 9e1462
      sslcert_id = int(request.postvars.get('sslcert_id', 0))
Ivan Mahonin 9e1462
    except Exception:
Ivan Mahonin 9e1462
      raise exception.ActionError( request.t('SSL Certificate Id incorrect') )
Ivan Mahonin 9e1462
    if not sslcert_id:
Ivan Mahonin 9e1462
      raise exception.ActionError( request.t('SSL Certificate Id incorrect') )
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
    sslcert = request.model.sslcerts.get_by_id(sslcert_id)
Ivan Mahonin 9e1462
    if not sslcert:
Ivan Mahonin 9e1462
      raise exception.ActionError( request.t('SSL Certificate not found') )
Ivan Mahonin 9e1462
    user = sslcert.get_user()
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
    try:
Ivan Mahonin 9e1462
      sslcert.delete()
Ivan Mahonin 9e1462
    except Exception as e:
Ivan Mahonin 9e1462
      self.propagate_exception(e)
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
    request.connection.commit()
Ivan Mahonin 9e1462
    return self.redirect_to_user(request, user, ['edit'])
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
Ivan Mahonin 9e1462
actions = {
Ivan Mahonin 9e1462
  'create' : SslcertCreate(),
Ivan Mahonin 9e1462
  'delete' : SslcertDelete(),
Ivan Mahonin 9e1462
}