Create PostgreSQL ROLE (user) if it doesn’t exist

Simple script (question asked) Building on @a_horse_with_no_name‘s answer and improved with @Gregory’s comment: DO $do$ BEGIN IF EXISTS ( SELECT FROM pg_catalog.pg_roles WHERE rolname=”my_user”) THEN RAISE NOTICE ‘Role “my_user” already exists. Skipping.’; ELSE CREATE ROLE my_user LOGIN PASSWORD ‘my_password’; END IF; END $do$; Unlike, for instance, with CREATE TABLE there is no IF NOT EXISTS … Read more

Find out if someone has a role

The discord.js api has been updated and there is a better way since .exists() has been deprecated. if (message.member.roles.cache.some(role => role.name === ‘Whatever’)) {} This is better than .find() because .find() returns the role object (or undefined) which is then converted into a boolean. The .some() method returns a boolean by default.

asp.net mvc decorate [Authorize()] with multiple enums

Here is a simple and elegant solution which allows you to simply use the following syntax: [AuthorizeRoles(MyEnum.Admin, MyEnum.Moderator)] When creating your own attribute, use the params keyword in your constructor: public class AuthorizeRoles : AuthorizeAttribute { public AuthorizeRoles(params MyEnum[] roles) { … } protected override bool AuthorizeCore(HttpContextBase httpContext) { … } } This will allow … Read more

Discord.js Bot Welcomes Member, Assign a Role and send them a DM

Your code looks fine, the problem is that the event isn’t triggered. Thats because discord turned off “privileged intents” by default. Some intents are defined as “Privileged” due to the sensitive nature of the data. Those intents are: GUILD_PRESENCES GUILD_MEMBERS One effect of that is what you are experiencing, the not working guildMemberAdd event. The … Read more

Role based authentication in the new MVC 4 Internet template using simplemembership

Found an answer here by Mehdi Golchin which seems to take care of: [Authorize(Roles=”admin,editor,publisher”)] If I also add this to the home controller: [InitializeSimpleMembership] Because this attribute is on the Accounts controller, SimpleMembership database gets initialize only after the first use of the accounts controller like login/register. Even when the current user gets logged in … Read more

Grant all on a specific schema in the db to a group role in PostgreSQL

You found the shorthand to set privileges for all existing tables in the given schema. The manual clarifies: (but note that ALL TABLES is considered to include views and foreign tables). Bold emphasis mine. serial columns are implemented with nextval() on a sequence as column default and, quoting the manual: For sequences, this privilege allows … Read more

asp.net identity get all roles of logged in user

Controller.User.Identity is a ClaimsIdentity. You can get a list of roles by inspecting the claims… var roles = ((ClaimsIdentity)User.Identity).Claims .Where(c => c.Type == ClaimTypes.Role) .Select(c => c.Value); — update — Breaking it down a bit more… using System.Security.Claims; // …….. var userIdentity = (ClaimsIdentity)User.Identity; var claims = userIdentity.Claims; var roleClaimType = userIdentity.RoleClaimType; var roles = … Read more