Skip to content

Document the usage of the new permission tool "role_exists" #241

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

Closed
3D-I opened this issue Jul 26, 2021 · 3 comments · Fixed by #242
Closed

Document the usage of the new permission tool "role_exists" #241

3D-I opened this issue Jul 26, 2021 · 3 comments · Fixed by #242

Comments

@3D-I
Copy link

3D-I commented Jul 26, 2021

Working example

namespace phpbbstudio\mnote\migrations;

class install_permissions extends \phpbb\db\migration\migration
{
	public function effectively_installed()
	{
		$sql = 'SELECT * FROM ' . $this->table_prefix . "acl_options
			WHERE auth_option = '" . $this->db->sql_escape('a_phpbbstudio_mnote') . "'";
		$result = $this->db->sql_query_limit($sql, 1);
		$row = $this->db->sql_fetchrow($result);
		$this->db->sql_freeresult($result);

		return $row !== false;
	}

	public static function depends_on()
	{
		return ['\phpbb\db\migration\data\v33x\v334'];
	}

	public function update_data()
	{
		return [
			// Add permissions not set
			['permission.add', ['a_phpbbstudio_mnote']],
			['permission.add', ['m_phpbbstudio_mnote']],

			// Set permission on role if it exists
			['if', [
				['permission.role_exists', ['ROLE_ADMIN_FULL']],
				['permission.permission_set', ['ROLE_ADMIN_FULL', 'a_phpbbstudio_mnote']],
			]],

			['if', [
				['permission.role_exists', ['ROLE_MOD_FULL']],
				['permission.permission_set', ['ROLE_MOD_FULL', 'm_phpbbstudio_mnote']],
			]],
		];
	}
}
@3D-I
Copy link
Author

3D-I commented Jul 26, 2021

The effectively_installed() method here uses its own query instead of the native tool, just do not care, it works. 😉

@iMattPro
Copy link
Member

I was like, when did we get that? 🧐

Oh. I added it. Like a year ago. 🤪

@3D-I
Copy link
Author

3D-I commented Jul 27, 2021

Yes, you did it. 😜

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 a pull request may close this issue.

2 participants