I have written a passing condition for user which is as follows:

```
def check_admin(user):
    isAdmin = False
    if user.role == "ADMIN":
        isAdmin=True
    return isAdmin

```

This is working fine in class based view:

```
class AgentUpdate(LoginRequiredMixin,UpdateView):
    model = User
    form_class = UserUpdateForm
    template_name_suffix = '_update_form'
    success_url='/agents'

    @method_decorator(user_passes_test(check_admin))
    def dispatch(self, *args, **kwargs):
        return super(AgentUpdate, self).dispatch(*args, **kwargs)

```

Bu when i use it in function based view it is giving me error `'AnonymousUser' object has no attribute 'role'`

```
@login_required
@user_passes_test(check_admin)
def upload_topic(request):
    ---- Rest of the view---

```