Cake PHP making groups private - mysql

I am using cakephp and am new to it. I have created public and private groups in my website. How do i make sure only members can view the content of private groups and not everyone.
The SQL Tables are -
Users-
id
created
modified
email
password
Groups-
id
name
type - has value 1 if group is private and 0 if group is public
Groups_Users
id
group_id
user_id
created
modified
Please if someone can explain. Thank You

Are you using ACL ? if so you can create a "private" group & a method allowed to users belonging to that group (you can enhance it with routing prefix, but that's another subject)
It's as simple as : create method that fetch content -> create group -> give access rights to that group & that's it, only users belonging to that group can access that method.
If you're not using ACL, i suggest you to learn more about it it's time well spent. There's plugins which make it really easy to work with them & if you need more control you can create your own Authorization process.

Related

Joining 2 tables together and using the where function based on a separate mysql query

I am building a training platform for work. I have created the requirements for a user to be trained based on a role given to them. If that role is aligned to a document it will sit against the user. I have managed to get most of the way but am struglling on the best way to finish the where statement within mysqli.
tbldocfiles is a list of my files. I am looking at docid (could be multiple files associated to the document)
tbltrainingaccess sets the roles (driver, warehouseman, customer services) and shows which role (by id) is associated to the document in docfiles.
tblusertraining is the list of users and what role they have associated to them. (driver, warehouseman, customer services).
I am listing the documents associated to the user so have thought the following is the best way:
Look at the user and how many roles he/she is allocated
Look at the roles returned in point 1 (where function)
Identify and match the documents that have the same roles as the user (Join function)
create the list, then look at the unique values for docid. (distinct value)
Example User Bri has the driver and warehouseman role.
There are 5 documents in the db, 3 of them are associated to the driver role (docid 1,2,3) and 2 of them are associated to the warehouseman role (docid 2,4) the 5th document is associayted to customerservice.
My query should do this:
List all documents associated to the roles, that are associated to the user Bri
1
2
3
2
4
Now select unique values (using docid) from the above list:
1,2,3,4.
So my answer will be a used as a count function at the end using mysql_fetch_rows
SELECT DISTINCT tbldocfiles.docid FROM tbldocfiles LEFT JOIN tbltrainingaccess ON (tbldocfiles.docid = tbltrainingaccess.docid) where groupid='1' or groupid='9'
The above code works. but i've got myself confused.
The where statement needs to be the result of a query similar to :
select * from tblusertrainingrole where userid='1' (1 will be a variable based on page selection)
the result in this would be 1, 9 which are the groupid results.
Basically any help would be appreciated! I am sure it will be simple but have burnt myself out on this for a while and most answers in here helped with joining but not the where statement (that I could find)
Thank you in advance everyone!
You can do a select statement in the where. Since it is an or statement you can use in for the results. Please replace * with the column name for the value you need. Should look like
where groupid in (select * from tblusertrainingrole where userid = '1')

SSRS When uploading report owner name is wrong

I have SQL 2014 professional version 12.0.5000.0 with SSRS runing. eI have created a report in report builder 3.0 which works and runs find.
However when I go to create a subscription and run I get the user a1234 (as a example ) don't exist.
I looked there is no user with that name added to SSRS or in our domain.
my user name is ah1234 (as a example )
I looked in the subscription table and the owner is me ? However, the subscription is showing the owner as a1234?
I checked the report I uploaded it says the owner is a1234.
I'm thinking it might be a active directory issue but not sure.
Has anyone has see this before if so how can I fix the owner name of the subscription?
I don't know how SSRS has corrupted the owner name but here is a trick (written on 2008 R2) to correct owner names (I use this when people leave & their Active Directory user id gets deleted leaving orphaned subs that will not run).
Note that it updates the Microsoft-supplied subscriptions table, you may not wish to do that.
First identify the SSRS owner id for the from-person & also that of the to-person (you may need to get the to-person to create a subscription first):
SELECT distinct [OwnerID], u.username
FROM [<ssrs-database>].[dbo].[Subscriptions] s
join [<ssrs-database>].[dbo].[Users] u on s.ownerid = u.userid
Now make a safe copy of the subscriptions list, e.g.:
SELECT * into temp.subscriptionscpy
FROM [<ssrs-database>].[dbo].[Subscriptions] s
Now make the change, e.g. (this one changes the owner of all relevant subs):
update [<ssrs-database>].[dbo].[Subscriptions]
set ownerid = 'DDD87598-8957-42C8-8DBC-A893E7174CB6'
where ownerid = 'EBF0E483-69E6-4458-B171-BA28FFCCDF3F'
Now check the owner is as you want it.

How to create Google Contact using Google API

I am trying to create Google Contact using Google Contacts API.
According to Google doc(as below), I have already implement the create function.
Google Docs Creating contacts
To create a new contact, send an authorized POST request to the user's contacts feed URL with contact data in the body.
The URL is of the form:
https://www.google.com/m8/feeds/contacts/{userEmail}/full
I use this query to create a contact:
www.google.com/m8/feeds/contacts/{userEmail}/full
However, the new contact is created in the group "Other Contact" by default.
How can I directly create in the group "My Contact"?
Do I need to modify the query?
From the doc (https://developers.google.com/google-apps/contacts/v3/?csw=1#authorizing_requests_to_the_api_name_service):
Contact Group Entry
Contacts can be placed into user-defined groups. You can create,
retrieve, update, and delete these groups using the Contacts Data API,
and you can add contacts to a group or remove contacts from a group.
For details, see the following sections.
The Contacts Data API also provides access to four predefined "system
groups" for each user:
My Contacts Friends Family Coworkers System groups appear in a groups
feed just like user-defined groups do. In fact, system groups are
mostly treated just like other groups. The differences are:
Each system group entry contains a subelement.
The id attribute of that subelement indicates which system group the
group is: Contacts, Friends, Family, or Coworkers. Note that the My
Contacts ID value is simply Contacts, without the "My". Also note
that this system group ID value is different from the group ID given
in the group entry's element. You can't add new system groups,
change the name of a system group, add extended properties to a system
group, or delete a system group. * The contact-group entry
representing a system group doesn't contain a rel="edit" link.
def get_group_id(label_name):
feed = gd_client.GetGroups()
for entry in feed.entry:
if entry.title.text.lower() == label_name:
return entry.id.text
contact_entry = gdata.contacts.data.ContactEntry() #contact_entry
group = get_group_id("My Contact") #group id
membership = gdata.contacts.data.GroupMembershipInfo(href=group) #group membership
contact_entry.group_membership_info.append(membership) # adding group membership to contact_entry
Its not true that contacts can only be placed into user-defined groups. I just experimented with Google Contact V3 API and was able to put a contact under system defined group (My contacts):
ContactEntry contact = new ContactEntry();
Name name = new Name();
final String NO_YOMI = null;
name.setFullName(new FullName("Elizabeth Bennet", NO_YOMI));
name.setGivenName(new GivenName("Elizabeth", NO_YOMI));
name.setFamilyName(new FamilyName("Bennet", NO_YOMI));
contact.setName(name);
GroupMembershipInfo groupInfo = new GroupMembershipInfo();
//You can fetch the following link from GroupEntry#getId()
groupInfo.setHref("http://www.google.com/m8/feeds/groups/{EmailId}/base/{groupId}");
groupInfo.setDeleted(false);
contact.getGroupMembershipInfos().add(groupInfo);
ContactEntry createdContact = myService.insert(new URL(
"https://www.google.com/m8/feeds/contacts/{EmailId}/full"), contact);

LINQ to SQL

While trying to use LINQ to SQL I encountered several problems.
I have table persons:
int ID
string firstName
string lastName
And table notes that has:
int ID
string noteText
string createdBy
datetime creationDate
int PersonID
PersonID is a foreign key and the relationship is 1:n
I tried to use LINQ to SQL to create a person and some notes for each person.
Person person = new person();
Person.firstName = "me";
Person.note = new note();
Person.note.noteText = "some text…";
_DataContext.Persons.InsertOnSubmit(person);
_DataContext.SubmitChanges();
The problem is that the person object doesn't yet exist in the DB so it doesn't have an ID yet. So the note.personID filed has a 0 value… (the ID field is an identity field in the sql server)
The only solution for this that I found is to create a person , submitchanges and then create a note and submitchanges again.
Am I missing something here or maybe that’s the way one should work with LINQ to SQL?
How can I add multiple notes per person with LTS? I have a 1:n relationship and I don't see it with LTS.
If a person has 10000 notes, I don't want the person object constructor to load all the notes he has. I want to load them only when I refer to them. How can I config LTS to load the notes on demand?
If you aren't using the LinqToSql class designer, you should think about using it. The classes it generates will support the insertion scenario you outlined.
I can tell you aren't using the designer because it would give you a Notes (plural) property on the Person... as Person is 1 to Many with Notes.
How can I config LTS to load the notes on demand?
The designer will generate a property of type EntitySet(Note), which will load Notes on demand.

How do I create my own custom group in mediawiki?

I have been reading carefully through the MediaWiki documentation but I have not been able to find out how to create new groups.
When I look at Special:Userrights, I see only 3 groups :
Bots, Sysops, Bureaucrats
I would like to create my own custom groups, so I can use some extensions like the http://www.mediawiki.org/wiki/Extension:Group_Based_Access_Control.
Can someone tell me how it's done, or point me to some documentation?
You can add permissions for new groups to your LocalSettings.php file and they will automatically appear in the Special:UserRights page.
For example, I wanted to disallow editing by regular users but create a "Trusted" group that was allowed to edit. The following code creates a "Trusted" group that is equal to the "user" group, except that "Trusted" users can edit but "user" users cannot.
$wgGroupPermissions['Trusted'] = $wgGroupPermissions['user'];
$wgGroupPermissions['user' ]['edit'] = false;
$wgGroupPermissions['Trusted']['edit'] = true;
$wgGroupPermissions['sysop' ]['edit'] = true;
On the Special:UserRights page, I can now check the "Trusted" box to make users trusted.
You can alter the appearance of the group name by creating the following messages:
(For a group named ninja:)
MediaWiki:Group-ninja (content: Ninjas)
MediaWiki:Group-ninja-member (content: ninja)
MediaWiki:Grouppage-ninja (content: Project:Ninjas)
This will insure that the group will be referred to as "Ninjas" throughout the interface, and a member will be referred to as a "ninja", and overviews will link the groupname to Project:Ninjas.
(source: http://www.mediawiki.org/wiki/Manual:User_rights#Examples)
Here you will find a List of Permissions. http://www.mediawiki.org/wiki/Manual:User_rights
I beleive I have found the answer, I just need to add the UserGroup and the permission to the wgGroupPermissions array in the LocalSettings.php file.
$wgGroupPermissions['TomatoUsers']['read'] = true;
$wgGroupPermissions['TomatoUsers']['edit'] = false;
I don't have the reputation to vote up the first answer (which can also be added to extension initialization files), but for when you get to adding users to your groups you may want to consider directly editing the database (ie. if you need to sync the wiki groups with external information). If you open the database "wikidb" the "PREFIX_user_groups"* table contains the mapping between user IDs (ug_user) and group names (ug_group). This table, combined with the "PREFIX_user"* table's name information (user_name) and ID information (user_id), give you all the information to add and remove large numbers of users from groups.
* Replace "PREFIX" with the database prefix you used for your wiki.