Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dynamicroles #23

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Dynamicroles #23

wants to merge 11 commits into from

Conversation

suhailasif
Copy link

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
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 (

@@ -1576,3 +1576,48 @@ function downloadmanager_activate() {

flush_rewrite_rules();
}

function generate_user_roles_select( $permission = array(), $mode = 'create' ) {
Copy link
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

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
Owner

Choose a reason for hiding this comment

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

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

}

function get_file_permissions_info() {
if ( ! empty( $_POST['file_permission'] ) ) {
Copy link
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
Author

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

@lesterchan
Copy link
Owner

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

@suhailasif
Copy link
Author

Great! No worries.

}

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

Choose a reason for hiding this comment

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

$permissions

$select = '<select name="file_permission[]" multiple>';
$options = '';
if ( $mode == 'edit' ) {
$permission = explode( '+', $permission );
Copy link
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

@@ -1509,7 +1509,7 @@ function downloadmanager_activate() {
"file_updated_date varchar(20) NOT NULL default '',".
"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
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

foreach ( $roles as $role ) {
if ( in_array( $role, $user_roles ) ) {
$allowed = true;
return $allowed;
Copy link
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.

}
}

return $allowed;
Copy link
Owner

Choose a reason for hiding this comment

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

return false;

$roles[] = 'administrator';
$current_user = wp_get_current_user();
$user_roles = $current_user->roles;
$allowed = false;
Copy link
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.

$permissoins_post = $_POST['file_permission'];
$permissions = array();
foreach ( $permissoins_post as $permission ) {
$permissions[] = filter_var( $permission, FILTER_SANITIZE_STRING );
Copy link
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 );

}

if ( ! empty( $permissions ) ) {
$permissions = $_POST['file_permission'];
Copy link
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?

@@ -72,9 +72,10 @@
$file_timestamp_minute = ! empty( $_POST['file_timestamp_minute'] ) ? intval( $_POST['file_timestamp_minute'] ) : 0;
$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
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