Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/graeme-f/eden
Browse files Browse the repository at this point in the history
  • Loading branch information
flavour committed Oct 8, 2012
2 parents 9a17472 + 46e81c3 commit d532d89
Show file tree
Hide file tree
Showing 22 changed files with 29,056 additions and 546 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
d83784e (2012-10-08 14:55:22)
9a17472 (2012-10-08 16:24:48)
48 changes: 37 additions & 11 deletions controllers/vulnerability.py
Expand Up @@ -609,7 +609,7 @@ def submitted_repr(id):
Return the initial of the first name and the complete last name
"""
if not id:
repr_text = current.messages.NONE
repr_text = T("Imported data")
else:
table = db.pr_person
row = db(table.id == id).select(table.first_name,
Expand All @@ -626,8 +626,11 @@ def approved_repr(id):
"""
Return the initials of the first and the last name
"""
if not id:

if id is None:
repr_text = T("Approval pending")
elif id == 0:
repr_text = T("Approved")
else:
table = db.pr_person
row = db(table.id == id).select(table.first_name,
Expand All @@ -646,11 +649,12 @@ def action_repr(id):
"""
Return the action button for this row
"""
if not id:

if id is None:
repr_text = current.messages.NONE
else:
row = s3db.stats_group[id]
if row.approved_by:
if row.approved_by != None:
repr_text = A(T("View"),
_id = id,
_class = "viewButton",
Expand Down Expand Up @@ -966,6 +970,7 @@ def approveReport(id):
query = (s3db.stats_data.group_id == id)
resource = s3db.resource("stats_data", filter=query, unapproved=True)
resource.approve()
s3task.async("stats_group_clean")
return True
rec_instance = record.stats_group_instance
if rec_instance == "doc_image":
Expand All @@ -974,6 +979,12 @@ def approveReport(id):
resource = s3db.resource("doc_image", filter=query, unapproved=True)
resource.approve()
return True
elif rec_instance == "doc_document":
query = (sgtable.id == id) &\
(s3db.doc_document.source_id == sgtable.source_id)
resource = s3db.resource("doc_document", filter=query, unapproved=True)
resource.approve()
return True
return False

# -----------------------------------------------------------------------------
Expand Down Expand Up @@ -1025,12 +1036,18 @@ def report():
reportDetails = getReportDetails(id, buttonsRequired=buttonsRequired)
data = json.dumps(reportDetails)
elif request.args(0) == "approve":
id = request.post_vars.id
if approveReport(id):
report = reportDataTable(request)
data = json.dumps(report)
# Check authorization
permitted = current.auth.s3_has_permission
authorised = permitted("approve", "stats_group")
if not authorised:
data = json.dumps(str(T("You are not permitted to approve documents")))
else:
data = json.dumps(str(T("Failed to approve")))
id = request.post_vars.id
if approveReport(id):
report = reportDataTable(request)
data = json.dumps(report)
else:
data = json.dumps(str(T("Failed to approve")))
elif request.args(0) == "decline":
id = request.post_vars.id
if declineReport(id):
Expand Down Expand Up @@ -1127,8 +1144,17 @@ def import_vul_part1():
response.headers["Content-Type"] = "application/json"
return json({"Error": str(T("Error File missing"))})

# Check authorization
permitted = current.auth.s3_has_permission
authorised = permitted("create", "vulnerability_data")
if not authorised:
response.headers["Content-Type"] = "application/json"
return json({"Error": str(T("You are not permitted to upload files"))})

from lxml import etree
from datetime import datetime

creator = auth.s3_logged_in_person()
output = s3_rest_controller("vulnerability", "data",
csv_stylesheet="data.xsl")
upload_id = output[0]
Expand Down Expand Up @@ -1174,8 +1200,8 @@ def import_vul_part1():
row = group[0]
group_dict = {}
group_dict["group"] = key
group_dict["date"] = row["date"]
group_dict["created_by"] = row["created_by"]
group_dict["date"] = datetime.strptime(row["date"], "%Y-%m-%d").strftime("%d-%b-%y")
group_dict["created_by"] = creator
loc = row["location_id"][1][12:] # strip location L#: from the tuid
loc = "%s %s" % (loc, loc_label)
group_dict["location"] = loc
Expand Down
14 changes: 14 additions & 0 deletions models/tasks.py
Expand Up @@ -175,6 +175,20 @@ def msg_search_subscription_notifications(frequency):
# -----------------------------------------------------------------------------
if settings.has_module("stats"):

def stats_group_clean(user_id=None):
"""
Update the stats_aggregate table by calculating all the stats_group
records which have the dirty flag set to True
"""
if user_id:
# Authenticate
auth.s3_impersonate(user_id)
# Run the Task
result = s3db.stats_group_clean()
return result

tasks["stats_group_clean"] = stats_group_clean

def stats_update_time_aggregate(data_id=None, user_id=None):
"""
Update the stats_aggregate table for the given stats_data record
Expand Down

0 comments on commit d532d89

Please sign in to comment.