Skip to content
This repository has been archived by the owner on Jun 18, 2018. It is now read-only.

Commit

Permalink
RuleListModel: restore parent class for rule list models
Browse files Browse the repository at this point in the history
  • Loading branch information
pebenito committed Dec 15, 2015
1 parent f89f875 commit fe97068
Showing 1 changed file with 30 additions and 42 deletions.
72 changes: 30 additions & 42 deletions setoolsgui/apol/rulemodels.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,34 @@
from setools.policyrep.exception import RuleNotConditional, RuleUseError


class MLSRuleListModel(QAbstractTableModel):
class RuleListModel(QAbstractTableModel):

"""MLS rule model. Represents rules as a column."""
"""Base class for rule list models."""

def __init__(self, parent):
super(MLSRuleListModel, self).__init__(parent)
super(RuleListModel, self).__init__(parent)
self.resultlist = []

def headerData(self, section, orientation, role):
raise NotImplementedError

def columnCount(self, parent=QModelIndex()):
return 5

def rowCount(self, parent=QModelIndex()):
if self.resultlist:
return len(self.resultlist)
else:
return 0

def data(self, index, role):
raise NotImplementedError


class MLSRuleListModel(RuleListModel):

"""MLS rule model. Represents rules as a column."""

def headerData(self, section, orientation, role):
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
if section == 0:
Expand All @@ -45,13 +62,7 @@ def headerData(self, section, orientation, role):
elif section == 4:
return "Default Range"
else:
raise ValueError("Invalid column number")

def rowCount(self, parent=QModelIndex()):
if self.resultlist:
return len(self.resultlist)
else:
return 0
raise ValueError("Invalid column number: {0}".format(section))

def data(self, index, role):
if role == Qt.DisplayRole:
Expand All @@ -72,23 +83,16 @@ def data(self, index, role):
elif col == 4:
return str(self.resultlist[row].default)
else:
raise ValueError("Invalid column number")
raise ValueError("Invalid column number: {0}".format(col))
elif role == Qt.UserRole:
# get the whole rule for user role
return self.resultlist[row].statement()


class RBACRuleListModel(QAbstractTableModel):
class RBACRuleListModel(RuleListModel):

"""RBAC rule model. Represents rules as a column."""

def __init__(self, parent):
super(RBACRuleListModel, self).__init__(parent)
self.resultlist = []

def columnCount(self, parent=QModelIndex()):
return 5

def headerData(self, section, orientation, role):
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
if section == 0:
Expand All @@ -102,13 +106,7 @@ def headerData(self, section, orientation, role):
elif section == 4:
return "Default Role"
else:
raise ValueError("Invalid column number")

def rowCount(self, parent=QModelIndex()):
if self.resultlist:
return len(self.resultlist)
else:
return 0
raise ValueError("Invalid column number: {0}".format(section))

def data(self, index, role):
if role == Qt.DisplayRole:
Expand Down Expand Up @@ -137,23 +135,16 @@ def data(self, index, role):
except RuleUseError:
return None
else:
raise ValueError("Invalid column number")
raise ValueError("Invalid column number: {0}".format(col))
elif role == Qt.UserRole:
# get the whole rule for user role
return self.resultlist[row].statement()


class TERuleListModel(QAbstractTableModel):
class TERuleListModel(RuleListModel):

"""Type Enforcement rule model. Represents rules as a column."""

def __init__(self, parent):
super(TERuleListModel, self).__init__(parent)
self.resultlist = []

def columnCount(self, parent=QModelIndex()):
return 6

def headerData(self, section, orientation, role):
if role == Qt.DisplayRole and orientation == Qt.Horizontal:
if section == 0:
Expand All @@ -169,13 +160,10 @@ def headerData(self, section, orientation, role):
elif section == 5:
return "Conditional Expression"
else:
raise ValueError("Invalid column number")
raise ValueError("Invalid column number: {0}".format(section))

def rowCount(self, parent=QModelIndex()):
if self.resultlist:
return len(self.resultlist)
else:
return 0
def columnCount(self, parent=QModelIndex()):
return 6

def data(self, index, role):
if role == Qt.DisplayRole:
Expand Down Expand Up @@ -204,7 +192,7 @@ def data(self, index, role):
except RuleNotConditional:
return None
else:
raise ValueError("Invalid column number")
raise ValueError("Invalid column number: {0}".format(col))
elif role == Qt.UserRole:
# get the whole rule for user role
return self.resultlist[row].statement()

0 comments on commit fe97068

Please sign in to comment.