views:

73

answers:

2

Hello I am trying the ACL component in cakephp for my web application. The example on their website for using their ACL structure has a many to one relationship between groups and users. A user can belong to one group, while a group can have more than one users in it.

But I have a situation where I need to have a few users in more than one group. For that I had to change the table structure, as it would be a many to many. So I built an associative entity called "groups_users". Now I have baked all the controllers, models, and views.

I have added groups and users, and things are working fine. I have also added the components into the parent class, AppController. I have also generated the ACL tables ACOs, AROs and AROs_ACOs using the baking console.

So in the groups_users add view, I have a list of users and groups. I can choose the users and their groups, and on submit a record has to be technically created in my groups_users table.

But to my surprise, records are being inserted into aros_acos table which is weird. I believe there is some internal relation between users, groups and the acl tables. I tried to understand if there was any foreign key cascading between these tables, but nothing was mentioned in the config/schema/dbacl.sql file.

I am pasting my table structure for a better understanding of my problem. Any ideas would be great help.

Thanks

SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0;
SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL';

CREATE SCHEMA IF NOT EXISTS `acl_cake` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci ;
USE `acl_cake` ;

-- -----------------------------------------------------
-- Table `acl_cake`.`users`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `acl_cake`.`users` (
  `id` INT(11) NOT NULL AUTO_INCREMENT ,
  `username` VARCHAR(255) NOT NULL ,
  `password` CHAR(40) NOT NULL ,
  `created` DATETIME NULL DEFAULT NULL ,
  `modified` DATETIME NULL DEFAULT NULL ,
  PRIMARY KEY (`id`) ,
  UNIQUE INDEX (`username` ASC) );


-- -----------------------------------------------------
-- Table `acl_cake`.`groups`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `acl_cake`.`groups` (
  `id` INT(11) NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(100) NOT NULL ,
  `created` DATETIME NULL DEFAULT NULL ,
  `modified` DATETIME NULL DEFAULT NULL ,
  PRIMARY KEY (`id`) );


-- -----------------------------------------------------
-- Table `acl_cake`.`posts`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `acl_cake`.`posts` (
  `id` INT(11) NOT NULL AUTO_INCREMENT ,
  `title` VARCHAR(255) NOT NULL ,
  `body` TEXT NULL DEFAULT NULL ,
  `created` DATETIME NULL DEFAULT NULL ,
  `modified` DATETIME NULL DEFAULT NULL ,
  `user_id` INT(11) NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_posts_users1` (`user_id` ASC) ,
  CONSTRAINT `fk_posts_users1`
    FOREIGN KEY (`user_id` )
    REFERENCES `acl_cake`.`users` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION);


-- -----------------------------------------------------
-- Table `acl_cake`.`widgets`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `acl_cake`.`widgets` (
  `id` INT(11) NOT NULL AUTO_INCREMENT ,
  `name` VARCHAR(100) NOT NULL ,
  `part_no` VARCHAR(12) NULL DEFAULT NULL ,
  `quantity` INT(11) NULL DEFAULT NULL ,
  PRIMARY KEY (`id`) );


-- -----------------------------------------------------
-- Table `acl_cake`.`groups_users`
-- -----------------------------------------------------
CREATE  TABLE IF NOT EXISTS `acl_cake`.`groups_users` (
  `id` INT NOT NULL ,
  `user_id` INT(11) NOT NULL ,
  `group_id` INT(11) NOT NULL ,
  PRIMARY KEY (`id`) ,
  INDEX `fk_permissions_users` (`user_id` ASC) ,
  INDEX `fk_permissions_groups1` (`group_id` ASC) ,
  CONSTRAINT `fk_permissions_users`
    FOREIGN KEY (`user_id` )
    REFERENCES `acl_cake`.`users` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION,
  CONSTRAINT `fk_permissions_groups1`
    FOREIGN KEY (`group_id` )
    REFERENCES `acl_cake`.`groups` (`id` )
    ON DELETE NO ACTION
    ON UPDATE NO ACTION)
ENGINE = InnoDB;



SET SQL_MODE=@OLD_SQL_MODE;
SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS;
SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS;
A: 

I can choose the users and their groups, and on submit a record has to be technically created in my groups_users table.

Do you mean when you insert a record assigning a user to a group?

Does your application work as expected apart from the problem you describe?

It's difficult to be sure from your description, but it's possible that an aro_aco record has to be created for each user/group combination.

Leo
Ok In the regular example, Users table has an extra column "group_id", which means that a user can only be part of one group. I want the user to be part of more than one groups. So I have the associative table groups_users.
macha
Now when I go to the action add in groups_users controller, I get a list of users and groups, from which I can assign the users to so and so groups. Technically any inserts on a controller, should hit its default model, but this time inserts are taking place on aros_acos table.
macha
I understand what you're trying to do. Are the groups_users records being inserted correctly? The problem is likely to be that the ACL component is written to expect a Group[1]:[n]User relationship. I think that you'll probably have to customise the component to do what you want.
Leo
No the records are not being inserted in groups_users table at all. An error is flashed whenever I submit data, the records are inserted into the aros_acos table which, comes with the ACL in cake-php. Would I have to customize the original code from cake-php to make my script work??
macha
+1  A: 

This may help get you pointed in the right direction or possibly give you another route to take. Simple Auth Users Has And Belongs To Many Groups CakePHP

jostster
Hey can this be integrated into the ACL component in cakePHP or would this be seperate, and on its own?? This works for authorization, but would it control the access based on control lists such as controllers and actions?
macha
I don't believe it does. I posted it as a reference for you to get an idea of how they are using the one to many so that you can edit the ACL to add the functionality.
jostster