Hi,
I'm attaching what probably should have been a simple patch to show the
username + a link for deployments. This also required making User a
PermissionedObject, as well as making the DeploymentsController actually
show Deployments in the first place. I didn't aim to fully finish the
Deployments page, since it was outside the scope of this task. (You will
note that none of the buttons up top work, for example.)
I found myself writing silly lines in views like:
= deployment.user.has_privilege(@current_user, Privilege::VIEW) ?
link_to(deployment.user.name, admin_user_path(deployment.user)) :
deployment.user.name
It also occurred to me that we're probably going to want to follow this
pattern (link to an object if the user has permission to see it; just
show its name or some other attribute in a table otherwise) elsewhere as
we move forward, so I elected to create a conditional_link helper
method.
Unfortunately, this required the ability to link_to an object without
knowing its path, e.g., link_to(User.first). This works ordinarily, but
because we use namespaces, it is not possible[1]. Since we don't
duplicate routes within namespaces (there is not an /admin/users and a
/resources/users), I wrote a fairly-ugly find_link_to(object) method to
try to determine the appropriate path in support of the above.
I'm sending these as three separate patches in case the above changes
are controversial. You'll need all three patches applied in order to test,
however.
-- Matt
[1]
http://stackoverflow.com/questions/731487/rails-correct-routing-for-names...