Select global and project permissions of a given group (Anyone group is NOT supported)
Each row returns a {@link GroupPermissionDto}
556477
public void selectAllPermissionsByGroupId(DbSession dbSession, String organizationUuid, Integer groupId, ResultHandler resultHandler) {
    mapper(dbSession).selectAllPermissionsByGroupId(organizationUuid, groupId, resultHandler);
  }
828611
public function getAllowedStaffGroups($current = true)
    {
        // Always refresh because these values are otherwise not responsive to change
        $dbLookup = $this->util->getDbLookup();
        $groupId  = $this->getGroupId($current);
        $groups   = $dbLookup->getActiveStaffGroups();

        if ('master' === $this->getRole($current)) {
            $groups[-1] = $this->_('Project \'master\'');
            return $groups;
        }

        try {
            $setGroups     = $this->db->fetchOne(
                    "SELECT ggp_may_set_groups FROM gems__groups WHERE ggp_id_group = ?",
                    $groupId
                    );
            $groupsAllowed = explode(',', $setGroups);
        } catch (\Zend_Db_Exception $e) {
            // The database might not be updated
            $groupsAllowed = [];
        }

        $result = array();

        foreach ($groups as $id => $label) {
            if ((in_array($id, $groupsAllowed))) {
                $result[$id] = $groups[$id];
            }
        }
        natsort($result);

        return $result;
    }
292748
def _load_group_permissions(self):
        
        group_names = self._get_groups().get_group_names()

        perms = Permission.objects.filter(group__name__in=group_names)
        perms = perms.values_list('content_type__app_label', 'codename')
        perms = perms.order_by()

        self._group_permissions = set(["%s.%s" % (ct, name) for ct, name in perms])
1292565
public void collectPermissionIds(AccessControlGroup group, Set<String> permissions) {

    boolean added = permissions.add(group.getId());
    if (!added) {
      // we have already visited this node, stop recursion...
      return;
    }
    for (AccessControlPermission permission : group.getPermissions()) {
      permissions.add(permission.getId());
    }
    for (AccessControlGroup inheritedGroup : group.getInherits()) {
      collectPermissionIds(inheritedGroup, permissions);
    }
  }
864901
@Override
	public synchronized List<Permission> getPermissions()
	{
		if (permissions == null || permissions.isEmpty())
			return null;

		return new ArrayList<Permission>(this.permissions);
	}
550007
@SuppressWarnings("unchecked")
    public List<Permission> getPermissions() {
        final Query query = pm.newQuery(Permission.class);
        query.setOrdering("name asc");
        return (List<Permission>) query.execute();
    }
598514
@Override
    public boolean hasPermission(User user, E userGroup, Permission permission) {

        // always grant READ access to groups in which the user itself is a member
        if (user != null && permission.equals(Permission.READ)
            && userGroup.getMembers().contains(user)) {
            LOG.trace("Granting READ access on group where the user is member.");
            return true;
        }

        // call parent implementation
        return super.hasPermission(user, userGroup, permission);
    }
75973
public void grantDefaultPermissions(GroupValue groupValue) {
    PackageIdentity packageIdentity = new PackageIdentity(groupValue.getRootPackage().getName());
    GroupIdentity groupIdentity = new GroupIdentity(groupValue.getName());
    aclService.createAcl(groupIdentity);
    groupValue
        .getRoles()
        .forEach(
            roleValue -> {
              PermissionSet permissionSet = PERMISSION_SETS_PER_ROLE.get(roleValue.getLabel());
              Sid roleSid = createRoleSid(roleValue.getName());
              permissionService.grant(packageIdentity, permissionSet, roleSid);
              permissionService.grant(groupIdentity, permissionSet, roleSid);
            });
    if (groupValue.isPublic()) {
      permissionService.grant(groupIdentity, READ, createAuthoritySid(AUTHORITY_USER));
    }
  }
988959
public List<Integer> selectUserIdsWithGlobalPermission(DbSession dbSession, String organizationUuid, String permission) {
    return mapper(dbSession).selectUserIdsWithGlobalPermission(organizationUuid, permission);
  }
906536
public void deleteGlobalPermission(DbSession dbSession, int userId, String permission, String organizationUuid) {
    mapper(dbSession).deleteGlobalPermission(userId, permission, organizationUuid);
  }
1311547
protected Project filterProjectByPermission(final Project project, final User user,
      final Permission.Type type) {
    return filterProjectByPermission(project, user, type, null);
  }
1072223
def permitted_query(self, query, group, operations):
        ''''''
        session = query.session
        models = session.router
        user = group.user
        if user.is_superuser:   # super-users have all permissions
            return query
        roles = group.roles.query()
        roles = group.roles.query()  # query on all roles for group
        # The throgh model for Role/Permission relationship
        throgh_model = models.role.permissions.model
        models[throgh_model].filter(role=roles,
                                    permission__model_type=query.model,
                                    permission__operations=operations)

        # query on all relevant permissions
        permissions = router.permission.filter(model_type=query.model,
                                               level=operations)

        owner_query = query.filter(user=user)
        # all roles for the query model with appropriate permission level
        roles = models.role.filter(model_type=query.model, level__ge=level)
        # Now we need groups which have these roles
        groups = Role.groups.throughquery(
            session).filter(role=roles).get_field('group')
        # I need to know if user is in any of these groups
        if user.groups.filter(id=groups).count():
            # it is, lets get the model with permissions less
            # or equal permission level
            permitted = models.instancerole.filter(
                role=roles).get_field('object_id')
            return owner_query.union(model.objects.filter(id=permitted))
        else:
            return owner_query
833281
@RequestMapping(value = "globals/{type}/{id}", method = RequestMethod.DELETE)
    public Ack deleteGlobalPermission(@PathVariable PermissionTargetType type, @PathVariable int id) {
        return accountService.deleteGlobalPermission(type, id);
    }
521773
private int checkSelfPermission(Activity activity, String permission) {
    try {
      return androidPermissionService.checkSelfPermission(activity, permission);
    } catch (RuntimeException ignored) {
      return PackageManager.PERMISSION_DENIED;
    }
  }
887814
def global_permission_set(self):
        ''''''
        only_admins_create_admins = Or(
            AllowAdmin,
            And(
                ObjAttrTrue(
                    lambda r, _: r.data.get('admin') is not True),
                Or(
                    AllowPermission('org:admin')
                )
            )
        )

        return And(
            AllowOnlyAuthenticated,
            Or(
                Not(AllowCreate),
                only_admins_create_admins
            )
        )
447988
private static Map<String, Integer> permissions() {

        if (m_permissions == null) {
            LinkedHashMap<String, Integer> permissions = new LinkedHashMap<String, Integer>();
            permissions.put("GUI_PERMISSION_TYPE_READ_0", new Integer(CmsPermissionSet.PERMISSION_READ));
            permissions.put("GUI_PERMISSION_TYPE_WRITE_0", new Integer(CmsPermissionSet.PERMISSION_WRITE));
            permissions.put("GUI_PERMISSION_TYPE_VIEW_0", new Integer(CmsPermissionSet.PERMISSION_VIEW));
            permissions.put("GUI_PERMISSION_TYPE_CONTROL_0", new Integer(CmsPermissionSet.PERMISSION_CONTROL));
            permissions.put(
                "GUI_PERMISSION_TYPE_DIRECT_PUBLISH_0",
                new Integer(CmsPermissionSet.PERMISSION_DIRECT_PUBLISH));
            m_permissions = Collections.unmodifiableMap(permissions);
        }
        return m_permissions;
    }
860188
public int countUsersWithGlobalPermissionExcludingGroup(DbSession dbSession, String organizationUuid,
    String permission, int excludedGroupId) {
    return mapper(dbSession).countUsersWithGlobalPermissionExcludingGroup(organizationUuid, permission, excludedGroupId);
  }