Role specific tasks

defp tasks do
[
%{value: “”, label: “”, description: nil},
%{
value: “A”,
label: “A”,
description: “A”
},
%{
value: “B”,
label: “B”,
description: “B”
},
%{
value: “C”,
label: “C”,
description: “C”
},
%{value: “other”, label: “Other”, description: “”}
end

  Roles -  'admin' and 'non-admin'

Right now all the tasks ‘A’, ‘B’ and ‘C’ are visible to both admin and non-admin.

Is there a way by which I can make the task ‘A’ visible only for the admin and not visible for non-admin?

Any help is greatly appreciated.

First off, a quick formatting note - use triple-backticks ``` before and after a code block to preserve indentation.

To your question: the code you’ve posted doesn’t have any connection to user roles at all, can you provide additional context?

1 Like

Yes Matt, currently there is no linking of tasks with role.

# all admin users should be able to view
  def can?(%AdminUser{}, action, Task) when action in [:index, :unassigned_index] do
    true
  end

I have the above code which makes all tasks visible to all users (admin and non-admin).
So, now I want to make it role specific as per my above post.

You need to implement something like RBAC.

As a super simple solution, You could add a Permission struct, with both role_id and task_id…

Thanks let me try it.