Skip to content

Dynamicroles#23

Open
suhailasif wants to merge 11 commits into
lesterchan:masterfrom
suhailasif:dynamicroles
Open

Dynamicroles#23
suhailasif wants to merge 11 commits into
lesterchan:masterfrom
suhailasif:dynamicroles

Conversation

@suhailasif
Copy link
Copy Markdown

Custom roles can now be selected for file permissions. Previously it was hard coded and only General Roles were available for file permissions.

From now on any custom role added, shows up for file permissions drop box.

It is a multiple select box now, you can choose all the users you want to grant permissions to download file. Administrator have permission to download all the files by default.

Copy link
Copy Markdown
Owner

@lesterchan lesterchan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, it is ok, the code quality is inconsistent. Sometimes there is space before/after (, sometimes there is not. Let's follow WP and use space before and after (

Comment thread wp-downloadmanager.php Outdated
flush_rewrite_rules();
}

function generate_user_roles_select( $permission = array(), $mode = 'create' ) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think should prefix it with downloads_ generate_user_roles_select

Comment thread wp-downloadmanager.php Outdated
echo 'Administrators will have access to all downloads, that can\'t be protected. <br />';
$select = '<select name="file_permission[]" multiple>';
$options = '';
if ($mode == 'edit' ) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if ( $mode === 'edit' ) {

Comment thread wp-downloadmanager.php Outdated
}

function get_file_permissions_info() {
if ( ! empty( $_POST['file_permission'] ) ) {
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to sanitize $_POST['file_permission']

@suhailasif
Copy link
Copy Markdown
Author

I have done all the required fixes, some issue i faced while working on it. Fixed theme too.

@lesterchan
Copy link
Copy Markdown
Owner

Thanks, I will review them when I get back from my holiday in Jul.

@suhailasif
Copy link
Copy Markdown
Author

Great! No worries.

Comment thread wp-downloadmanager.php
}

function get_file_permissions_info() {
$permissoins_post = $_POST['file_permission'];
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$permissions

Comment thread wp-downloadmanager.php
$select = '<select name="file_permission[]" multiple>';
$options = '';
if ( $mode == 'edit' ) {
$permission = explode( '+', $permission );
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, any reason we use + instead of ","? I would prefer it to be "," rather than "+" as it is more readable and doesn't need to be urlencoded

Comment thread wp-downloadmanager.php
"file_last_downloaded_date varchar(20) NOT NULL default '',".
"file_hits int(10) NOT NULL default '0',".
"file_permission TINYINT(2) NOT NULL default '0',".
"file_permission varchar(255) NOT NULL default '0',".
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we change the col, we need to provide exisiting user an upgrade path.

Similar to https://github.com/lesterchan/wp-polls/blob/master/wp-polls.php#L1881-L1888

Comment thread wp-downloadmanager.php
foreach ( $roles as $role ) {
if ( in_array( $role, $user_roles ) ) {
$allowed = true;
return $allowed;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return true;

$allowed = true; is no longer needed.

Comment thread wp-downloadmanager.php
}
}

return $allowed;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return false;

Comment thread wp-downloadmanager.php
$roles[] = 'administrator';
$current_user = wp_get_current_user();
$user_roles = $current_user->roles;
$allowed = false;
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't need this line.

Comment thread wp-downloadmanager.php
$permissoins_post = $_POST['file_permission'];
$permissions = array();
foreach ( $permissoins_post as $permission ) {
$permissions[] = filter_var( $permission, FILTER_SANITIZE_STRING );
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should do a $permissions[] = sanitize_text_field( $permission );

Comment thread wp-downloadmanager.php
}

if ( ! empty( $permissions ) ) {
$permissions = $_POST['file_permission'];
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After sanitizing it, why do we use the unsanitized version again?

Comment thread download-add.php
$file_timestamp_second = ! empty( $_POST['file_timestamp_second'] ) ? intval( $_POST['file_timestamp_second'] ) : 0;
$file_date = gmmktime($file_timestamp_hour, $file_timestamp_minute, $file_timestamp_second, $file_timestamp_month, $file_timestamp_day, $file_timestamp_year);
$file_permission = ! empty( $_POST['file_permission'] ) ? intval( $_POST['file_permission'] ) : 0;
$file_permission = "'" . get_file_permissions_info(). "'";
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we need this? Instead can get_file_permissions_info() return a string instead of int?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants