Skip to content

Commit

Permalink
DVR/DRKCM: cases are doc entities, doc controller for person perspective
Browse files Browse the repository at this point in the history
+ customised for DRKCM; rheader: controller-tabs should also be hidden if not
permitted, S3Model.update_super: leave modified_by/modified_on alone
  • Loading branch information
nursix committed Dec 13, 2017
1 parent 2c09923 commit 11ea562
Show file tree
Hide file tree
Showing 9 changed files with 120 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nursix-dev-1649-g8c2abbd (2017-12-13 09:07:13)
nursix-dev-1650-g2c09923 (2017-12-13 13:52:31)
54 changes: 54 additions & 0 deletions controllers/dvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,60 @@ def prep(r):

return s3_rest_controller("pr", "person")

# -----------------------------------------------------------------------------
def document():

def prep(r):

table = r.table
resource = r.resource

get_vars = r.get_vars
if "viewing" in get_vars:
try:
vtablename, record_id = get_vars["viewing"].split(".")
except ValueError:
return False
else:
return False

ctable = s3db.dvr_case
auth = current.auth
has_permission = auth.s3_has_permission
if vtablename == "pr_person":
if not has_permission("read", "pr_person", record_id):
r.unauthorised()
query = auth.s3_accessible_query("read", ctable) & \
(ctable.person_id == record_id) & \
(ctable.deleted == False)
elif vtablename == "dvr_case":
query = auth.s3_accessible_query("read", ctable) & \
(ctable.id == record_id) & \
(ctable.deleted == False)
else:
# Unsupported
return False

case = db(query).select(ctable.doc_id,
limitby = (0, 1),
orderby = ~ctable.modified_on,
).first()
if case:
doc_id = case.doc_id
field = r.table.doc_id
field.default = doc_id
r.resource.add_filter(FS("doc_id") == doc_id)
else:
# No case found
r.error(404, "Case not found")

return True
s3.prep = prep

return s3_rest_controller("doc", "document",
rheader = s3db.dvr_rheader,
)

# -----------------------------------------------------------------------------
def group_membership():
"""
Expand Down
1 change: 1 addition & 0 deletions languages/de.py
Original file line number Diff line number Diff line change
Expand Up @@ -4870,6 +4870,7 @@
'Upload an image file here.': 'Laden Sie hier die Grafikdatei hoch.',
'Upload an image, such as a photo': 'Laden Sie eine Grafikdatei hoch, wie beispielsweise ein Foto',
'Uploaded Image': 'Hochgeladenes Bild',
'Uploaded on': 'Hochgeladen am',
'Upload translated files': 'Übersetzte Dateien hochladen',
'Upon Request': 'Eingehende Anfrage',
'Urban Fire': 'Siedlungsfeuer',
Expand Down
4 changes: 4 additions & 0 deletions modules/s3/s3model.py
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,10 @@ def update_super(cls, table, record):

# Update the super_keys in the record
if super_keys:
# System update => don't update modified_by/on
if "modified_on" in table.fields:
super_keys["modified_by"] = table.modified_by
super_keys["modified_on"] = table.modified_on
db(table.id == record_id).update(**super_keys)

record.update(super_keys)
Expand Down
5 changes: 5 additions & 0 deletions modules/s3/s3navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1635,6 +1635,7 @@ def active(self, r):

resource = r.resource
component = self.component
function = self.function
if component:
clist = get_components(resource.table, names=[component])
is_component = False
Expand All @@ -1657,6 +1658,10 @@ def active(self, r):
handler = r.get_handler(component)
if handler is None:
return component in ("create", "read", "update", "delete")

elif function:
return current.auth.permission.has_permission("read", f=function)

return True

# -------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions modules/s3db/doc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def model(self):
deploy_mission = T("Mission"),
dc_response = T(settings.get_dc_response_label()),
doc_sitrep = T("Situation Report"),
dvr_case = T("Case"),
dvr_case_activity = T("Case Activity"),
event_event = T("Event"),
event_incident = T("Incident"),
Expand Down Expand Up @@ -135,6 +136,7 @@ def model(self):
# @ToDo: Remove since Site Instances are doc entities?
super_link("site_id", "org_site"),
Field("file", "upload",
label = T("File"),
autodelete = True,
length = current.MAX_FILENAME_LENGTH,
represent = self.doc_file_represent,
Expand Down
2 changes: 2 additions & 0 deletions modules/s3db/dvr.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ def model(self):

tablename = "dvr_case"
define_table(tablename,
self.super_link("doc_id", "doc_entity"),

# The primary case beneficiary
person_id(represent = self.pr_PersonRepresent(show_link=True),
Expand Down Expand Up @@ -549,6 +550,7 @@ def model(self):
onvalidation = self.case_onvalidation,
create_onaccept = self.case_create_onaccept,
update_onaccept = self.case_onaccept,
super_entity = ("doc_entity",),
)

# Reusable field
Expand Down
4 changes: 4 additions & 0 deletions modules/templates/DRKCM/auth_roles.csv
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ CASE_MANAGEMENT,Case Manager,,dvr,case_appointment,,CREATE|READ|UPDATE|DELETE,,,
CASE_MANAGEMENT,Case Manager,,dvr,case_appointment_type,,NONE,,,,,Case Managers can not manage DVR taxonomies
CASE_MANAGEMENT,Case Manager,,dvr,case_flag,,NONE,,,,,Case Managers can not manage DVR taxonomies
CASE_MANAGEMENT,Case Manager,,dvr,case_status,,NONE,,,,,Case Managers can not manage DVR taxonomies
CASE_MANAGEMENT,Case Manager,,dvr,document,,CREATE|READ|UPDATE|DELETE,,,,,Case Managers can manage case documents
CASE_MANAGEMENT,Case Manager,,dvr,due_followups,,CREATE|READ|UPDATE|DELETE,,,,,Case Managers can manage case activities
CASE_MANAGEMENT,Case Manager,,dvr,group_membership,,CREATE|READ|UPDATE|DELETE,,,,,Case Managers can add family members
CASE_MANAGEMENT,Case Manager,,dvr,index,,CREATE|READ|UPDATE|DELETE,,,,,Case Managers can see the DVR index page
Expand Down Expand Up @@ -138,6 +139,7 @@ ORG_GROUP_ADMIN,Organisation Group Admin,,dvr,case_appointment,,NONE,,,,,
ORG_GROUP_ADMIN,Organisation Group Admin,,dvr,case_appointment_type,,CREATE|READ|UPDATE|DELETE,,,,,
ORG_GROUP_ADMIN,Organisation Group Admin,,dvr,case_flag,,CREATE|READ|UPDATE|DELETE,,,,,
ORG_GROUP_ADMIN,Organisation Group Admin,,dvr,case_status,,CREATE|READ|UPDATE|DELETE,,,,,
ORG_GROUP_ADMIN,Organisation Group Admin,,dvr,document,,NONE,,,,,Case Managers can manage case documents
ORG_GROUP_ADMIN,Organisation Group Admin,,dvr,due_followups,,NONE,,,,,
ORG_GROUP_ADMIN,Organisation Group Admin,,dvr,group_membership,,NONE,,,,,
ORG_GROUP_ADMIN,Organisation Group Admin,,dvr,index,,CREATE|READ|UPDATE|DELETE,,,,,
Expand Down Expand Up @@ -183,6 +185,7 @@ REGISTRATION,Case Registration,,dvr,case_appointment,,NONE,,,,,
REGISTRATION,Case Registration,,dvr,case_appointment_type,,NONE,,,,,
REGISTRATION,Case Registration,,dvr,case_flag,,NONE,,,,,
REGISTRATION,Case Registration,,dvr,case_status,,NONE,,,,,
REGISTRATION,Case Registration,,dvr,document,,CREATE|READ|UPDATE|DELETE,,,,,Registration can manage case documents
REGISTRATION,Case Registration,,dvr,due_followups,,NONE,,,,,
REGISTRATION,Case Registration,,dvr,group_membership,,CREATE|READ|UPDATE|DELETE,,,,,
REGISTRATION,Case Registration,,dvr,index,,CREATE|READ|UPDATE|DELETE,,,,,
Expand Down Expand Up @@ -236,6 +239,7 @@ TRACING,Tracing Service,,dvr,case_appointment,,NONE,,,,,
TRACING,Tracing Service,,dvr,case_appointment_type,,NONE,,,,,
TRACING,Tracing Service,,dvr,case_flag,,NONE,,,,,
TRACING,Tracing Service,,dvr,case_status,,NONE,,,,,
TRACING,Tracing Service,,dvr,document,,NONE,,,,,
TRACING,Tracing Service,,dvr,due_followups,,NONE,,,,,
TRACING,Tracing Service,,dvr,group_membership,,READ,,,,,
TRACING,Tracing Service,,dvr,index,,READ,,,,,
Expand Down
47 changes: 47 additions & 0 deletions modules/templates/DRKCM/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,52 @@ def drk_realm_entity(table, row):
# Issue a "not checked-in" warning in case event registration
#settings.dvr.event_registration_checkin_warning = True

# -------------------------------------------------------------------------
def customise_doc_document_resource(r, tablename):

if r.controller == "dvr":

s3db = current.s3db
table = s3db.doc_document

# Hide URL field
field = table.url
field.readable = field.writable = False

# Custom label for date-field
field = table.date
field.label = T("Uploaded on")
field.default = r.utcnow.date()
field.writable = False

# Custom label for name-field
field = table.name
field.label = T("Title")

# List fields
list_fields = ["name",
"file",
"date",
"comments",
]
s3db.configure("doc_document",
list_fields = list_fields,
)

settings.customise_doc_document_resource = customise_doc_document_resource

# -------------------------------------------------------------------------
def customise_doc_document_controller(**attr):

current.deployment_settings.ui.export_formats = None

if current.request.controller == "dvr":
attr["rheader"] = drk_dvr_rheader

return attr

settings.customise_doc_document_controller = customise_doc_document_controller

# -------------------------------------------------------------------------
def customise_dvr_home():
""" Do not redirect to person-controller """
Expand Down Expand Up @@ -2519,6 +2565,7 @@ def drk_dvr_rheader(r, tabs=[]):
(T("Activities"), "case_activity"),
(T("Appointments"), "case_appointment"),
(T("Photos"), "image"),
(T("Documents"), "document/"),
(T("Notes"), "case_note"),
]

Expand Down

0 comments on commit 11ea562

Please sign in to comment.