public static void EnsureProjectActive(this IProjectEntity character)
 {
     if (!character.Project.Active)
     {
         throw new ProjectDeactivedException();
     }
 }
 public static bool HasMasterAccess([NotNull] this IProjectEntity entity, int?currentUserId)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     return(entity.HasMasterAccess(currentUserId, acl => true));
 }
 public static bool HasMasterAccess([NotNull] this IProjectEntity entity, int?currentUserId, Func <ProjectAcl, bool> requiredAccess)
 {
     if (entity == null)
     {
         throw new ArgumentNullException(nameof(entity));
     }
     return(entity.Project.ProjectAcls.Where(requiredAccess).Any(pa => pa.UserId == currentUserId));
 }
 /// <summary>
 /// Checks for master access is it's a match by Id
 /// </summary>
 protected static bool CheckMasterAccessIfMatchById(
     IProjectEntity entity,
     int?currentUserId,
     int?searchedEntityId)
 {
     return
         (entity.Id != searchedEntityId ||
          entity.Project.HasMasterAccess(currentUserId));
 }
Exemplo n.º 5
0
        protected ActionResult WithEntity(IProjectEntity field)
        {
            if (field == null)
            {
                return(HttpNotFound());
            }
            var project = field.Project;

            if (project == null)
            {
                return(HttpNotFound());
            }

            ViewBag.ProjectId = project.ProjectId;

            var acl = project.ProjectAcls.FirstOrDefault(a => a.UserId == CurrentUserIdOrDefault);
            //TODO[GroupsLoad]. If we not loaded groups already, that's slow
            var bigGroups = project.RootGroup.ChildGroups.Where(cg => !cg.IsSpecial && cg.IsActive);

            if (acl != null)
            {
                ViewBag.MasterMenu = new MasterMenuViewModel
                {
                    ProjectId         = project.ProjectId,
                    ProjectName       = project.ProjectName,
                    AccessToProject   = acl,
                    BigGroups         = bigGroups.Select(cg => new CharacterGroupLinkViewModel(cg)),
                    IsAcceptingClaims = project.IsAcceptingClaims,
                    IsActive          = project.Active,
                    RootGroupId       = project.RootGroup.CharacterGroupId,
                    HasAllrpg         = project.Details?.AllrpgId != null,
                    IsAdmin           = IsCurrentUserAdmin(),
                };
            }
            else
            {
                ViewBag.PlayerMenu = new PlayerMenuViewModel
                {
                    ProjectId         = project.ProjectId,
                    ProjectName       = project.ProjectName,
                    Claims            = project.Claims.OfUserActive(CurrentUserIdOrDefault).Select(c => new ClaimShortListItemViewModel(c)).ToArray(),
                    BigGroups         = bigGroups.Where(cg => cg.IsPublic || project.IsPlotPublished()).Select(cg => new CharacterGroupLinkViewModel(cg)),
                    IsAcceptingClaims = project.IsAcceptingClaims,
                    IsActive          = project.Active,
                    RootGroupId       = project.RootGroup.IsAvailable ? (int?)project.RootGroup.CharacterGroupId : null,
                    PlotPublished     = project.Details?.PublishPlot == true,
                    IsAdmin           = IsCurrentUserAdmin(),
                };
            }
            return(null);
        }
 public static void RequestMasterAccess(this IProjectEntity field, int currentUserId)
 {
     if (field == null)
     {
         throw new ArgumentNullException(nameof(field));
     }
     if (field.Project == null)
     {
         throw new ArgumentNullException(nameof(field.Project));
     }
     if (!field.HasMasterAccess(currentUserId))
     {
         throw new NoAccessToProjectException(field.Project, currentUserId);
     }
 }
 public static void RequestMasterAccess(this IProjectEntity field, int?currentUserId, Expression <Func <ProjectAcl, bool> > lambda)
 {
     if (field == null)
     {
         throw new ArgumentNullException(nameof(field));
     }
     if (field.Project == null)
     {
         throw new ArgumentNullException(nameof(field.Project));
     }
     if (!field.HasMasterAccess(currentUserId, acl => lambda.Compile()(acl)))
     {
         throw new NoAccessToProjectException(field.Project, currentUserId, lambda);
     }
 }
Exemplo n.º 8
0
        /// <summary>
        /// Create a new project repository
        /// </summary>
        /// <exception cref="ArgumentNullException"/>
        public ProjectRepository(string projectName, IDevNotesSQLiteConnection sqliteConnection)
        {
            // Check that connection is a valid object before proceeding.
            if (sqliteConnection is null)
            {
                throw new ArgumentNullException("sqliteConnection");
            }

            if (projectName is null)
            {
                throw new ArgumentNullException("projectName");
            }

            this.sqliteConnection = sqliteConnection;
            sqliteCommandFactory  = new SQLiteCommandFactory(sqliteConnection);
            currentProject        = new ProjectEntity(projectName, new List <ITaskEntity>());
        }
Exemplo n.º 9
0
 protected JoinRpgProjectEntityException(IProjectEntity entity, string message)
     : base(entity.Project, message)
 {
 }
Exemplo n.º 10
0
 public NoAccessToProjectException(IProjectEntity entity, int?userId)
     : base(entity, $"No access to entity of {entity.Project.ProjectName} for user {userId}")
 {
     UserId = userId;
 }
Exemplo n.º 11
0
 public EntityWrongStatusException(IProjectEntity entity)
     : base(entity, $"This operation can not be performed on entity with this status")
 {
 }
Exemplo n.º 12
0
 public ProjectEntityDeactivedException(IProjectEntity entity) : base(entity, $"This operation can't be performed on deactivated entity")
 {
 }
Exemplo n.º 13
0
 public static bool HasEditRolesAccess(this IProjectEntity character, int?currentUserId)
 {
     return(character.HasMasterAccess(currentUserId, s => s.CanEditRoles) && character.Project.Active);
 }