activeadmin: how do I controle what header menu items show based on user - ruby-on-rails-3

I would like to create some logic with in my Rails app that is using ActiveAdmin backend and I'm not sure if it's possible or not.
Basically I'm wanting to give each AdminUser a new property called client_id. When the user logs in I would like to filter what is shown to them in the header menu.
Each item in the header will all have a "client_id" so that I can filter them.

It's possible, but you'll be doing a bit of custom stuff to get that working.
I'd suggest you would be way better off just rolling your own admin setup. You're going to jump through hoops and do some hackery that doesn't feel right to make everything play nice.

Related

Hide menu items for users with custom role

I have a custom role for "regular users". for those users I would like to hide / remove some of the menu items in the lower left corner:
basically all I want them to be able to do is to edit their profile, or to sign out. — I was wondering if and how that's possible.
I don't think there's a way to do this out-of-the-box now without you changing the core codebase. I've added a Feature Request to the Directus App repo:
https://github.com/directus/app/issues/1709
Give it a thumbs up and we'll try to include it soon!
Good idea!

Adding short text/badge/icon for a user

Is there a way to show a sub headline or icon for each user? We are trying to show which team each user belongs to. Is there a way to do this?
There is no in-built way of doing so. You can, however, create a plugin to add any metadata you like to a user's profile popover, including the team(s) ther are a member of.

Yii-User and Yii-eauth integration

I am trying to put together an application using yii-user and yii-eauth extensions but I am coming up short. When I create a new webapp and install eauth I can get it to work fine so I know that I am not doing anything wrong on that end. I think the problem lies with my urls. This is a demo of what it is supposed to be like: http://nodge.ru/yii-eauth/demo/login. When someone clicks on say google it should bring you to the google sign in page but on my application I am getting a 404 error that states "The system is unable to find the requested action "login"." The url for this is user/user/login/service/google_oauth whereas the url should read user/login/service/google_oauth. Upon typing this into the browser manually I am redirected to the right page.
So I took a look into the EAuthWidget.php class to see if I could find out where it was getting that extra "user" from but I could not figure it out. I think it may have something to do with the fact that I have this in the user module which is in the /modules/user directory in my webapp. I also tried to use the URLManager to point to the right address but with no luck.
Does anyone have any similar experiences setting this up? Or any suggestions?
You just need to change the widget initialization code in your view(namely change the action property of the widget), somewhat like this:
<h2>Do you already have an account on one of these sites? Click the logo to log in with it here:</h2>
<?php
$this->widget('ext.eauth.EAuthWidget', array('action' => 'login'));
?>
Just to add, keep in mind that this action depends on which view you are including this widget, if the view is protected/views/site/login.php (which is yii's default site login view) then action should be able to go to the yii-user module's login action, so it'll be : 'action'=>'/user/login' , however if you are including this widget in yii-user's protected/modules/user/views/user/login.php then the action will be 'login' as already mentioned.

ruby on rails 3, render multiple views in one view

I have a problem and I dont know how to solve it.
I have a user that log in a web site, and I identify them by session[:user_id] and user has a status page that is defined in user_controller and in status view.
So, I would like to make one page for admin, to see all the statuses from all users on one page, using already written controller and view.
Is that possible?
I could rewrite some of the code, so that I could call with params, like ?user_id=70 and then set session[:user_id]=params[:user_id], but it would be painful if I will have to rewrite whole statuses, beside i would have to maintain same code on 2 different places.
Thank you.
Dorijan
If you need more functionality in your controller, you can add more actions to it. You can also do that in a resourcefull way.
On the other hand it usually is best practice to keep controllers thin.
See: ActionController
In order to make your views reusable, you should use partials.
You could make a _user_status partial.html.erb and render a single partial for a user render all of them for an admin.
Checkout: Layouts and Rendering in Rails

How Do I Intercept Banner in WordPress?

My client wants me to make a plugin that intercepts the banner on a WordPress blog so that the existing one displays, but right beneath it, above the content and the sidebar, another banner appears. And he needs it such that it works in most themes and isn't theme-specific.
I found I could use add_action('loop_start','interceptMe') to put something at the top before posts or a single post, but it still left the sidebar on the right. I have tried using add_action('all','test') to dump out different intercepts to see if I could figure this out, but I just can't seem to get it yet. I'm thinking I may have to intercept all esc_html calls and contextually inspect that until I find one used for the banner.
Does anyone know how to intercept the banner to add another one right beneath it?
This is going to be very challenging to do. There's no consistent structure, HTML, or CSS IDs that would allow you to do cross-theme injection like this (hell, some themes don't have a header image). You will likely need to make manual changes to each theme for this.
I suppose you might insert some JavaScript that looks for an H1 tag and inserts your banner right after it. Ceejayoz is right though -- there's not consistency to different themes. One theme might use H1 for the site header and another for a Post title.