Skip to content

Commit

Permalink
Open-Web-Analytics#577 access control (duplicate Open-Web-Analytics#288
Browse files Browse the repository at this point in the history
  • Loading branch information
danielp committed Jan 13, 2012
1 parent 1b41f05 commit b26123a
Show file tree
Hide file tree
Showing 35 changed files with 636 additions and 207 deletions.
2 changes: 2 additions & 0 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
// Initialize owa admin
$owa = new owa_php;


if (!$owa->isOwaInstalled()) {
// redirect to install
owa_lib::redirectBrowser(owa_coreAPI::getSetting('base','public_url').'install.php');
Expand All @@ -44,6 +45,7 @@
// run controller or view and echo page content
echo $owa->handleRequestFromURL();
} else {

// unload owa
$owa->restInPeace();
}
Expand Down
2 changes: 1 addition & 1 deletion modules/base/apiRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function action() {
// doesn't look like the currentuser has the necessary priviledges
owa_coreAPI::debug('User does not have capability required by this controller.');
// auth user
$auth = &owa_auth::get_instance();
$auth = owa_auth::get_instance();
$status = $auth->authenticateUser();
// if auth was not successful then return login view.
if ($status['auth_status'] != true) {
Expand Down
4 changes: 2 additions & 2 deletions modules/base/classes/installController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ function createAdminUser($email_address, $real_name = '', $password = '') {
if (empty($id_check)) {

//Check to see if user name already exists
$u->getByColumn('user_id', 'admin');
$u->getByColumn('user_id', owa_user::ADMIN_USER_ID);

$id = $u->get('id');

Expand All @@ -89,7 +89,7 @@ function createAdminUser($email_address, $real_name = '', $password = '') {
if ( ! $password ) {
$password = $u->generateRandomPassword();
}
$ret = $u->createNewUser('admin', 'admin', $password, $email_address, $real_name);
$ret = $u->createNewUser('admin', owa_user::ADMIN_USER_ID, $password, $email_address, $real_name);
owa_coreAPI::debug("Admin user created successfully.");
return $password;

Expand Down
2 changes: 1 addition & 1 deletion modules/base/classes/installManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function createAdminUser($email_address, $real_name = '', $password = '') {
if (empty($id_check)) {

//Check to see if user name already exists
$u->getByColumn('user_id', 'admin');
$u->getByColumn('user_id', owa_user::ADMIN_USER_ID);

$id = $u->get('id');

Expand Down
3 changes: 3 additions & 0 deletions modules/base/classes/resultSetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,9 @@ function applyMetaDataToSingleResultRow($row) {
$type = 'metric';
$data_type = $this->getMetric($k)->getDataType();
}
else {
throw new Exception($k.' is not a metric or dimension. Check the configuration!');
}



Expand Down
6 changes: 4 additions & 2 deletions modules/base/classes/service.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ function _loadEventProcessors() {

}

function &getCurrentUser() {

/**
* @return owa_serviceUser
*/
function getCurrentUser() {
return $this->current_user;
}

Expand Down
64 changes: 37 additions & 27 deletions modules/base/classes/serviceUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@


class owa_serviceUser extends owa_base {

var $user;
/**
* @var owa_user
*/
public $user;
var $capabilities = array();
var $preferences = array();
var $is_authenticated;
Expand All @@ -55,26 +57,24 @@ function loadRelatedUserData() {
$this->preferences = $this->getPreferences($this->user->get('user_id'));
return;
}

function getCapabilities($role) {

$caps = owa_coreAPI::getSetting('base', 'capabilities');

/**
* gets allowed capabilities for the user role
* @param unknown_type $role
*/
function getCapabilities($role) {
$caps = owa_coreAPI::getSetting('base', 'capabilities');
if (array_key_exists($role, $caps)) {
return $caps[$role];
} else {
return array();
}

}
}

function getPreferences($user_id) {

function getPreferences($user_id) {
return false;
}

function getRole() {

function getRole() {
return $this->user->get('role');
}

Expand All @@ -96,23 +96,33 @@ function getUserData($name) {
return $this->user->get($name);
}

function isCapable($cap) {
//owa_coreAPI::debug(print_r($this->user->getProperties(), true));
owa_coreAPI::debug("cap ".$cap);
// just in case there is no cap passed
if (!empty($cap)) {
//adding @ here as is_array throws warning that an empty array is not the right data type!
if (in_array($cap, $this->capabilities)) {
return true;
} else {
return false;
}

} else {

/**
* Checks if user is capable to do something
* @param string $cap
* @param integer $currentSiteId optionel - only needed if cap is a capabilities That Require SiteAccess. You need to pass site_id (not id) field
*/
function isCapable($cap, $siteId = null) {
owa_coreAPI::debug("check cap ".$cap);
//global admin can always everything:
if ($this->user->isOWAAdmin() || empty($cap)) {
return true;
}
if (!in_array($cap, $this->capabilities)) {
return false;
}

$capabilitiesThatRequireSiteAccess = owa_coreAPI::getSetting('base', 'capabilitiesThatRequireSiteAccess');
if (is_array($capabilitiesThatRequireSiteAccess) && in_array($cap, $capabilitiesThatRequireSiteAccess)) {
if (is_null($siteId)) {
throw new InvalidArgumentException('Capability "'.$cap.'" that should be checked requires a sited - but nothing given');
}
$site = owa_coreAPI::entityFactory('base.site');
$site->load($siteId,'site_id');
if (!$site->isUserAssigned($this->user->get('id'))) {
return false;
}
}
return true;
}

// mark the user as authenticated and populate their capabilities
Expand Down
Loading

0 comments on commit b26123a

Please sign in to comment.