Get rows where field equal value in grocery crud - codeigniter

$crud->set_table('pages',"where permission =1"); <----------------------how to do this in the right way
$crud->set_relation('pagetype','themes','name');
$crud->set_rules('systemTTL', 'System Title', 'trim|required|min_length[4]|xss_clean|alpha_dash');
$crud->callback_add_field('title',array($this,'edit_field_callback'));
Hellooo
I have multiple users with permissions and i want to show only raws which are for certain user group ....
Thank you

Use the where method:
$crud->where('permission', 1);
Edit:
Here is the documentation.

Related

Correct Many to Many friends relationship for users

What is the correct way to relate users in parse to one another as friends?
I also want users to be able to query other users but not see all fields, like emails. Is there a way I can create a view on the users table with cloud code, and only return this to the client code?
I was thinking I can create a friends table that will have two columns with 2 pointers, 1 for each user.
thanks for any advice.
I was thinking I can create a friends table that will have two columns with 2 pointers, 1 for each user.
I'll do that too, with a status column to handle pending, blocked...etc
I also want users to be able to query other users but not see all fields, like emails.
You have to add a privateData column on user with ACL restricted to owner only, which would contain private infos such as emails...etc

Check if user is in group by group name

I may be thinking about this wrong, but shouldn't it be a very common thing to need to check if a user belongs to a certain group? For example, if you want to show a certain menu item only to "Administrators", shouldn't there be a way within my view file to easily check if the user belongs to that group?
I see that there is a inGroup() function on the user, but this requires that you first fetch the group object, and pass it into the function, rather than simply passing the group name, for example, $user->inGroup('Administrators');. I also realize I could write my own method to accept the group name, look it up, and then use that in the exiting inGroup() method.
However, the fact that this is not much more obvious in the docs makes me believe I am thinking about it in the wrong way.
Would the preferred way be to give the "Administrators" group an "admin: 1" permission, and therefore just check if the user has that permission rather than checking if they are in the group?
If so, I am struggling to see the value of a group at all since you aren't able to easily use them to determine access; instead, you need to use the individual permissions that the group contains.
You can check to see if a user belongs to a group easily:
$user = Sentry::findUserById(1);
$adminGroup = Sentry::findGroupByName('Admin');
$isAdmin = $user->inGroup($adminGroup);
However the best approach is to use permissions. You can setup an 'Admin' group with permissions to 'manage user accounts'. You then simply check to see if the user has permission to 'manage user accounts' as opposed to checking whether they belong to the Admin group.
In my 'group' table i have a row like this:
id | name | permissions
1 | Admin | {"manageUserAccounts":1}
I can now check whether a user has permission to 'manageUserAccounts' with the following:
$user = Sentry::findUserById($userId);
if ($user->hasPermission('manageUserAccounts') {
print 'You can manage user accounts';
}
else {
print 'Oops, you cant manage user accounts';
}
Note that the 'user' table is connected to the 'group' table via the user_groups table.
See the Sentry documentation for more info on how to fine grain permissions. It's quite powerful.

How can I prevent users from editing the OpportunityLineItem records in Salesforce.com?

I need a validation rule that prevents certain users from editing the OpportunityLineItem records.
I'm assuming that I will need to compare the LastModifiedDate value.
Any help is greatly appreciated.
Cheers!
Friday
You might want to look at the special fields available in formulas that begin with dollar sign. Roughly speaking they depend on who is looking at the data and aren't related to the record itself. They contain basic running user's info, his session id etc.
Example validation rule could look like that:
OR($Profile.Name = 'Marketing User',
$UserRole.Name = 'IT',
$User.Title = 'Contractor'
)
This should get you started if you can easily distinguish your "certain users" by Role, Profile or for example some checkbox you'd put on the User record that would be editable only by sysadmins.
If your logic is more complex (dependent on being a member of some group for example) - you'll have to write a trigger I believe.
Keep in mind that validation rules don't fire on record delete! If this is a concern there are 2 ways to solve it:
sane way: to remove the right to delete Opportunities (because Opp. Products "inherit" this permission from Opportunities) from most Profiles and then apply it to selected users with Permission Set
hacky way: delete of product will cause some rollup recalculations on the Opportunity (for example Amount field). So build a similar rule to the one you'll have on Opp. Line Items and attach && ISCHANGED(Amount) to it.

Comet chat integration with Code Igniter

I am using comet chat with Code Igniter 2.0.
Problem-
i have a listing page where all the users are listed and i need to show their comet chat status ("Online" or "Offline") next to their name.
For this purpose we have a DB field ('chat_status') in our users table, we usually set this field to '0' or '1' when user logged in we set this field to '1' and when user logged out we set this field to '0'. I just want to use comet chat call backs that will return all the online user_ids in array so i will change their 'chat_status' to '1' in our users table.
I couldn't find any comet chat function or query that will return all the online users in one shot.
Can you please assist me to solve this stuff.
Thanks in advance
There is a function in integration file [in my case its in its integration.php]
function getFriendsList() show all the friends on-line but if you want to show all the user insted of friends fellow the instruction given in link
You just have to edit the 3 sql queries in integration.php function by making changes to the username field .
You can write a subquery and get the status of the user that will be very easy .

Adding multiple users at a time in joomla

I have created a joomla component where we can upload the csv file which contain the user name and email of many users.I have written query for inserting the data to the jos_users table.The password in auto generated and i have encrypted the password using
$crypt = JUserHelper::getCryptedPassword("blabla", $salt);
I haven't inserted anything in the activation field.
But due to some reasons I cannot login using the username and the password.Should I do any thing else for this ?
Thanks Brent for your time.I have found the answer and is explained below.
For creating new user accounts by script you need to execute three queries.
1)
insert into jos_users (id,name,username,email,password,usertype,block,sendEmail,gid,registerDate,lastvisitDate) values (NULL,'name','username','email','password','Registered','0','0','18','date','date2')
2)
insert into jos_core_acl_aro (id,section_value,value,name) values (NULL, 'users', '(insertid of the above query)', 'name')
3)
insert into jos_core_acl_groups_aro_map (group_id,section_value,aro_id) values (18, '', '(insertid of the above query)')
This worked for me.
In order for a user to be able to log in -
activation field must be blank
user must be enabled
user must be a member of a group

Resources