Updated navigation templte to include current user.
Updated CMS_NODE, CMS_USER. Added USER_PROFILE and USER_ROLE Updated new USER_DATA_PROVIDER and NODE_DATA_PROVIDER to support new features. Added ROLE_DATA_PROVIDER. Updated test cases. Updated MySQL database schema.
This commit is contained in:
@@ -7,8 +7,10 @@
|
||||
<div class="collapse navbar-collapse" id="navbarCollapse">
|
||||
<ul class="nav navbar-nav">
|
||||
<li class="ListOfNodes"><a title="Nodes" href="{$host/}/nodes" rel="node">List of Nodes</a></li>
|
||||
|
||||
{if isset="$user"}
|
||||
</ul>
|
||||
<ul class="nav navbar-nav navbar-right">
|
||||
{if isset="$user"}
|
||||
<li><a>{$user/}</a></li>
|
||||
<li><a title="Node" href="{$host/}/node" rel="node">New Node</a></li>
|
||||
<li><a title="Logoff" href="{$host/}/logoff" rel="logoff">Logoff</a></li>
|
||||
{/if}
|
||||
@@ -16,7 +18,7 @@
|
||||
<li><a title="Login" href="{$host/}/login" rel="login">Login</a></li>
|
||||
<li><a title="Register" href="{$host/}/user" rel="register">Register</a></li>
|
||||
{/unless}
|
||||
</ul>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
@@ -6,6 +6,10 @@ note
|
||||
class
|
||||
CMS_NODE
|
||||
|
||||
inherit
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
@@ -21,6 +25,10 @@ feature{NONE} -- Initialization
|
||||
set_creation_date (l_time)
|
||||
set_modification_date (l_time)
|
||||
set_publication_date (l_time)
|
||||
fixme ("Remove harcode format")
|
||||
set_format ("HTML")
|
||||
fixme ("Remove harcode content type")
|
||||
set_content_type ("Page")
|
||||
ensure
|
||||
content_set: content = a_content
|
||||
summary_set: summary = a_summary
|
||||
@@ -48,10 +56,32 @@ feature -- Access
|
||||
-- When the node was published.
|
||||
|
||||
publication_date_output: READABLE_STRING_32
|
||||
-- Formatted output.
|
||||
|
||||
id: INTEGER_64 assign set_id
|
||||
-- Unique id.
|
||||
|
||||
format: READABLE_STRING_32
|
||||
-- Format associated with `body'.
|
||||
-- For example: text, mediawiki, html, etc
|
||||
|
||||
content_type: READABLE_STRING_32
|
||||
-- Associated content type name.
|
||||
-- Page, Article, Blog, News, etc.
|
||||
|
||||
feature -- status report
|
||||
|
||||
has_id: BOOLEAN
|
||||
do
|
||||
Result := id > 0
|
||||
end
|
||||
|
||||
author: detachable CMS_USER
|
||||
-- Node's author.
|
||||
|
||||
collaborators: detachable LIST[CMS_USER]
|
||||
-- Node's collaborators.
|
||||
|
||||
feature -- Element change
|
||||
|
||||
set_content (a_content: like content)
|
||||
@@ -103,6 +133,22 @@ feature -- Element change
|
||||
publication_date_assigned: publication_date = a_publication_date
|
||||
end
|
||||
|
||||
set_content_type (a_content_type: like content_type)
|
||||
-- Assign `content_type' with `a_content_type'.
|
||||
do
|
||||
content_type := a_content_type
|
||||
ensure
|
||||
content_type_assigned: content_type = a_content_type
|
||||
end
|
||||
|
||||
set_format (a_format: like format)
|
||||
-- Assign `format' with `a_format'.
|
||||
do
|
||||
format := a_format
|
||||
ensure
|
||||
format_assigned: format = a_format
|
||||
end
|
||||
|
||||
set_id (an_id: like id)
|
||||
-- Assign `id' with `an_id'.
|
||||
do
|
||||
@@ -111,4 +157,25 @@ feature -- Element change
|
||||
id_assigned: id = an_id
|
||||
end
|
||||
|
||||
set_author (u: like author)
|
||||
-- Assign 'author' with `u'
|
||||
do
|
||||
author := u
|
||||
ensure
|
||||
auther_set: author = u
|
||||
end
|
||||
|
||||
add_collaborator (a_user: CMS_USER)
|
||||
-- Add collaborator `a_user' to the collaborators list.
|
||||
local
|
||||
lst: like collaborators
|
||||
do
|
||||
lst := collaborators
|
||||
if lst = Void then
|
||||
create {ARRAYED_SET [CMS_USER]} lst.make (1)
|
||||
collaborators := lst
|
||||
end
|
||||
lst.force (a_user)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
@@ -6,6 +6,10 @@ note
|
||||
class
|
||||
CMS_USER
|
||||
|
||||
inherit
|
||||
|
||||
DEBUG_OUTPUT
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
@@ -15,6 +19,9 @@ feature {NONE} -- Initialization
|
||||
-- Create an object with name `a_name'.
|
||||
do
|
||||
name := a_name
|
||||
create creation_date.make_now_utc
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
@@ -31,6 +38,48 @@ feature -- Access
|
||||
email: detachable READABLE_STRING_32
|
||||
-- User email.
|
||||
|
||||
profile: detachable CMS_USER_PROFILE
|
||||
-- User profile.
|
||||
|
||||
creation_date: DATE_TIME
|
||||
-- Creation date.
|
||||
|
||||
last_login_date: detachable DATE_TIME
|
||||
-- User last login.
|
||||
|
||||
data: detachable STRING_TABLE [detachable ANY]
|
||||
-- Additional user's data.
|
||||
|
||||
data_item (k: READABLE_STRING_GENERAL): detachable ANY
|
||||
-- Additional item data.
|
||||
do
|
||||
if attached data as l_data then
|
||||
Result := l_data.item (k)
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
has_id: BOOLEAN
|
||||
do
|
||||
Result := id > 0
|
||||
end
|
||||
|
||||
has_email: BOOLEAN
|
||||
do
|
||||
Result := attached email as e and then not e.is_empty
|
||||
end
|
||||
|
||||
debug_output: STRING
|
||||
do
|
||||
Result := name
|
||||
end
|
||||
|
||||
same_as (u: detachable CMS_USER): BOOLEAN
|
||||
do
|
||||
Result := u /= Void and then id = u.id
|
||||
end
|
||||
|
||||
feature -- Change element
|
||||
|
||||
set_id (a_id: like id)
|
||||
@@ -65,4 +114,53 @@ feature -- Change element
|
||||
email_set: email = m
|
||||
end
|
||||
|
||||
set_profile (prof: like profile)
|
||||
-- Set `profile' with `prof'.
|
||||
do
|
||||
profile := prof
|
||||
ensure
|
||||
profile_set: profile = prof
|
||||
end
|
||||
|
||||
set_data_item (k: READABLE_STRING_GENERAL; d: like data_item)
|
||||
local
|
||||
l_data: like data
|
||||
do
|
||||
l_data := data
|
||||
if l_data = Void then
|
||||
create l_data.make (1)
|
||||
data := l_data
|
||||
end
|
||||
l_data.force (d, k)
|
||||
end
|
||||
|
||||
remove_data_item (k: READABLE_STRING_GENERAL)
|
||||
do
|
||||
if attached data as l_data then
|
||||
l_data.remove (k)
|
||||
end
|
||||
end
|
||||
|
||||
set_profile_item (k: READABLE_STRING_8; v: READABLE_STRING_8)
|
||||
local
|
||||
prof: like profile
|
||||
do
|
||||
prof := profile
|
||||
if prof = Void then
|
||||
create prof.make
|
||||
profile := prof
|
||||
end
|
||||
prof.force (v, k)
|
||||
end
|
||||
|
||||
set_last_login_date (dt: like last_login_date)
|
||||
do
|
||||
last_login_date := dt
|
||||
end
|
||||
|
||||
set_last_login_date_now
|
||||
do
|
||||
set_last_login_date (create {DATE_TIME}.make_now_utc)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
48
persistence/implementation/common/model/cms_user_profile.e
Normal file
48
persistence/implementation/common/model/cms_user_profile.e
Normal file
@@ -0,0 +1,48 @@
|
||||
note
|
||||
description: "Summary description for {CMS_USER_PROFILE}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_USER_PROFILE
|
||||
|
||||
inherit
|
||||
TABLE_ITERABLE [READABLE_STRING_8, READABLE_STRING_8]
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make
|
||||
do
|
||||
create items.make (0)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
item (k: READABLE_STRING_8): detachable READABLE_STRING_8
|
||||
do
|
||||
Result := items.item (k.as_string_8)
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
|
||||
force (v: READABLE_STRING_8; k: READABLE_STRING_8)
|
||||
do
|
||||
items.force (v, k.as_string_8)
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
new_cursor: TABLE_ITERATION_CURSOR [READABLE_STRING_8, READABLE_STRING_8]
|
||||
-- Fresh cursor associated with current structure
|
||||
do
|
||||
Result := items.new_cursor
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
items: HASH_TABLE [READABLE_STRING_8, STRING_8]
|
||||
|
||||
end
|
||||
90
persistence/implementation/common/model/cms_user_role.e
Normal file
90
persistence/implementation/common/model/cms_user_role.e
Normal file
@@ -0,0 +1,90 @@
|
||||
note
|
||||
description: "Summary description for {CMS_USER_ROLE}."
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
CMS_USER_ROLE
|
||||
|
||||
inherit
|
||||
ANY
|
||||
redefine
|
||||
is_equal
|
||||
end
|
||||
|
||||
create
|
||||
make,
|
||||
make_with_id
|
||||
|
||||
feature {NONE} -- Initialization
|
||||
|
||||
make_with_id (a_id: like id; a_name: like name)
|
||||
do
|
||||
id := a_id
|
||||
make (a_name)
|
||||
end
|
||||
|
||||
make (a_name: like name)
|
||||
do
|
||||
name := a_name
|
||||
create {ARRAYED_LIST [READABLE_STRING_8]} permissions.make (0)
|
||||
end
|
||||
|
||||
feature -- Status report
|
||||
|
||||
has_id: BOOLEAN
|
||||
do
|
||||
Result := id > 0
|
||||
end
|
||||
|
||||
has_permission (p: READABLE_STRING_8): BOOLEAN
|
||||
do
|
||||
Result := across permissions as c some c.item.is_case_insensitive_equal (p) end
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
id: INTEGER
|
||||
|
||||
name: READABLE_STRING_8
|
||||
|
||||
permissions: LIST [READABLE_STRING_8]
|
||||
|
||||
feature -- Comparison
|
||||
|
||||
same_user_role (r: CMS_USER_ROLE): BOOLEAN
|
||||
do
|
||||
Result := r.id = id
|
||||
end
|
||||
|
||||
is_equal (other: like Current): BOOLEAN
|
||||
-- Is `other' attached to an object considered
|
||||
-- equal to current object?
|
||||
do
|
||||
Result := id = other.id
|
||||
end
|
||||
|
||||
feature -- Change
|
||||
|
||||
set_id (a_id: like id)
|
||||
-- Set `id' with `a_id'.
|
||||
do
|
||||
id := a_id
|
||||
ensure
|
||||
set_id: id = a_id
|
||||
end
|
||||
|
||||
set_name (a_name: like name)
|
||||
-- Set `name' with `a_name'.
|
||||
do
|
||||
name := a_name
|
||||
ensure
|
||||
name_set: name = a_name
|
||||
end
|
||||
|
||||
add_permission (n: READABLE_STRING_8)
|
||||
do
|
||||
permissions.force (n)
|
||||
end
|
||||
|
||||
end
|
||||
@@ -3,15 +3,18 @@ SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0;
|
||||
SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='TRADITIONAL,ALLOW_INVALID_DATES';
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Schema cms
|
||||
-- Schema mydb
|
||||
-- -----------------------------------------------------
|
||||
CREATE SCHEMA IF NOT EXISTS `cms` DEFAULT CHARACTER SET latin1 ;
|
||||
USE `cms` ;
|
||||
-- -----------------------------------------------------
|
||||
-- Schema cms_dev
|
||||
-- -----------------------------------------------------
|
||||
CREATE SCHEMA IF NOT EXISTS `cms_dev` DEFAULT CHARACTER SET latin1 ;
|
||||
USE `cms_dev` ;
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `cms`.`nodes`
|
||||
-- Table `cms_dev`.`nodes`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `cms`.`nodes` (
|
||||
CREATE TABLE IF NOT EXISTS `cms_dev`.`nodes` (
|
||||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`publication_date` DATE NOT NULL,
|
||||
`creation_date` DATE NOT NULL,
|
||||
@@ -26,38 +29,39 @@ DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `cms`.`roles`
|
||||
-- Table `cms_dev`.`roles`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `cms`.`roles` (
|
||||
CREATE TABLE IF NOT EXISTS `cms_dev`.`roles` (
|
||||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`role` VARCHAR(100) NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `role` (`role` ASC))
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `cms`.`users`
|
||||
-- Table `cms_dev`.`users`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `cms`.`users` (
|
||||
CREATE TABLE IF NOT EXISTS `cms_dev`.`users` (
|
||||
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
|
||||
`username` VARCHAR(100) NOT NULL,
|
||||
`password` VARCHAR(100) NOT NULL,
|
||||
`salt` VARCHAR(100) NOT NULL,
|
||||
`email` VARCHAR(250) NOT NULL,
|
||||
`creation_date` DATETIME NULL,
|
||||
`last_login_date` DATETIME NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `username` (`username` ASC))
|
||||
ENGINE = InnoDB
|
||||
AUTO_INCREMENT = 1
|
||||
AUTO_INCREMENT = 2
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `cms`.`users_nodes`
|
||||
-- Table `cms_dev`.`users_nodes`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `cms`.`users_nodes` (
|
||||
CREATE TABLE IF NOT EXISTS `cms_dev`.`users_nodes` (
|
||||
`users_id` INT(10) UNSIGNED NOT NULL,
|
||||
`nodes_id` INT(10) UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (`users_id`, `nodes_id`),
|
||||
@@ -65,12 +69,12 @@ CREATE TABLE IF NOT EXISTS `cms`.`users_nodes` (
|
||||
INDEX `fk_users_has_nodes_users_idx` (`users_id` ASC),
|
||||
CONSTRAINT `fk_users_has_nodes_nodes1`
|
||||
FOREIGN KEY (`nodes_id`)
|
||||
REFERENCES `cms`.`nodes` (`id`)
|
||||
REFERENCES `cms_dev`.`nodes` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_users_has_nodes_users`
|
||||
FOREIGN KEY (`users_id`)
|
||||
REFERENCES `cms`.`users` (`id`)
|
||||
REFERENCES `cms_dev`.`users` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
@@ -78,9 +82,9 @@ DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `cms`.`users_roles`
|
||||
-- Table `cms_dev`.`users_roles`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `cms`.`users_roles` (
|
||||
CREATE TABLE IF NOT EXISTS `cms_dev`.`users_roles` (
|
||||
`users_id` INT(10) UNSIGNED NOT NULL,
|
||||
`roles_id` INT(10) UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (`users_id`, `roles_id`),
|
||||
@@ -88,18 +92,55 @@ CREATE TABLE IF NOT EXISTS `cms`.`users_roles` (
|
||||
INDEX `fk_users_has_roles_users1_idx` (`users_id` ASC),
|
||||
CONSTRAINT `fk_users_has_roles_roles1`
|
||||
FOREIGN KEY (`roles_id`)
|
||||
REFERENCES `cms`.`roles` (`id`)
|
||||
REFERENCES `cms_dev`.`roles` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION,
|
||||
CONSTRAINT `fk_users_has_roles_users1`
|
||||
FOREIGN KEY (`users_id`)
|
||||
REFERENCES `cms`.`users` (`id`)
|
||||
REFERENCES `cms_dev`.`users` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB
|
||||
DEFAULT CHARACTER SET = latin1;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `cms_dev`.`permissions`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `cms_dev`.`permissions` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`name` VARCHAR(45) NOT NULL,
|
||||
`roles_id` INT(10) UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `name_UNIQUE` (`name` ASC),
|
||||
INDEX `fk_permissions_roles1_idx` (`roles_id` ASC),
|
||||
CONSTRAINT `fk_permissions_roles1`
|
||||
FOREIGN KEY (`roles_id`)
|
||||
REFERENCES `cms_dev`.`roles` (`id`)
|
||||
ON DELETE NO ACTION
|
||||
ON UPDATE NO ACTION)
|
||||
ENGINE = InnoDB;
|
||||
|
||||
|
||||
-- -----------------------------------------------------
|
||||
-- Table `cms_dev`.`profiles`
|
||||
-- -----------------------------------------------------
|
||||
CREATE TABLE IF NOT EXISTS `cms_dev`.`profiles` (
|
||||
`id` INT NOT NULL AUTO_INCREMENT,
|
||||
`key` VARCHAR(45) NOT NULL,
|
||||
`value` VARCHAR(100) NULL,
|
||||
`users_id` INT(10) UNSIGNED NOT NULL,
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE INDEX `key_UNIQUE` (`key` ASC),
|
||||
INDEX `fk_profiles_users1_idx` (`users_id` ASC),
|
||||
CONSTRAINT `fk_profiles_users1`
|
||||
FOREIGN KEY (`users_id`)
|
||||
REFERENCES `cms_dev`.`users` (`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;
|
||||
|
||||
@@ -0,0 +1,222 @@
|
||||
note
|
||||
description: "Summary description for {ROLE_DATA_PROVIDER}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
ROLE_DATA_PROVIDER
|
||||
|
||||
inherit
|
||||
|
||||
PARAMETER_NAME_HELPER
|
||||
|
||||
SHARED_ERROR
|
||||
|
||||
REFACTORING_HELPER
|
||||
|
||||
create
|
||||
make
|
||||
|
||||
feature -- Initialization
|
||||
|
||||
make (a_connection: DATABASE_CONNECTION)
|
||||
-- Create a data provider.
|
||||
do
|
||||
create {DATABASE_HANDLER_IMPL} db_handler.make (a_connection)
|
||||
post_execution
|
||||
end
|
||||
|
||||
db_handler: DATABASE_HANDLER
|
||||
-- Db handler.
|
||||
|
||||
feature -- Status Report
|
||||
|
||||
is_successful: BOOLEAN
|
||||
-- Is the last execution sucessful?
|
||||
do
|
||||
Result := db_handler.successful
|
||||
end
|
||||
|
||||
has_roles: BOOLEAN
|
||||
-- Has any role?
|
||||
do
|
||||
Result := count > 0
|
||||
end
|
||||
|
||||
feature -- Access
|
||||
|
||||
roles: DATABASE_ITERATION_CURSOR [CMS_USER_ROLE]
|
||||
-- List of roles.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".roles")
|
||||
create l_parameters.make (0)
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_roles, l_parameters))
|
||||
db_handler.execute_query
|
||||
create Result.make (db_handler, agent fetch_role)
|
||||
post_execution
|
||||
end
|
||||
|
||||
feature -- Basic Operations
|
||||
|
||||
new_role (a_role: READABLE_STRING_32)
|
||||
-- Create a new node.
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
log.write_information (generator + ".new_role")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_role,"name")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (sql_insert_role, l_parameters))
|
||||
db_handler.execute_change
|
||||
post_execution
|
||||
end
|
||||
|
||||
role (a_id: INTEGER_64): detachable CMS_USER_ROLE
|
||||
-- Role for the given id `a_id', if any.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".role")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_id,"id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_role_by_id, l_parameters))
|
||||
db_handler.execute_query
|
||||
if db_handler.count = 1 then
|
||||
Result := fetch_role
|
||||
end
|
||||
post_execution
|
||||
end
|
||||
|
||||
role_by_name (a_name: READABLE_STRING_32): detachable CMS_USER_ROLE
|
||||
-- Role for the given name `a_name', if any.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".role_by_name")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_name,"name")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_role_by_name, l_parameters))
|
||||
db_handler.execute_query
|
||||
if db_handler.count = 1 then
|
||||
Result := fetch_role
|
||||
end
|
||||
post_execution
|
||||
end
|
||||
|
||||
count: INTEGER
|
||||
-- Number of items users.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".count")
|
||||
create l_parameters.make (0)
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (select_count, l_parameters))
|
||||
db_handler.execute_query
|
||||
if db_handler.count = 1 then
|
||||
Result := db_handler.read_integer_32 (1)
|
||||
end
|
||||
post_execution
|
||||
end
|
||||
|
||||
save_role_permission (a_role_id: INTEGER; a_permission: READABLE_STRING_32)
|
||||
-- Add permission `a_permission' to the role id `a_role_id'.
|
||||
require
|
||||
valid_id: a_role_id > 0
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
log.write_information (generator + ".save_role_permission")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_permission,"name")
|
||||
l_parameters.put (a_role_id,"id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (SQL_Insert_permissions, l_parameters))
|
||||
db_handler.execute_change
|
||||
post_execution
|
||||
end
|
||||
|
||||
permission_by_role (a_role_id: INTEGER_64): DATABASE_ITERATION_CURSOR [READABLE_STRING_32]
|
||||
-- List of permission by role `a_role_id'.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".permission_by_role")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_role_id, "id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_permissions, l_parameters))
|
||||
db_handler.execute_query
|
||||
create Result.make (db_handler, agent fetch_permission)
|
||||
post_execution
|
||||
end
|
||||
|
||||
feature -- New Object
|
||||
|
||||
fetch_role: CMS_USER_ROLE
|
||||
do
|
||||
create Result.make_with_id (0,"")
|
||||
if attached db_handler.read_integer_32 (1) as l_id then
|
||||
Result.set_id (l_id)
|
||||
end
|
||||
if attached db_handler.read_string (2) as l_u then
|
||||
Result.set_name (l_u)
|
||||
end
|
||||
end
|
||||
|
||||
fetch_permission: STRING_32
|
||||
do
|
||||
create Result.make_empty
|
||||
if attached db_handler.read_string (1) as l_u then
|
||||
Result := l_u
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
feature {NONE} -- Sql Queries: Roles
|
||||
|
||||
Select_count: STRING = "select count(*) from Roles;"
|
||||
-- Number of roles.
|
||||
|
||||
Select_roles: STRING = "select * from Roles;"
|
||||
-- roles.
|
||||
|
||||
Select_role_by_id: STRING = "select * from Roles where id =:id;"
|
||||
-- Retrieve role by id if exists.
|
||||
|
||||
Select_role_by_name: STRING = "select * from Roles where role =:name;"
|
||||
-- Retrieve user by name if exists.
|
||||
|
||||
SQL_Insert_role: STRING = "insert into roles (role) values (:name);"
|
||||
-- SQL Insert to add a new node.
|
||||
|
||||
|
||||
feature {NONE} -- Sql Queries: Permissions
|
||||
|
||||
Select_permissions_count: STRING = "select count(*) from permissions where roles_id=:id;"
|
||||
-- Number of permissions for a given role.
|
||||
|
||||
Select_permissions: STRING = "select * from permissions where roles_id=:id;"
|
||||
-- List of permissions for a given role.
|
||||
|
||||
Select_permissions_by_id: STRING = "select name from permissions where roles_id=:id and id=:permissionid;"
|
||||
-- Permission for a given role and permission id
|
||||
|
||||
SQL_Insert_permissions: STRING = "insert into permissions (name, roles_id) values (:name, :id);"
|
||||
-- SQL Insert to add a new node.
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
post_execution
|
||||
-- Post database execution.
|
||||
do
|
||||
if db_handler.successful then
|
||||
set_successful
|
||||
else
|
||||
if attached db_handler.last_error then
|
||||
set_last_error_from_handler (db_handler.last_error)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -149,6 +149,34 @@ feature -- Basic Operations
|
||||
post_execution
|
||||
end
|
||||
|
||||
add_role (a_user_id: INTEGER; a_role_id: INTEGER)
|
||||
-- Add Role `a_role_id' to user `a_user_id'
|
||||
local
|
||||
l_parameters: STRING_TABLE [detachable ANY]
|
||||
do
|
||||
log.write_information (generator + ".add_role")
|
||||
create l_parameters.make (2)
|
||||
l_parameters.put (a_user_id,"users_id")
|
||||
l_parameters.put (a_role_id,"roles_id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (slq_insert_users_roles, l_parameters))
|
||||
db_handler.execute_change
|
||||
post_execution
|
||||
end
|
||||
|
||||
user_roles (a_id:INTEGER_64): DATABASE_ITERATION_CURSOR [INTEGER]
|
||||
-- List of Roles id for the given user `a_id'.
|
||||
local
|
||||
l_parameters: STRING_TABLE [ANY]
|
||||
do
|
||||
log.write_information (generator + ".user_roles")
|
||||
create l_parameters.make (1)
|
||||
l_parameters.put (a_id, "user_id")
|
||||
db_handler.set_query (create {DATABASE_QUERY}.data_reader (Select_user_roles, l_parameters))
|
||||
db_handler.execute_query
|
||||
create Result.make (db_handler, agent fetch_role_id)
|
||||
post_execution
|
||||
end
|
||||
|
||||
feature -- New Object
|
||||
|
||||
fetch_user: CMS_USER
|
||||
@@ -168,7 +196,14 @@ feature -- New Object
|
||||
end
|
||||
end
|
||||
|
||||
feature -- Sql Queries
|
||||
fetch_role_id: INTEGER
|
||||
do
|
||||
if attached db_handler.read_integer_32 (1) as l_id then
|
||||
Result := l_id
|
||||
end
|
||||
end
|
||||
|
||||
feature {NONE} -- Sql Queries: USER
|
||||
|
||||
Select_count: STRING = "select count(*) from Users;"
|
||||
-- Number of users.
|
||||
@@ -189,6 +224,12 @@ feature -- Sql Queries
|
||||
-- SQL Insert to add a new node.
|
||||
|
||||
|
||||
feature {NONE} -- Sql Queries: USER_ROLES
|
||||
|
||||
Slq_insert_users_roles: STRING = "insert into users_roles (users_id, roles_id) values (:users_id, :roles_id);"
|
||||
|
||||
Select_user_roles: STRING = "Select roles_id from users_roles where users_id = :user_id"
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
post_execution
|
||||
|
||||
100
persistence/implementation/mysql/tests/roles/role_test_set.e
Normal file
100
persistence/implementation/mysql/tests/roles/role_test_set.e
Normal file
@@ -0,0 +1,100 @@
|
||||
note
|
||||
description: "Summary description for {ROLE_TEST_SET}."
|
||||
author: ""
|
||||
date: "$Date$"
|
||||
revision: "$Revision$"
|
||||
|
||||
class
|
||||
ROLE_TEST_SET
|
||||
inherit
|
||||
EQA_TEST_SET
|
||||
redefine
|
||||
on_prepare,
|
||||
on_clean
|
||||
select
|
||||
default_create
|
||||
end
|
||||
ABSTRACT_DB_TEST
|
||||
rename
|
||||
default_create as default_db_test
|
||||
end
|
||||
|
||||
|
||||
feature {NONE} -- Events
|
||||
|
||||
on_prepare
|
||||
-- <Precursor>
|
||||
do
|
||||
(create {CLEAN_DB}).clean_db(connection)
|
||||
end
|
||||
|
||||
on_clean
|
||||
-- <Precursor>
|
||||
do
|
||||
end
|
||||
|
||||
feature -- Test routines
|
||||
|
||||
test_roles_empty
|
||||
do
|
||||
assert ("Not elements",role_provider.roles.after)
|
||||
assert ("Count = 0", role_provider.count = 0)
|
||||
end
|
||||
|
||||
test_roles_by_id_not_exist
|
||||
do
|
||||
assert ("Void", role_provider.role (1) = Void)
|
||||
end
|
||||
|
||||
test_roles_by_name_not_exist
|
||||
do
|
||||
assert ("Void", role_provider.role_by_name ("admin") = Void)
|
||||
end
|
||||
|
||||
test_new_role
|
||||
do
|
||||
assert ("Count = 0", role_provider.count = 0)
|
||||
role_provider.new_role ("admin")
|
||||
assert ("Count = 1", role_provider.count = 1)
|
||||
assert ("Expected role", attached role_provider.role (1) as l_role and then l_role.name ~ "admin")
|
||||
assert ("Expected role", attached role_provider.role_by_name ("admin") as l_role and then l_role.id = 1)
|
||||
end
|
||||
|
||||
test_permissions_empty_not_exist_role
|
||||
do
|
||||
assert ("Not elements",role_provider.permission_by_role (1).after)
|
||||
end
|
||||
|
||||
test_permissions_empty_exist_role
|
||||
do
|
||||
assert ("Count = 0", role_provider.count = 0)
|
||||
role_provider.new_role ("admin")
|
||||
assert ("Count = 1", role_provider.count = 1)
|
||||
assert ("Exist role",not role_provider.roles.after)
|
||||
assert ("Not permission by role 1 elements",role_provider.permission_by_role (1).after)
|
||||
end
|
||||
|
||||
test_new_role_with_permissions
|
||||
do
|
||||
assert ("Count = 0", role_provider.count = 0)
|
||||
role_provider.new_role ("admin")
|
||||
role_provider.save_role_permission (1, "Create Page")
|
||||
role_provider.save_role_permission (1, "Edit Page")
|
||||
role_provider.save_role_permission (1, "Delete Page")
|
||||
assert ("Count = 1", role_provider.count = 1)
|
||||
assert ("Exist role",not role_provider.roles.after)
|
||||
assert ("Exist role permissions",not role_provider.permission_by_role (1).after)
|
||||
assert ("Not Exist role permissions, for id 2",role_provider.permission_by_role (2).after)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
role_provider: ROLE_DATA_PROVIDER
|
||||
-- role provider.
|
||||
once
|
||||
create Result.make (connection)
|
||||
end
|
||||
end
|
||||
@@ -200,8 +200,6 @@ feature -- Test routines
|
||||
end
|
||||
|
||||
test_node_does_not_exist
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
do
|
||||
across 1 |..| 10 as c loop
|
||||
storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
|
||||
@@ -210,8 +208,6 @@ feature -- Test routines
|
||||
end
|
||||
|
||||
test_node
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
do
|
||||
across 1 |..| 10 as c loop
|
||||
storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
|
||||
@@ -221,7 +217,6 @@ feature -- Test routines
|
||||
|
||||
test_update_node
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
storage.save_node (custom_node ("Content", "Summary", "Title"))
|
||||
@@ -237,9 +232,6 @@ feature -- Test routines
|
||||
end
|
||||
|
||||
test_update_node_title
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
storage.save_node (custom_node ("Content", "Summary", "Title"))
|
||||
if attached {CMS_NODE} storage.node (1) as ll_node then
|
||||
@@ -249,9 +241,6 @@ feature -- Test routines
|
||||
end
|
||||
|
||||
test_update_node_summary
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
storage.save_node (custom_node ("Content", "Summary", "Title"))
|
||||
if attached {CMS_NODE} storage.node (1) as ll_node then
|
||||
@@ -261,9 +250,6 @@ feature -- Test routines
|
||||
end
|
||||
|
||||
test_update_node_content
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
l_node: CMS_NODE
|
||||
do
|
||||
storage.save_node (custom_node ("Content", "Summary", "Title"))
|
||||
if attached {CMS_NODE} storage.node (1) as ll_node then
|
||||
@@ -273,8 +259,6 @@ feature -- Test routines
|
||||
end
|
||||
|
||||
test_delete_node
|
||||
local
|
||||
l_nodes: LIST[CMS_NODE]
|
||||
do
|
||||
across 1 |..| 10 as c loop
|
||||
storage.save_node (custom_node ("Content_" + c.item.out, "Summary_" + c.item.out, "Title_" + c.item.out))
|
||||
|
||||
@@ -65,6 +65,14 @@ feature -- Test routines
|
||||
assert ("Not void", attached user_provider.user_by_name ("test"))
|
||||
end
|
||||
|
||||
test_new_user_with_roles
|
||||
do
|
||||
user_provider.new_user ("test", "test","test@admin.com")
|
||||
role_provider.new_role ("Admin")
|
||||
assert ("Empty roles for given user", user_provider.user_roles (1).after)
|
||||
user_provider.add_role (1, 1)
|
||||
assert ("Not empty roles for given user", not user_provider.user_roles (1).after)
|
||||
end
|
||||
|
||||
feature {NONE} -- Implementation
|
||||
|
||||
@@ -73,6 +81,13 @@ feature {NONE} -- Implementation
|
||||
once
|
||||
create Result.make (connection)
|
||||
end
|
||||
|
||||
role_provider: ROLE_DATA_PROVIDER
|
||||
-- user provider.
|
||||
once
|
||||
create Result.make (connection)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
@@ -23,6 +23,20 @@ feature
|
||||
do
|
||||
create l_parameters.make (0)
|
||||
|
||||
|
||||
-- Clean Permissions
|
||||
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Sql_delete_permissions, l_parameters))
|
||||
db_handler(a_connection).execute_change
|
||||
|
||||
-- Clean Users Roles
|
||||
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Sql_delete_users_roles, l_parameters))
|
||||
db_handler(a_connection).execute_change
|
||||
|
||||
-- Clean Roles
|
||||
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Sql_delete_roles, l_parameters))
|
||||
db_handler(a_connection).execute_change
|
||||
|
||||
-- Clean Nodes
|
||||
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Sql_delete_nodes, l_parameters))
|
||||
db_handler(a_connection).execute_change
|
||||
|
||||
@@ -30,12 +44,20 @@ feature
|
||||
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Sql_delete_users, l_parameters))
|
||||
db_handler(a_connection).execute_change
|
||||
|
||||
|
||||
-- Reset Autoincremente
|
||||
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Rest_users_autoincrement, l_parameters))
|
||||
db_handler(a_connection).execute_change
|
||||
|
||||
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Rest_nodes_autoincrement, l_parameters))
|
||||
db_handler(a_connection).execute_change
|
||||
|
||||
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Rest_roles_autoincrement, l_parameters))
|
||||
db_handler(a_connection).execute_change
|
||||
|
||||
db_handler(a_connection).set_query (create {DATABASE_QUERY}.data_reader (Rest_permissions_autoincrement, l_parameters))
|
||||
db_handler(a_connection).execute_change
|
||||
|
||||
end
|
||||
|
||||
|
||||
@@ -57,10 +79,25 @@ feature -- Sql delete queries
|
||||
Sql_delete_nodes: STRING = "delete from Nodes"
|
||||
-- Clean Nodes.
|
||||
|
||||
Sql_delete_roles: STRING = "delete from Roles"
|
||||
-- Clean Roles.
|
||||
|
||||
Sql_delete_permissions: STRING = "delete from Permissions"
|
||||
-- Clean Permissions.
|
||||
|
||||
Sql_delete_users_roles: STRING = "delete from Users_roles"
|
||||
-- Clean User roles.
|
||||
|
||||
Rest_users_autoincrement: STRING = "ALTER TABLE Users AUTO_INCREMENT = 1"
|
||||
-- reset autoincrement
|
||||
|
||||
Rest_nodes_autoincrement: STRING = "ALTER TABLE Nodes AUTO_INCREMENT = 1"
|
||||
-- reset autoincrement.
|
||||
|
||||
Rest_roles_autoincrement: STRING = "ALTER TABLE Roles AUTO_INCREMENT = 1"
|
||||
-- reset autoincrement.
|
||||
|
||||
Rest_permissions_autoincrement: STRING = "ALTER TABLE Permissions AUTO_INCREMENT = 1"
|
||||
-- reset autoincrement.
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user