/** * Applies the selected errata * * @param mapping ActionMapping * @param formIn ActionForm * @param request ServletRequest * @param response ServletResponse * @return The ActionForward to go to next. */ public ActionForward applyErrata( ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) { Map<String, Object> params = new HashMap<String, Object>(); RequestContext requestContext = new RequestContext(request); StrutsDelegate strutsDelegate = getStrutsDelegate(); // if they chose errata, send them to the confirmation page Long sid = requestContext.getParamAsLong("sid"); User user = requestContext.getCurrentUser(); RhnSet set = getSetDecl(sid).get(user); // if they chose no errata, return to the same page with a message if (set.isEmpty()) { ActionMessages msg = new ActionMessages(); msg.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errata.applynone")); params = makeParamMap(formIn, request); strutsDelegate.saveMessages(request, msg); return strutsDelegate.forwardParams(mapping.findForward(RhnHelper.DEFAULT_FORWARD), params); } if (sid != null) { params.put("sid", sid); } return strutsDelegate.forwardParams(mapping.findForward(RhnHelper.CONFIRM_FORWARD), params); }
private Channel makePrivate(DynaActionForm form, ActionErrors errors, RequestContext ctx) { User user = ctx.getCurrentUser(); Long cid = ctx.getParamAsLong("cid"); Channel channel = ChannelFactory.lookupById(cid); unsubscribeOrgsFromChannel(user, channel, Channel.PRIVATE); return edit(form, errors, ctx); }
private Channel edit(DynaActionForm form, ActionErrors errors, RequestContext ctx) { User loggedInUser = ctx.getCurrentUser(); Channel updated = null; // handle submission // why can't I just pass in a dictionary? sigh, there are // times where python would make this SOOOO much easier. UpdateChannelCommand ucc = new UpdateChannelCommand(); ucc.setArchLabel((String) form.get("arch")); ucc.setChecksumLabel((String) form.get("checksum")); ucc.setLabel((String) form.get("label")); ucc.setName((String) form.get("name")); ucc.setSummary((String) form.get("summary")); ucc.setDescription((String) form.get("description")); ucc.setUser(loggedInUser); ucc.setGpgKeyId((String) form.get("gpg_key_id")); ucc.setGpgKeyUrl((String) form.get("gpg_key_url")); ucc.setGpgKeyFp((String) form.get("gpg_key_fingerprint")); ucc.setMaintainerName((String) form.get("maintainer_name")); ucc.setMaintainerEmail((String) form.get("maintainer_email")); ucc.setMaintainerPhone((String) form.get("maintainer_phone")); ucc.setSupportPolicy((String) form.get("support_policy")); ucc.setAccess((String) form.get("org_sharing")); String parent = (String) form.get("parent"); if (parent == null || parent.equals("")) { ucc.setParentId(null); } else { ucc.setParentId(Long.valueOf(parent)); } try { updated = ucc.update(ctx.getParamAsLong("cid")); String sharing = (String) form.get("per_user_subscriptions"); updated.setGloballySubscribable( (sharing != null) && ("all".equals(sharing)), loggedInUser.getOrg()); updated = (Channel) ChannelFactory.reload(updated); } catch (InvalidGPGFingerprintException borg) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgfp")); } catch (InvalidGPGKeyException dukat) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgkey")); } catch (InvalidGPGUrlException khan) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("edit.channel.invalidgpgurl")); } catch (InvalidChannelNameException ferengi) { handleChannelNameException(errors, ferengi); } catch (InvalidChannelLabelException q) { handleChannelLabelException(errors, q); } catch (IllegalArgumentException iae) { errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage(iae.getMessage())); } return updated; }
private PackageAction syncToVictim( RequestContext requestContext, Long sid, Set pkgIdCombos, String option) { PackageAction pa = null; Date time = new Date(requestContext.getParamAsLong("time")); if (isProfileSync(requestContext)) { Long prid = requestContext.getRequiredParam("prid"); pa = ProfileManager.syncToProfile( requestContext.getCurrentUser(), sid, prid, pkgIdCombos, option, time); if (pa == null) { createMessage(requestContext.getRequest(), "message.nopackagestosync"); return null; } List args = new ArrayList(); args.add(sid.toString()); args.add(pa.getId().toString()); args.add(requestContext.lookupAndBindServer().getName()); args.add( ProfileManager.lookupByIdAndOrg(prid, requestContext.getCurrentUser().getOrg()) .getName()); createMessage(requestContext.getRequest(), "message.syncpackages", args); } else if (isSystemSync(requestContext)) { Long sid1 = requestContext.getRequiredParam("sid_1"); pa = ProfileManager.syncToSystem( requestContext.getCurrentUser(), sid, sid1, pkgIdCombos, option, time); if (pa == null) { createMessage(requestContext.getRequest(), "message.nopackagestosync"); return null; } List args = new ArrayList(); args.add(sid.toString()); args.add(pa.getId().toString()); args.add(requestContext.lookupAndBindServer().getName()); args.add(SystemManager.lookupByIdAndUser(sid1, requestContext.getCurrentUser()).getName()); createMessage(requestContext.getRequest(), "message.syncpackages", args); } addHardwareMessage(pa, requestContext); return pa; }
/** {@inheritDoc} */ public List getResult(RequestContext ctx) { Long sid = ctx.getParamAsLong(RequestContext.SID); User user = ctx.getCurrentUser(); KickstartScheduleCommand cmd = getKickstartScheduleCommand(sid, user); DataResult profiles = cmd.getKickstartProfiles(); if (profiles.size() == 0) { addMessage(ctx.getRequest(), "kickstart.schedule.noprofiles"); ctx.getRequest().setAttribute(HAS_PROFILES, Boolean.FALSE.toString()); } else { ctx.getRequest().setAttribute(HAS_PROFILES, Boolean.TRUE.toString()); } return profiles; }
/** {@inheritDoc} */ public ActionForward execute( ActionMapping mapping, ActionForm formIn, HttpServletRequest request, HttpServletResponse response) { RequestContext requestContext = new RequestContext(request); User user = requestContext.getLoggedInUser(); // If this is an easy one and we have the pid if (request.getParameter("pid") != null) { long pid = requestContext.getRequiredParam("pid"); Package pkg = PackageFactory.lookupByIdAndUser(pid, user); // show permission error if pid is invalid like we did before if (pkg == null) { throw new PermissionException("Invalid pid"); } if (pkg instanceof Patch) { request.setAttribute("type", "patch"); request.setAttribute(PACKAGE_NAME, pkg.getPackageName().getName()); request.setAttribute( "readme_url", DownloadManager.getPatchReadmeDownloadPath((Patch) pkg, user)); } else if (pkg instanceof PatchSet) { request.setAttribute("type", "patchset"); request.setAttribute(PACKAGE_NAME, pkg.getNameEvra()); request.setAttribute( "readme_url", DownloadManager.getPatchSetReadmeDownloadPath((PatchSet) pkg, user)); } else { request.setAttribute("type", "rpm"); request.setAttribute(PACKAGE_NAME, pkg.getFilename()); if (!pkg.getPackageKeys().isEmpty()) { request.setAttribute(PACKAGE_KEY, pkg.getPackageKeys().iterator().next().getKey()); } boolean isDebug = pkg.getPackageName().getName().contains("debuginfo"); request.setAttribute("isDebuginfo", isDebug); if (!isDebug) { Package debugPkg = PackageManager.findDebugInfo(user, pkg); String ftpUrl = PackageManager.generateFtpDebugPath(pkg); if (debugPkg != null) { request.setAttribute( "debugUrl", DownloadManager.getPackageDownloadPath(debugPkg, user)); } else if (ftpUrl != null) { request.setAttribute("debugUrl", ftpUrl); request.setAttribute("debugFtp", true); } } } if (DownloadManager.isFileAvailable(pkg.getPath())) { request.setAttribute("url", DownloadManager.getPackageDownloadPath(pkg, user)); } List<PackageSource> src = PackageFactory.lookupPackageSources(pkg); if (!src.isEmpty() && DownloadManager.isFileAvailable(src.get(0).getPath())) { request.setAttribute( "srpm_url", DownloadManager.getPackageSourceDownloadPath(pkg, src.get(0), user)); request.setAttribute("srpm_path", src.get(0).getFile()); } request.setAttribute("pack", pkg); // description can be null. if (pkg.getDescription() != null) { request.setAttribute("description", pkg.getDescription().replace("\n", "<BR>\n")); } else { request.setAttribute("description", pkg.getDescription()); } request.setAttribute("packArches", PackageFactory.findPackagesWithDifferentArch(pkg)); request.setAttribute("pid", pid); return mapping.findForward("default"); } else { // we have to guess PackageListItem item = PackageListItem.parse(request.getParameter("id_combo")); Package pkg; long nameId = item.getIdOne(); long evrId = item.getIdTwo(); long archId = 0; if (item.getIdThree() != null) { archId = item.getIdThree(); } Long cid = requestContext.getParamAsLong("cid"); Long sid = requestContext.getParamAsLong("sid"); if (cid != null) { pkg = PackageManager.guestimatePackageByChannel(cid, nameId, evrId, user.getOrg()); } else if (sid != null) { pkg = PackageManager.guestimatePackageBySystem(sid, nameId, evrId, archId, user.getOrg()); } else { throw new BadParameterException("pid, cid, or sid"); } // show permission error if pid is invalid like we did before if (pkg == null) { throw new NoSuchPackageException(); } Map params = new HashMap(); params.put("pid", pkg.getId()); return getStrutsDelegate().forwardParams(mapping.findForward("package"), params); } }
/** {@inheritDoc} */ public List<SoftwareCrashDto> getResult(RequestContext contextIn) { User user = contextIn.getCurrentUser(); Long serverId = contextIn.getParamAsLong("sid"); Server server = ServerFactory.lookupByIdAndOrg(serverId, user.getOrg()); return ServerFactory.listServerSoftwareCrashes(server); }
/** {@inheritDoc} */ public String getParentUrl(RequestContext ctx) { return ctx.getRequest().getRequestURI() + "?cid=" + ctx.getParamAsLong("cid"); }
private void setupForm(HttpServletRequest request, DynaActionForm form) { RequestContext ctx = new RequestContext(request); prepDropdowns(ctx); Long cid = ctx.getParamAsLong("cid"); if (cid != null) { Channel c = ChannelManager.lookupByIdAndUser(cid, ctx.getCurrentUser()); if (!UserManager.verifyChannelAdmin(ctx.getCurrentUser(), c)) { throw new PermissionException(RoleFactory.CHANNEL_ADMIN); } form.set("name", c.getName()); form.set("summary", c.getSummary()); form.set("description", c.getDescription()); form.set("org_sharing", c.getAccess()); form.set("gpg_key_url", c.getGPGKeyUrl()); form.set("gpg_key_id", c.getGPGKeyId()); form.set("gpg_key_fingerprint", c.getGPGKeyFp()); form.set("maintainer_name", c.getMaintainerName()); form.set("maintainer_phone", c.getMaintainerPhone()); form.set("maintainer_email", c.getMaintainerEmail()); form.set("support_policy", c.getSupportPolicy()); if (c.getChecksumTypeLabel() == null) { form.set("checksum", null); } else { form.set("checksum", c.getChecksumTypeLabel()); } if (c.isGloballySubscribable(ctx.getCurrentUser().getOrg())) { form.set("per_user_subscriptions", "all"); } else { form.set("per_user_subscriptions", "selected"); } if (c.getParentChannel() != null) { request.setAttribute("parent_name", c.getParentChannel().getName()); request.setAttribute("parent_id", c.getParentChannel().getId()); } else { request.setAttribute( "parent_name", LocalizationService.getInstance().getMessage("generic.jsp.none")); } if (c.getSources().isEmpty()) { request.setAttribute("last_sync", ""); } else { String lastSync = LocalizationService.getInstance().getMessage("channel.edit.repo.neversynced"); if (c.getLastSynced() != null) { lastSync = LocalizationService.getInstance().formatCustomDate(c.getLastSynced()); } request.setAttribute("last_sync", lastSync); if (!ChannelManager.getLatestSyncLogFiles(c).isEmpty()) { request.setAttribute( "log_url", DownloadManager.getChannelSyncLogDownloadPath(c, ctx.getCurrentUser())); } } request.setAttribute("channel_label", c.getLabel()); request.setAttribute("channel_name", c.getName()); request.setAttribute("channel_arch", c.getChannelArch().getName()); request.setAttribute("channel_arch_label", c.getChannelArch().getLabel()); } else { // default settings String channelName = LocalizationService.getInstance().getMessage("frontend.actions.channels.manager.create"); request.setAttribute("channel_name", channelName); form.set("org_sharing", "private"); form.set("per_user_subscriptions", "all"); form.set("checksum", "sha1"); } }
/** * Return true if the form value of org_sharing is different than the Channel for the given id. * * @param form contains the user entered values. * @param ctx current Request context. * @return true if the form value of org_sharing is different than the Channel for the given id. */ private boolean hasSharingChanged(DynaActionForm form, RequestContext ctx) { Long cid = ctx.getParamAsLong("cid"); Channel c = ChannelFactory.lookupByIdAndUser(cid, ctx.getCurrentUser()); return !c.getAccess().equals(form.get("org_sharing")); }