class UserController extends BaseController {

    @RequestMapping(path = "", method = RequestMethod.GET)
    public String index(
        final Model model,
        final Pageable pageable,
        @RequestParam Map<String,String> allParams,
        final RedirectAttributes redirectAttributes
    ) {
        // Setup breadcrumbs
        setupBreadCrumbs(model, null, null);

        // Check for LDAP auth method and restrict access.
        if (redirectIfUsingLdapAuthentication(redirectAttributes)) {
            return "redirect:/";
        }

        final Datatable.Builder<User> builder = Datatable.newBuilder(User.class)
            .withRepository(userRepository)
            .withPageable(pageable)
            .withRequestParams(allParams)
            .withUrl("/configuration/user")
            .withLabel("Users")
            // Only show active users.
            .withConstraint("isActive", true, ConstraintOperator.EQUALS)
            // With Create Link
            .withCreateLink("/configuration/user/create")
            // Email Column
            .withColumn(DatatableColumn.newBuilder(User.class)
                .withFieldName("email")
                .withLabel("Email")
                .withRenderFunction(User::getEmail)
                .withIsSortable(true)
                .build())
            // Name Column
            .withColumn(DatatableColumn.newBuilder(User.class)
                .withFieldName("displayName")
                .withLabel("Name")
                .withRenderFunction(User::getDisplayName)
                .withIsSortable(true)
                .build())
            // Role Column
            .withColumn(DatatableColumn.newBuilder(User.class)
                .withFieldName("role")
                .withLabel("Role")
                .withRenderFunction((user) -> {
                    switch (user.getRole()) {
                        case ROLE_ADMIN:
                            return "Admin";
                        case ROLE_USER:
                            return "User";
                        default:
                            return "Unknown";
                    }
                })
                .withIsSortable(true)
                .build())
            // Action Column
            .withColumn(DatatableColumn.newBuilder(User.class)
                .withLabel("Action")
                .withFieldName("id")
                .withIsSortable(false)
                .withHeaderAlignRight()
                .withRenderTemplate(ActionTemplate.newBuilder(User.class)
                    // Edit Link
                    .withEditLink(User.class, (record) -> "/configuration/user/edit/" + record.getId())
                    // Delete Link
                    .withDeleteLink(User.class, (record) -> "/configuration/user/delete/" + record.getId())
                    .build())
                .build())
            .withSearch("email", "displayName");
            // TODO fix filters with enums
//            .withFilter(DatatableFilter.newBuilder()
//                .withField("role")
//                .withLabel("Role")
//                .withOption(UserRole.ROLE_ADMIN.name(), "Admin")
//                .withOption(UserRole.ROLE_USER.name(), "User")
//                .build()
//            );

        // Add datatable attribute
        model.addAttribute("datatable", builder.build());
        return "configuration/user/index";
    }

}