Exemplo n.º 1
0
        public IActionResult RemoveHost(string id, [FromForm] string userDisplayId)
        {
            UserAccount user        = GetCurrentUser();
            Event       targetEvent = DatabaseHelpers.Events.GetEventByUrl(id);

            if (targetEvent == null)
            {
                return(NotFound());
            }

            EventPermissions userPermissions = DatabaseHelpers.Events.GetUserPermissionsForEvent(user, targetEvent);

            if (!userPermissions.HasFlag(EventPermissions.EditEventSettings))
            {
                return(Forbid());
            }

            UserAccount targetUser = DatabaseHelpers.Context.QueryByDisplayID <UserAccount>(userDisplayId);

            if (targetUser == null)
            {
                return(NotFound());
            }

            if (user.ID != targetUser.ID)
            {
                DatabaseHelpers.Events.RemoveUserAsHost(targetUser, targetEvent);
            }

            return(Redirect(targetEvent.GetUrl() + "/hosts"));
        }
Exemplo n.º 2
0
        public IActionResult Settings(string id, [FromForm, Bind] Event eventChanges)
        {
            UserAccount user        = GetCurrentUser();
            Event       targetEvent = DatabaseHelpers.Events.GetEventByUrl(id);

            if (targetEvent == null)
            {
                return(NotFound());
            }

            EventPermissions userPermissions = DatabaseHelpers.Events.GetUserPermissionsForEvent(user, targetEvent);

            if (!userPermissions.HasFlag(EventPermissions.EditEventSettings))
            {
                return(Forbid());
            }

            eventChanges.ID = targetEvent.ID;

            ModelState.Clear();
            TryValidateModel(eventChanges);

            // Collect the initial model errors
            List <string> errorMessages = new List <string>();

            if (!ModelState.IsValid)
            {
                errorMessages = ModelState.Values.SelectMany(value => value.Errors).Select(error => error.ErrorMessage).ToList();
            }

            // Perform additional validation

            if (errorMessages.Count > 0)
            {
                // If validation errors occured, display them on the edit page.
                ViewBag.ErrorMessages = errorMessages.ToArray();
                return(Settings(id));
            }

            targetEvent.Title       = eventChanges.Title;
            targetEvent.URL         = eventChanges.URL;
            targetEvent.Description = eventChanges.Description;

            targetEvent.EventType = eventChanges.EventType;
            targetEvent.Settings  = eventChanges.Settings;

            targetEvent.RevealDate  = eventChanges.RevealDate;
            targetEvent.StartDate   = eventChanges.StartDate;
            targetEvent.EndDate     = eventChanges.EndDate;
            targetEvent.VoteEndDate = eventChanges.VoteEndDate;

            DatabaseHelpers.Context.UpdateAndSave(targetEvent);

            return(Redirect(targetEvent.GetUrl()));
        }
Exemplo n.º 3
0
        public IActionResult RejectReport([FromBody] int reportId)
        {
            Report           r           = DatabaseHelpers.Context.QueryByID <Report>(reportId);
            EventPermissions permissions = DatabaseHelpers.Events.GetUserPermissionsForEvent(GetCurrentUser(), r.Entry.Event);

            if (!permissions.HasFlag(EventPermissions.ManageEntries))
            {
                return(Unauthorized());
            }

            DatabaseHelpers.Entries.UpdateEntryReportStatus(r, ReportStatus.Rejected);

            return(Ok());
        }
        public bool HasPermission(
            ClaimsPrincipal user,
            EventEntity ev,
            EventPermissions permission,
            IEnumerable <RegionRoleEntity> regionRoles)
        {
            switch (permission)
            {
            case EventPermissions.View:
                return(CanViewEvent(user, ev, regionRoles));

            default:
                return(false);
            }
        }
Exemplo n.º 5
0
        public IActionResult DeleteReportedPost([FromBody] int reportId)
        {
            Report           r           = DatabaseHelpers.Context.QueryByID <Report>(reportId);
            EventPermissions permissions = DatabaseHelpers.Events.GetUserPermissionsForEvent(GetCurrentUser(), r.Entry.Event);

            if (!permissions.HasFlag(EventPermissions.ManageEntries))
            {
                return(Unauthorized());
            }

            // Note: This will also delete the report (and all votes linked to the entry), so the "approved" status will never actually be visible.
            DatabaseHelpers.Entries.DeleteEntry(r.Entry);
            DatabaseHelpers.Entries.UpdateEntryReportStatus(r, ReportStatus.Approved);

            return(Ok());
        }
Exemplo n.º 6
0
        public IActionResult Settings(string id)
        {
            UserAccount user = GetCurrentUser();
            Event       e    = DatabaseHelpers.Events.GetEventByUrl(id);

            if (e == null)
            {
                return(NotFound());
            }

            EventPermissions permissions = DatabaseHelpers.Events.GetUserPermissionsForEvent(user, e);

            if (!permissions.HasFlag(EventPermissions.EditEventSettings))
            {
                return(Forbid());
            }

            return(View(e));
        }
Exemplo n.º 7
0
        public override PluginResponse OnEnable(IBotSettings botSettings)
        {
            // CLear the list in-case
            // it was restarted.
            AccountsSaved.Clear();

            // Request permissions to hook low level events.
            var permission = EventPermissions.CheckPermissions("low-level");

            if (permission == false)
            {
                return(new PluginResponse(false, "Not enough permissions, plugin requires 'All permissions'."));
            }
            EventPermissions.LowLevelHook("Ban checker", LowLevelEvents.OnServerInitialResponse, ServerResponse);

            bool exists = false;

            // Check if the files exist.
            if (!File.Exists(Setting.At(0).Get <string>()))
            {
                DiscordHelper.Alert("'Banned accounts' path not set.", 1);
            }
            else
            {
                exists = true;
            }
            if (!File.Exists(Setting.At(1).Get <string>()))
            {
                DiscordHelper.Alert("'Unbanned accounts' path not set.", 2);
            }
            else
            {
                exists = true;
            }

            if (!exists)
            {
                DiscordHelper.Error("No output paths have been set.", 1);
            }
            return(new PluginResponse(true));
        }
Exemplo n.º 8
0
        /// <summary>
        /// Checks if the specified user can win the given event, based on his <see cref="EventPermissions"/>.
        /// </summary>
        public bool CanUserWin(UserAccount user, Event e)
        {
            EventPermissions antiWinningPermissions = EventPermissions.EditEventSettings | EventPermissions.ManageEntries | EventPermissions.ManageVotes;

            return((GetUserPermissionsForEvent(user, e) & antiWinningPermissions) == 0);
        }