Best way to populate a dropdown sitewide that is - cakephp

I am using CakePHP 1.3 and a layout which includes a dropdown of organizations a user has access to administer, so I'm trying to populate that dropdown with organizations that contain the userid that is logged in, but I want to populate it before the user sees anything so they can use it in the header. The dropdown needs to appear on every page once logged in. I tried adding the query to pull these organizations in the appcontroller, but userid was not yet available to use in before filter. Where or how should I do this? Should it be in session or is there a better construct to use? Element?

In my app it's no problem to use the user_id from within the beforeRender (if you are using the Auth-Component).
You can use it with $this->Auth->user('id').
I would do it like this: Check in the AppController if the user is logged in. If he is, pull your wanted information from the database (or whereever you get your information from) and store it in a variable called $dropdown for example.
If the user is not logged in, $dropdown will be false.
You now make this variable available to the view with $this->set(compact('dropdown'))
Now in your layout (this is important to you have it on every page) you can easily do a check if $dropdown is false or not. If not, you can work with your variable and show the user your wanted dropdown.

Related

Different views for different users in reactJS

I am having a problem in ReactJS. I want to create a text editor ( with ReactQuill). So, I want different accounts for each user, such that, if one person creates a note and edits it in his account, the other person should not see this.for example this is my current stage - https://wright-text.web.app. After you create your account and login you would see a note called first note because that's the note I created. What should I do so that when you login you see no notes because you have not created a note, but when I login, I should see the note I had already created. How would I do this ??
You need to add a scope to notes endpoint so that user could only GET notes, which they have created.
You need to add query parameters in the API you are fetching. For example, if you are fetching data via a GET request, add in some specific user id that you assign to your user upon validation and then fetch data of a particular user using that id as a query parameter on your API.

Drupal 7 views contextual filter restrict content based on current users role

I'd like to restrict access to a view based on the CURRENT users role. Not the author. For example, if a user has the authorized user role then they can see the content of the view. If a user is anonymous then they are shown the No Results Behavior of the view. I can't believe there is no way to do this. I know there is the Access settings, but I don't want the anonymous user given an access denied message.
One method I can think of:
Use hook_views_query_alter(). Check if the current user belongs to the set of roles you are interested in. If he doesn't, add a condition which is always false, such as 0 = 1. To see how to add such a condition in code, see the example on this page: http://api.drupal.org/api/views/views.api.php/function/hook_views_query_alter/7. The resulting view will not have any result on adding this condition.
Neerav Mehta.
Drupal Development

Website "you can do this" script

I want to create a training path for new users accessing my site. This training path must display info bubbles showing what you can do on every page, but only the first time you access it.
So, for example, if a user enters a page where there's an edit button an info box should appear next to the edit button telling the user that he can edit that page.
I will create the script myself, I just want to know what's the best method to check if the user has already seen that box or not. I was thinking about storing in database a boolean value for each info box which will be set to true if the user has seen the box. To save some queries from the DB I think I can also store the same values in localStorage or in Cookies.
What is the best practice for creating user training paths for a website?
The way I suggest is to store user id (ip or username ? ) and a bit value for each bubble like you say.
PS: for your script you can use this:
http://www.maxvergelli.com/jquery-bubble-popup/documentation/
Jérôme

Drupal 7 views exposed filter shows up even when the user does not have access to the field

I have a view that shows user profile fields in a tabular format. There is a "Country" field, which is not accessible to anonymous users. When viewed as anonymous user, the field is not shown by Views, which is correct. However, I also have the same field exposed, so that users can filter by "Country". The exposed filter shows up for anonymous user and an anonymous user can actually filter by the field, even though he does not see the field value. Am I missing something or it is normal behavior? Is there a way to force the filter to be hidden for anonymous users?
If you want to achieve this without having to do any custom coding, you can try to display the filter as a block and set the permissions on the block to display only to authenticated users.
This in fact is a known issue and detailed at http://drupal.org/node/1352654. As per the last comment in that issue this "wont fix". That's strange, and certainly not to my liking. Hopefully there will be some solution in a future version.

how to find out my current user id in other page controller after i login?

i am planing to set a permission on my event index page, which just allow certain user to view which had set when i add the event. After user click into my event, the event controller will 1st check the user id and check the event database which control the user can see which event in his calendar. The permission is added when user create a event and share to other user. Beside, how can i find the current user id to compare with my event database which is the accurate 1?
any suggestion for me to did this function?
i need to know the code and concept how i get the current user id to compare with all the event database, and allow the current user see the certain event.
thanks alot for your information.
The recommended approach for getting logged in user data is via the AuthComponent itself:
// in any controller
$userId = $this->Auth->user('id');
See Accessing the logged in user in the Auth section of the CakePHP Book.
Use sessions to save and read data for a user between pages.
Within Controllers:
// store a user id in the session
$this->Session->write('User.id', $userId);
// read a user id from the session
$userId = $this->Session->read('User.id');
Within Views:
// read a user id from the session
$userId = $session->read('User.id');
You can use any key you want if you prefer something over "User.id". I simply use this since it is what the AuthComponent defaults to if you are using that.
What you're looking for are ACLs (Access Control Lists). There's an AclComponent built into Cake which you should look into. It works together with the AuthComponent, which will hold the user id. It's a little complicated at first, but worth the hassle.
Also, for a simple approach, have a look at the model and controller settings of AuthComponent::authorize. This allows you to define an isAuthorized() method in your controller or model (your choice) which will store logic that determines access (should return true if access allowed and false if denied).
to see sessions, queries, data, and everything else that is passed from page to page in cake use this amazing little helper http://thechaw.com/debug_kit

Resources