Skip to content

Commit

Permalink
Merge branch 'master' of github.com:nursix/eden
Browse files Browse the repository at this point in the history
  • Loading branch information
nursix committed Dec 14, 2020
2 parents 69253a2 + 65a0f4e commit 0386644
Show file tree
Hide file tree
Showing 171 changed files with 12,931 additions and 8,434 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
DRKCM-1.6.3 (2020-07-15 23:07:51)
DRKCM-1.6.3-1-g69253a26a (2020-12-14 01:12:28)
190 changes: 122 additions & 68 deletions controllers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ def user():
table = auth.settings.table_user
s3_has_role = auth.s3_has_role

UNAPPROVED = request.get_vars.get("unapproved")

# Check for ADMIN first since ADMINs have all roles
ADMIN = False
if s3_has_role("ADMIN"):
Expand Down Expand Up @@ -113,11 +115,14 @@ def user():
if v else current.messages["NONE"]
date_represent = s3base.S3DateTime.date_represent
table.created_on.represent = date_represent
table.timestmp.represent = date_represent
list_fields += [(T("Roles"), "membership.group_id"),
(T("Registration"), "created_on"),
(T("Last Login"), "timestmp"),
]
if UNAPPROVED:
lappend((T("Registration"), "created_on"))
else:
table.timestmp.represent = date_represent
list_fields += [(T("Roles"), "membership.group_id"),
(T("Registration"), "created_on"),
(T("Last Login"), "timestmp"),
]

s3db.configure("auth_user",
create_next = URL(c="admin", f="user",
Expand All @@ -131,15 +136,21 @@ def user():
)

def disable_user(r, **args):
if not r.id:
user_id = r.id
if not user_id:
session.error = T("Can only disable 1 record at a time!")
redirect(URL(args=[]))

if r.id == session.auth.user.id: # we're trying to disable ourself
if user_id == session.auth.user.id: # we're trying to disable ourself
session.error = T("Cannot disable your own account!")
redirect(URL(args=[]))

db(table.id == r.id).update(registration_key = "disabled")
# Call Custom Hook, if present
ondisable = s3db.get_config("auth_user", "ondisable")
if callable(ondisable):
ondisable(user_id)

db(table.id == user_id).update(registration_key = "disabled")
session.confirmation = T("User Account has been Disabled")
redirect(URL(args=[]))

Expand Down Expand Up @@ -185,11 +196,16 @@ def link_user(r, **args):
method = "link",
action = link_user)

if UNAPPROVED:
title_list = T("Unapproved Users")
else:
title_list = T("Users")

# CRUD Strings
s3.crud_strings["auth_user"] = Storage(
label_create = T("Create User"),
title_display = T("User Details"),
title_list = T("Users"),
title_list = title_list,
title_update = T("Edit User"),
title_upload = T("Import Users"),
label_list_button = T("List Users"),
Expand Down Expand Up @@ -248,6 +264,14 @@ def rheader(r):

# Pre-processor
def prep(r):

if UNAPPROVED:
registration_key = FS("registration_key")
query = (registration_key != "disabled") & \
(registration_key != None) & \
(registration_key != "")
r.resource.add_filter(query)

if r.interactive:
s3db.configure(r.tablename,
addbtn = True,
Expand All @@ -267,7 +291,8 @@ def prep(r):
get_vars.update({"user.id":str(r.id)})
r.id = None
s3db.configure(r.tablename,
delete_next = URL(c="default", f="user/logout"))
delete_next = URL(c="default", f="user/logout"),
)
s3.crud.confirm_delete = T("You are attempting to delete your own account - are you sure you want to proceed?")

if r.http == "GET" and not r.method:
Expand All @@ -279,62 +304,79 @@ def prep(r):
def postp(r, output):
if r.interactive and isinstance(output, dict) and \
r.method in (None, "update", "create"):
# Only show the disable button if the user is not currently disabled
table = r.table
query = (table.registration_key == None) | \
(table.registration_key == "")
rows = db(query).select(table.id)
restrict = [str(row.id) for row in rows]
s3.actions = [{"label": s3_str(UPDATE),
"url": URL(c="admin", f="user",
args = ["[id]", "update"],
),
"_class": "action-btn",
},
{"label": s3_str(T("Roles")),
"url": URL(c="admin", f="user",
args = ["[id]", "roles"],
),
"_class": "action-btn",
},
{"label": s3_str(T("Disable")),
"restrict": restrict,
"url": URL(c="admin", f="user",
args = ["[id]", "disable"],
),
"_class": "action-btn",
},
]
if settings.get_auth_show_link():
s3.actions.insert(1, {"label": s3_str(T("Link")),
"restrict": restrict,
"url": URL(c="admin", f="user",
args = ["[id]", "link"],
),
"_class": "action-btn",
"_title": s3_str(T("Link (or refresh link) between User, Person & HR Record")),
}
)
# Only show the approve button if the user is currently pending
query = (table.registration_key != "disabled") & \
(table.registration_key != None) & \
(table.registration_key != "")
rows = db(query).select(table.id)
restrict = [str(row.id) for row in rows]
s3.actions.append({"label": str(T("Approve")),
"restrict": restrict,
"url": URL(c="admin", f="user",
args = ["[id]", "approve"],
),
"_class": "action-btn",
})
# Add some highlighting to the rows
query = (table.registration_key.belongs(["disabled", "pending"]))
rows = db(query).select(table.id,
table.registration_key,
)
s3.dataTableStyleDisabled = s3.dataTableStyleWarning = [str(row.id) for row in rows if row.registration_key == "disabled"]
s3.dataTableStyleAlert = [str(row.id) for row in rows if row.registration_key == "pending"]
actions = [{"label": s3_str(UPDATE),
"url": URL(c="admin", f="user",
args = ["[id]", "update"],
),
"_class": "action-btn",
},
]


if UNAPPROVED:
# Always show the Approve button
actions.append({"label": str(T("Approve")),
"url": URL(c="admin", f="user",
args = ["[id]", "approve"],
),
"_class": "action-btn",
})

else:
# Add a button to go direct to the Roles tab
actions.append({"label": s3_str(T("Roles")),
"url": URL(c="admin", f="user",
args = ["[id]", "roles"],
),
"_class": "action-btn",
})

# Only show the disable button if the user is not currently disabled
table = r.table
query = (table.registration_key == None) | \
(table.registration_key == "")
rows = db(query).select(table.id)
restrict = [str(row.id) for row in rows]
actions.append({"label": str(T("Disable")),
"restrict": restrict,
"url": URL(c="admin", f="user",
args = ["[id]", "disable"],
),
"_class": "action-btn",
})
if settings.get_auth_show_link():
actions.insert(1, {"label": s3_str(T("Link")),
"restrict": restrict,
"url": URL(c="admin", f="user",
args = ["[id]", "link"],
),
"_class": "action-btn",
"_title": s3_str(T("Link (or refresh link) between User, Person & HR Record")),
}
)
# Only show the approve button if the user is currently pending
query = (table.registration_key != "disabled") & \
(table.registration_key != None) & \
(table.registration_key != "")
rows = db(query).select(table.id)
restrict = [str(row.id) for row in rows]
actions.append({"label": str(T("Approve")),
"restrict": restrict,
"url": URL(c="admin", f="user",
args = ["[id]", "approve"],
),
"_class": "action-btn",
})

# Add some highlighting to the rows
query = (table.registration_key.belongs(["disabled", "pending"]))
rows = db(query).select(table.id,
table.registration_key,
)
s3.dataTableStyleDisabled = s3.dataTableStyleWarning = [str(row.id) for row in rows if row.registration_key == "disabled"]
s3.dataTableStyleAlert = [str(row.id) for row in rows if row.registration_key == "pending"]

s3.actions = actions

# Translate the status values
values = [{"col": 6, "key": "", "display": s3_str(T("Active"))},
Expand All @@ -348,14 +390,26 @@ def postp(r, output):
form = output.get("form", None)
if not form:
crud_button = s3base.S3CRUD.crud_button
if UNAPPROVED:
switch_view = crud_button(T("View All Users"),
_href = URL(vars = {}),
)
elif settings.get_auth_registration_requires_approval():
switch_view = crud_button(T("View Unapproved Users"),
_href = URL(vars = {"unapproved": 1}),
)
else:
switch_view = ""
output["showadd_btn"] = DIV(crud_button(T("Create User"),
_href = URL(args = ["create"])
_href = URL(args = ["create"]),
),
crud_button(T("Import Users"),
_href = URL(args = ["import"])
_href = URL(args = ["import"]),
),
switch_view,
)
return output

# Assume formstyle callable
id = "auth_user_password_two__row"
label = "%s:" % T("Verify password")
Expand Down
Loading

0 comments on commit 0386644

Please sign in to comment.