Skip to content

Commit

Permalink
Merge pull request #13 from pravinTek/release1.0.0
Browse files Browse the repository at this point in the history
#12 chore: Update query, added joins based on filters & introduce new ACL
  • Loading branch information
thite-amol authored Aug 26, 2019
2 parents 984ac6e + b81b0df commit 5cc9683
Show file tree
Hide file tree
Showing 9 changed files with 285 additions and 50 deletions.
1 change: 1 addition & 0 deletions src/components/com_cluster/administrator/access.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
<action name="core.edit" title="JACTION_EDIT" description="JACTION_EDIT_COMPONENT_DESC" />
<action name="core.edit.state" title="JACTION_EDITSTATE" description="JACTION_EDITSTATE_COMPONENT_DESC" />
<action name="core.edit.own" title="JACTION_EDITOWN" description="JACTION_EDITOWN_COMPONENT_DESC" />
<action name="core.manageall" title="JACTION_MANAGE_ALL_CLUSTER" description="JACTION_MANAGE_ALL_CLUSTER_DESC" />
</section>
</access>
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,6 @@ COM_CLUSTER_PAGE_VIEW_USER = "Cluster user: View"
COM_CLUSTER_USER_LIST_VIEW_NAME="User"
COM_CLUSTER_USER_LIST_VIEW_CLUSTER="Cluster Name"
COM_CLUSTER_USERLIST_VIEW_ID="ID"

JACTION_MANAGE_ALL_CLUSTER="Manage All Clusters"
JACTION_MANAGE_ALL_CLUSTER_DESC="Manage All Clusters"
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ COM_CLUSTER_CLUSTER_VIEW_EDIT_DESC="Shows a form to create a New Cluster."
COM_CLUSTER_CLUSTERS_VIEW_DEFAULT_TITLE="List all Clusters"
COM_CLUSTER_CLUSTERS_VIEW_DEFAULT_DESC="Shows a list of all the Clusters."
COM_CLUSTER_TITLE_ITEM_VIEW_CLUSTER="Single Cluster"
COM_CLUSTER_TITLE_CLUSTER="Cluster"
COM_CLUSTER_TITLE_CLUSTER="Cluster"
COM_CLUSTERS_VIEW_CLUSTER_USERS="Cluster users"
30 changes: 30 additions & 0 deletions src/components/com_cluster/administrator/libraries/cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,34 @@ public function isOwner($userId = null)

return false;
}

/**
* Function isMember to check user associated with passed cluster_id
*
* @param INT $userId User Id
*
* @return boolean
*
* @since __DEPLOY_VERSION__
*/
public function isMember($userId = null)
{
$userId = Factory::getuser($userId)->id;

$ClusterModel = ClusterFactory::model('ClusterUsers', array('ignore_request' => true));

$ClusterModel->setState('filter.published', 1);
$ClusterModel->setState('filter.cluster_id', (int) $this->id);
$ClusterModel->setState('filter.user_id', $userId);

// Check user associated with passed cluster_id
$clusters = $ClusterModel->getItems();

if (!empty($clusters))
{
return true;
}

return false;
}
}
31 changes: 26 additions & 5 deletions src/components/com_cluster/administrator/models/clusterusers.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
// No direct access to this file
defined('_JEXEC') or die('Restricted access');

use Joomla\CMS\Factory;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\Component\ComponentHelper;

/**
* Methods supporting a list of records.
Expand All @@ -34,7 +36,7 @@ public function __construct($config = array())
$config['filter_fields'] = array(
'id', 'cu.id',
'cluster_id', 'cu.cluster_id',
'state', 'cu.state',
'state', 'cu.state','cl.name','cl.client_id'
);
}

Expand All @@ -54,11 +56,30 @@ protected function getListQuery()
$db = $this->getDbo();
$query = $db->getQuery(true);

$query->select(array('cu.*','cl.name', 'users.name as uname'));
$query->select(array('cu.*','cl.name', 'users.name as uname', 'users.username','cl.name as title', 'cl.client_id as client_id'));
$query->from($db->quoteName('#__tj_cluster_nodes', 'cu'));
$query->join('INNER', $db->quoteName('#__users', 'users') . ' ON (' . $db->quoteName('cu.user_id') . ' = ' . $db->quoteName('users.id') . ')');
$query->join('INNER', $db->quoteName('#__users', 'users') . ' ON (' . $db->quoteName('cu.user_id') . ' = '
. $db->quoteName('users.id') . ')');
$query->join('INNER', $db->quoteName('#__tj_clusters', 'cl') . ' ON (' . $db->quoteName('cl.id') . ' = ' . $db->quoteName('cu.cluster_id') . ')');

// Get com_subusers component status
$subUserExist = ComponentHelper::getComponent('com_subusers', true)->enabled;

if ($subUserExist)
{
$roleId = $this->getState('filter.role_id');

if (is_numeric($roleId))
{
$query->join('INNER', $db->qn('#__tjsu_users', 'su') .
' ON (' . $db->qn('users.id') . ' = ' . $db->qn('su.user_id') . ' AND ' . $db->qn('su.client') . ' = "com_multiagency" )');
$query->join('INNER', $db->qn('#__tjsu_roles', 'r') .
' ON (' . $db->qn('r.id') . ' = ' . $db->qn('su.role_id') . ' AND ' . $db->qn('r.state') . ' = 1 )');

$query->where($db->quoteName('su.role_id') . ' != ' . (int) $roleId);
}
}

// Filter by search in title.
$search = $this->getState('filter.search');

Expand Down Expand Up @@ -122,7 +143,7 @@ protected function getListQuery()
$query->where("cl.client_id IN ('" . implode("','", $clusterClientId) . "')");
}

// Filter by state
// Filter by cluster table state
$published = $this->getState('filter.published');

if (is_numeric($published))
Expand All @@ -134,7 +155,7 @@ protected function getListQuery()
$query->where('(cl.state = 0 OR cl.state = 1)');
}

// Filter by blocked users
// Filter users by block
$blockUser = $this->getState('filter.block');

if (is_numeric($blockUser))
Expand Down
103 changes: 85 additions & 18 deletions src/components/com_cluster/administrator/models/forms/cluster.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,91 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset>
<field name="id" type="hidden" />
<field name="name" type="text" required="true" filter="string" label="COM_CLUSTER_CLUSTER_FORM_LBL_NAME" description="COM_CLUSTER_CLUSTER_FORM_DESC_NAME" />
<field name="description" type="text" filter="SAFEHTML" label="COM_CLUSTER_CLUSTER_FORM_LBL_DESCRIPTION" description="COM_CLUSTER_CLUSTER_FORM_DESC_DESCRIPTION" />
<field name="params" type="textarea" filter="string" label="COM_CLUSTER_CLUSTER_FORM_LBL_PARAMS" description="COM_CLUSTER_CLUSTER_FORM_DESC_PARAMS" />
<field name="client" required="true" type="text" filter="string" label="COM_CLUSTER_CLUSTER_FORM_LBL_CLIENT" description="COM_CLUSTER_CLUSTER_FORM_DESC_CLIENT" />
<field name="client_id" required="true" type="text" filter="INT" default="0" label="COM_CLUSTER_CLUSTER_FORM_LBL_CLIENT_ID" description="COM_CLUSTER_CLUSTER_FORM_DESC_CLIENT_ID" size="10" />
<field name="state" type="list" filter="intval" label="JSTATUS" description="" default="1" class="inputbox" size="1">
<option value="1">JPUBLISHED</option>
<option value="0">JUNPUBLISHED</option>
<option value="2">JARCHIVED</option>
<option value="-2">JTRASHED</option>
<field name="id" type="hidden"/>
<field
name="name"
type="text"
required="true"
filter="string"
label="COM_CLUSTER_CLUSTER_FORM_LBL_NAME"
description="COM_CLUSTER_CLUSTER_FORM_DESC_NAME"/>
<field
name="description"
type="text"
filter="SAFEHTML"
label="COM_CLUSTER_CLUSTER_FORM_LBL_DESCRIPTION"
description="COM_CLUSTER_CLUSTER_FORM_DESC_DESCRIPTION"/>

<field
name="params"
type="textarea"
filter="string"
label="COM_CLUSTER_CLUSTER_FORM_LBL_PARAMS"
description="COM_CLUSTER_CLUSTER_FORM_DESC_PARAMS"/>

<field
name="client"
required="true"
type="text"
filter="string"
label="COM_CLUSTER_CLUSTER_FORM_LBL_CLIENT"
description="COM_CLUSTER_CLUSTER_FORM_DESC_CLIENT"/>

<field
name="client_id"
required="true"
type="text"
filter="INT"
default="0"
label="COM_CLUSTER_CLUSTER_FORM_LBL_CLIENT_ID"
description="COM_CLUSTER_CLUSTER_FORM_DESC_CLIENT_ID"
size="10" />

<field
name="state"
type="list"
filter="intval"
label="JSTATUS"
description=""
default="1"
class="inputbox"
size="1">
<option value="1">JPUBLISHED</option>
<option value="0">JUNPUBLISHED</option>
<option value="2">JARCHIVED</option>
<option value="-2">JTRASHED</option>
</field>
<field name="created_by" type="hidden" />
<field name="modified_on" type="hidden" />
<field name="modified_by" type="hidden" />
<field name="created_on" type="hidden" />
<field name="ordering" type="hidden" filter="INT" />
<field name="checked_out" type="hidden" filter="unset" />
<field name="checked_out_time" type="hidden" filter="unset" />

<field
name="created_by"
type="hidden"/>

<field
name="modified_on"
type="hidden"/>

<field
name="modified_by"
type="hidden"
/>

<field
name="created_on"
type="hidden"/>

<field
name="ordering"
type="hidden"
filter="INT"/>

<field
name="checked_out"
type="hidden"
filter="unset"/>

<field
name="checked_out_time"
type="hidden"
filter="unset"/>
</fieldset>
</form>
Original file line number Diff line number Diff line change
@@ -1,21 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fieldset>
<field name="id" type="hidden" />
<field name="cluster_id" required="true" type="sql" query="SELECT id,name FROM `#__tj_clusters` WHERE state = '1' ORDER BY id DESC" key_field="id" value_field="name" translate="false" header="COM_CLUSTER_USER_FORM_LBL_CLUSTER_HEADER" filter="int" label="COM_CLUSTER_USER_FORM_LBL_CLUSTER" description="COM_CLUSTER_USER_FORM_LBL_CLUSTER_DESC" />
<field name="user_id" required="true" type="user" filter="INT" default="0" label="COM_CLUSTER_USER_FORM_LBL_USER" description="COM_CLUSTER_USER_FORM_LBL_USER_DESC" size="10" />
<field name="state" type="list" filter="intval" label="JSTATUS" description="" default="1" class="inputbox" size="1">
<option value="1">JPUBLISHED</option>
<option value="0">JUNPUBLISHED</option>
<option value="2">JARCHIVED</option>
<option value="-2">JTRASHED</option>
<field name="id" type="hidden"/>
<field
name="cluster_id"
required="true"
type="sql"
query="SELECT id,name FROM `#__tj_clusters` WHERE state = '1' ORDER BY id DESC" key_field="id" value_field="name"
translate="false"
header="COM_CLUSTER_USER_FORM_LBL_CLUSTER_HEADER"
filter="int"
label="COM_CLUSTER_USER_FORM_LBL_CLUSTER"
description="COM_CLUSTER_USER_FORM_LBL_CLUSTER_DESC"
/>
<field
name="user_id"
required="true"
type="user"
filter="INT"
default="0"
label="COM_CLUSTER_USER_FORM_LBL_USER"
description="COM_CLUSTER_USER_FORM_LBL_USER_DESC"
size="10" />

<field
name="state"
type="list"
filter="intval"
label="JSTATUS"
description=""
default="1"
class="inputbox"
size="1">
<option value="1">JPUBLISHED</option>
<option value="0">JUNPUBLISHED</option>
<option value="2">JARCHIVED</option>
<option value="-2">JTRASHED</option>
</field>
<field name="created_by" type="user" label="JGLOBAL_FIELD_CREATED_BY_LABEL" class="readonly" readonly="true" filter="unset" />
<field name="modified_on" type="hidden" />
<field name="modified_by" type="user" label="JGLOBAL_FIELD_MODIFIED_BY_LABEL" class="readonly" readonly="true" filter="unset" />
<field name="created_on" type="hidden" />
<field name="ordering" type="hidden" filter="INT" />
<field name="checked_out" type="hidden" filter="unset" />
<field name="checked_out_time" type="hidden" filter="unset" />

<field
name="created_by"
type="user"
label="JGLOBAL_FIELD_CREATED_BY_LABEL"
class="readonly"
readonly="true"
filter="unset"
/>

<field
name="modified_on"
type="hidden"/>

<field
name="modified_by"
type="user"
label="JGLOBAL_FIELD_MODIFIED_BY_LABEL"
class="readonly"
readonly="true"
filter="unset"
/>
<field
name="created_on"
type="hidden"/>

<field
name="ordering"
type="hidden"
filter="INT"/>

<field
name="checked_out"
type="hidden"
filter="unset"/>

<field
name="checked_out_time"
type="hidden"
filter="unset"/>
</fieldset>
</form>
Original file line number Diff line number Diff line change
@@ -1,13 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<form>
<fields name="filter">
<field name="search" type="text" label="COM_CLUSTER_FILTER_SEARCH_LABEL" description="COM_CLUSTER_CLUSTERS_FILTER_SEARCH_DESC" hint="JSEARCH_FILTER" />
<field name="state" type="status" label="COM_CLUSTER_FILTER_PUBLISHED" description="COM_CLUSTER_FILTER_PUBLISHED_DESC" onchange="this.form.submit();">
<field
name="search"
type="text"
label="COM_CLUSTER_FILTER_SEARCH_LABEL"
description="COM_CLUSTER_CLUSTERS_FILTER_SEARCH_DESC"
hint="JSEARCH_FILTER"
/>
<field
name="state"
type="status"
label="COM_CLUSTER_FILTER_PUBLISHED"
description="COM_CLUSTER_FILTER_PUBLISHED_DESC"
onchange="this.form.submit();"
>
<option value="">JOPTION_SELECT_PUBLISHED</option>
</field>
<input type="hidden" name="form_submited" value="1" />
<input type="hidden" name="form_submited" value="1"/>
</fields>

<fields name="list">
<field name="limit" type="limitbox" label="COM_CLUSTER_LIST_LIMIT" description="COM_CLUSTER_LIST_LIMIT_DESC" class="input-mini" default="25" onchange="this.form.submit();" />
<field
name="limit"
type="limitbox"
label="COM_CLUSTER_LIST_LIMIT"
description="COM_CLUSTER_LIST_LIMIT_DESC"
class="input-mini"
default="25"
onchange="this.form.submit();"
/>
</fields>
</form>
</form>
Loading

0 comments on commit 5cc9683

Please sign in to comment.