About Project Admin Privileges

Submitted by meiji00 on 2013-01-08

Here's the thing, I want when I'm adding an issue is that some attributes are hidden when the user is only a project member, but I want is when I'm the project administrator all the hidden attributes are bow visible.
I've already accomplished it in some pages but I still get stuck when in adding an issue.

the code is

<?php
if ( $issue[ 'project_access' ] == System_Const::AdministratorAccess ){
$query = 'SELECT attr_id, attr_name, attr_def FROM {attr_types} WHERE type_id = %d ORDER BY attr_name COLLATE LOCALE';
$attributes = $this->connection->queryTable( $query, $typeId );

self::$attributeTypes[ $typeId ] = $attributes;
}
?>

How can I get this piece of code work on WebIssue\system\api\typemanager.inc.php

Thanks in advanced.

The problem is that the issue types are independent from projects, so you have to pass the project ID to the typemanager in order to be able to determine the user's permissions.

Regards,
Michał

Rovy Ray Perlas

So what code will I have to use? How do I pass the project ID?
Sorry I'm a noob to php compared to .NET programming. T_T

Rovy Ray Perlas

So what code will I have to use? How do I pass the project ID?
Sorry I'm a noob to php compared to .NET programming. T_T

Here's how it might work:

  • Add a function to TypeManager, similar to getAttributeTypesForIssueType, but also getting a folder, for example: public function getAttributeTypesForIssueTypeAndFolder( $type, $folder )
  • In that function, check $folder[ 'project_access' ] to determine the user's permission
  • Modify the processValues() function on the client/issues/issue.inc.php page so that it calls the new function: $rows = $typeManager->getAttributeTypesForIssueTypeAndFolder( $type, $this->folder );

Regards,
Michał

Rovy Ray Perlas

Thanks a lot it worked perfectly.

Lastly, I want to hide the attributes too when Im editing an Issue, where can I find it?
The adding of issue is in typemanager.inc.php right? How about when Edit Attributes?

Thanks.

Modify the getAllAttributeValuesForIssue method of System_Api_IssueManager. It's easy because the $issue already contains the 'project_access' property.

Regards,
Michał

Rovy Ray Perlas

It did hide the attribute while I'm editing but it also hides the attribute when viewing it in client/index.php

What I want is to hide attributes when editing but still visible if you view it.

Or at least make some attributes read only for regular users so project admins can only edit the attribute.

Thanks.

Copy getAllAttributeValuesForIssue, calling it for example getAllAttributeValuesForEditingIssue, and add a similar check based on $issue[ 'project_access' ]. Then modify processValues() in issue.inc.php to call that modified function instead of the original one.

Regards,
Michał

Rovy Ray Perlas

Wow okay that was stupid of me, ahaha it was just the same as adding an issue.

Thanks a lot mimec you and your Web Issue has been a really great help!

Thanks.

Hi Michał,

I have a similar requirement of restricting the display of certain attribute for regular user where project admin should have the full view in case of editing, followed your instruction given above and kindly reveiw the code before executing,
note: attr_names starting only with ** are required to be appered for regular user,

public function getAllAttributeValuesForEditingIssue( $issue)
{
$issueId = $issue[ 'issue_id' ];
$typeId = $issue[ 'type_id' ];

if ( $issue[ 'project_access' ] != System_Const::AdministratorAccess )

$query = 'SELECT a.attr_id, a.attr_name, a.attr_def, v.attr_value'
. ' FROM {attr_types} AS a'
. ' JOIN {attr_values} AS v ON v.attr_id = a.attr_id AND v.issue_id = %d'
. ' WHERE a.type_id = %d AND a.attr_name LIKE '**%' ORDER BY a.attr_name COLLATE LOCALE';

return $this->connection->queryTable( $query, $issueId, $typeId);
}

************
processValues() in issue.inc.php

$rows = $issueManager->getAllAttributeValuesForEditingIssue( $this->issue );

regards,
Suminda,

Did you happen to modify only the existing code for

<?php
public function getAllAttributeValuesForIssue( $issue, $flags = 0 )
?>

???

If you did I think that is your problem.

You need to retain the original function and add your modified function
it should look like this

<?php
public function getAllAttributeValuesForIssue( $issue, $flags = 0 )
    {
        $issueId = $issue[ 'issue_id' ];
        $typeId = $issue[ 'type_id' ];

        $query = 'SELECT a.attr_id, a.attr_name, a.attr_def, v.attr_value'
            . ' FROM {attr_types} AS a';
        if ( !( $flags & self::HideEmptyValues ) )
            $query .= ' LEFT OUTER';
        $query .= ' JOIN {attr_values} AS v ON v.attr_id = a.attr_id AND v.issue_id = %d'
            . ' WHERE a.type_id = %d'
            . ' ORDER BY a.attr_name COLLATE LOCALE';

        return $this->connection->queryTable( $query, $issueId, $typeId );
    }

public function getAllAttributeValuesForEditingIssue( $issue )
{
$issueId = $issue[ 'issue_id' ];
$typeId = $issue[ 'type_id' ];

if ( $issue[ 'project_access' ] != System_Const::AdministratorAccess )

$query = 'SELECT a.attr_id, a.attr_name, a.attr_def, v.attr_value'
. ' FROM {attr_types} AS a'
. ' JOIN {attr_values} AS v ON v.attr_id = a.attr_id AND v.issue_id = %d'
. ' WHERE a.type_id = %d AND a.attr_name LIKE '**%' ORDER BY a.attr_name COLLATE LOCALE';

return $this->connection->queryTable( $query, $issueId, $typeId);
}
?>

and a follow up question
why did you remove theif ( !( $flags & self::HideEmptyValues ) ) code?

hi,

I haven't change the original function, did only modification on a new function for editing as mentioned by michal in previous comment and I removed flag since my attribute values are required always and no way to contain empty,

regards,

suminda,